index.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. 'use strict';
  2. const report = require('../../utils/report');
  3. const ruleMessages = require('../../utils/ruleMessages');
  4. const validateOptions = require('../../utils/validateOptions');
  5. const ruleName = 'no-invalid-double-slash-comments';
  6. const messages = ruleMessages(ruleName, {
  7. rejected: 'Unexpected double-slash CSS comment',
  8. });
  9. const meta = {
  10. url: 'https://stylelint.io/user-guide/rules/no-invalid-double-slash-comments',
  11. };
  12. /** @type {import('stylelint').Rule} */
  13. const rule = (primary) => {
  14. return (root, result) => {
  15. const validOptions = validateOptions(result, ruleName, { actual: primary });
  16. if (!validOptions) {
  17. return;
  18. }
  19. root.walkDecls((decl) => {
  20. if (decl.prop.startsWith('//')) {
  21. report({
  22. message: messages.rejected,
  23. node: decl,
  24. result,
  25. ruleName,
  26. word: decl.toString(),
  27. });
  28. }
  29. });
  30. root.walkRules((ruleNode) => {
  31. for (const selector of ruleNode.selectors) {
  32. if (selector.startsWith('//')) {
  33. report({
  34. message: messages.rejected,
  35. node: ruleNode,
  36. result,
  37. ruleName,
  38. word: ruleNode.toString(),
  39. });
  40. }
  41. }
  42. });
  43. };
  44. };
  45. rule.ruleName = ruleName;
  46. rule.messages = messages;
  47. rule.meta = meta;
  48. module.exports = rule;