index.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. 'use strict';
  2. const isAutoprefixable = require('../../utils/isAutoprefixable');
  3. const isStandardSyntaxAtRule = require('../../utils/isStandardSyntaxAtRule');
  4. const report = require('../../utils/report');
  5. const ruleMessages = require('../../utils/ruleMessages');
  6. const validateOptions = require('../../utils/validateOptions');
  7. const ruleName = 'at-rule-no-vendor-prefix';
  8. const messages = ruleMessages(ruleName, {
  9. rejected: (p) => `Unexpected vendor-prefixed at-rule "@${p}"`,
  10. });
  11. const meta = {
  12. url: 'https://stylelint.io/user-guide/rules/list/at-rule-no-vendor-prefix',
  13. };
  14. /** @type {import('stylelint').Rule} */
  15. const rule = (primary, _secondary, context) => {
  16. return (root, result) => {
  17. const validOptions = validateOptions(result, ruleName, { actual: primary });
  18. if (!validOptions) {
  19. return;
  20. }
  21. root.walkAtRules((atRule) => {
  22. if (!isStandardSyntaxAtRule(atRule)) {
  23. return;
  24. }
  25. const name = atRule.name;
  26. if (!name.startsWith('-')) {
  27. return;
  28. }
  29. if (!isAutoprefixable.atRuleName(name)) {
  30. return;
  31. }
  32. if (context.fix) {
  33. atRule.name = isAutoprefixable.unprefix(atRule.name);
  34. return;
  35. }
  36. report({
  37. message: messages.rejected(name),
  38. node: atRule,
  39. result,
  40. ruleName,
  41. });
  42. });
  43. };
  44. };
  45. rule.ruleName = ruleName;
  46. rule.messages = messages;
  47. rule.meta = meta;
  48. module.exports = rule;