index.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. 'use strict';
  2. const isAutoprefixable = require('../../utils/isAutoprefixable');
  3. const report = require('../../utils/report');
  4. const ruleMessages = require('../../utils/ruleMessages');
  5. const validateOptions = require('../../utils/validateOptions');
  6. const ruleName = 'media-feature-name-no-vendor-prefix';
  7. const messages = ruleMessages(ruleName, {
  8. rejected: 'Unexpected vendor-prefix',
  9. });
  10. const meta = {
  11. url: 'https://stylelint.io/user-guide/rules/list/media-feature-name-no-vendor-prefix',
  12. };
  13. /** @type {import('stylelint').Rule} */
  14. const rule = (primary, _secondaryOptions, context) => {
  15. return (root, result) => {
  16. const validOptions = validateOptions(result, ruleName, { actual: primary });
  17. if (!validOptions) {
  18. return;
  19. }
  20. root.walkAtRules(/^media$/i, (atRule) => {
  21. const params = atRule.params;
  22. if (!isAutoprefixable.mediaFeatureName(params)) {
  23. return;
  24. }
  25. const matches = atRule.toString().match(/-[a-z-]+device-pixel-ratio/gi);
  26. if (!matches) {
  27. return;
  28. }
  29. if (context.fix) {
  30. atRule.params = isAutoprefixable.unprefix(atRule.params);
  31. return;
  32. }
  33. for (const match of matches) {
  34. report({
  35. message: messages.rejected,
  36. node: atRule,
  37. word: match,
  38. result,
  39. ruleName,
  40. });
  41. }
  42. });
  43. };
  44. };
  45. rule.ruleName = ruleName;
  46. rule.messages = messages;
  47. rule.meta = meta;
  48. module.exports = rule;