index.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. 'use strict';
  2. const getImportantPosition = require('../../utils/getImportantPosition');
  3. const report = require('../../utils/report');
  4. const ruleMessages = require('../../utils/ruleMessages');
  5. const validateOptions = require('../../utils/validateOptions');
  6. const { assert } = require('../../utils/validateTypes');
  7. const ruleName = 'keyframe-declaration-no-important';
  8. const messages = ruleMessages(ruleName, {
  9. rejected: 'Unexpected !important',
  10. });
  11. const meta = {
  12. url: 'https://stylelint.io/user-guide/rules/list/keyframe-declaration-no-important',
  13. };
  14. /** @type {import('stylelint').Rule} */
  15. const rule = (primary) => {
  16. return (root, result) => {
  17. const validOptions = validateOptions(result, ruleName, { actual: primary });
  18. if (!validOptions) {
  19. return;
  20. }
  21. root.walkAtRules(/^(-(moz|webkit)-)?keyframes$/i, (atRuleKeyframes) => {
  22. atRuleKeyframes.walkDecls((decl) => {
  23. if (!decl.important) {
  24. return;
  25. }
  26. const pos = getImportantPosition(decl.toString());
  27. assert(pos);
  28. report({
  29. message: messages.rejected,
  30. node: decl,
  31. index: pos.index,
  32. result,
  33. ruleName,
  34. });
  35. });
  36. });
  37. };
  38. };
  39. rule.ruleName = ruleName;
  40. rule.messages = messages;
  41. rule.meta = meta;
  42. module.exports = rule;