index.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. 'use strict';
  2. const isCustomProperty = require('../../utils/isCustomProperty');
  3. const isStandardSyntaxProperty = require('../../utils/isStandardSyntaxProperty');
  4. const matchesStringOrRegExp = require('../../utils/matchesStringOrRegExp');
  5. const report = require('../../utils/report');
  6. const ruleMessages = require('../../utils/ruleMessages');
  7. const validateOptions = require('../../utils/validateOptions');
  8. const vendor = require('../../utils/vendor');
  9. const { isRegExp, isString } = require('../../utils/validateTypes');
  10. const ruleName = 'property-disallowed-list';
  11. const messages = ruleMessages(ruleName, {
  12. rejected: (property) => `Unexpected property "${property}"`,
  13. });
  14. const meta = {
  15. url: 'https://stylelint.io/user-guide/rules/list/property-disallowed-list',
  16. };
  17. /** @type {import('stylelint').Rule<string | RegExp | Array<string | RegExp>>} */
  18. const rule = (primary) => {
  19. return (root, result) => {
  20. const validOptions = validateOptions(result, ruleName, {
  21. actual: primary,
  22. possible: [isString, isRegExp],
  23. });
  24. if (!validOptions) {
  25. return;
  26. }
  27. root.walkDecls((decl) => {
  28. const prop = decl.prop;
  29. if (!isStandardSyntaxProperty(prop)) {
  30. return;
  31. }
  32. if (isCustomProperty(prop)) {
  33. return;
  34. }
  35. if (!matchesStringOrRegExp(vendor.unprefixed(prop), primary)) {
  36. return;
  37. }
  38. report({
  39. message: messages.rejected(prop),
  40. node: decl,
  41. result,
  42. ruleName,
  43. });
  44. });
  45. };
  46. };
  47. rule.primaryOptionArray = true;
  48. rule.ruleName = ruleName;
  49. rule.messages = messages;
  50. rule.meta = meta;
  51. module.exports = rule;