index.js 1.3 KB

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