index.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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/list/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. });
  27. }
  28. });
  29. root.walkRules((ruleNode) => {
  30. for (const selector of ruleNode.selectors) {
  31. if (selector.startsWith('//')) {
  32. report({
  33. message: messages.rejected,
  34. node: ruleNode,
  35. result,
  36. ruleName,
  37. });
  38. }
  39. }
  40. });
  41. };
  42. };
  43. rule.ruleName = ruleName;
  44. rule.messages = messages;
  45. rule.meta = meta;
  46. module.exports = rule;