index.mjs 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import isStandardSyntaxComment from '../../utils/isStandardSyntaxComment.mjs';
  2. import report from '../../utils/report.mjs';
  3. import ruleMessages from '../../utils/ruleMessages.mjs';
  4. import validateOptions from '../../utils/validateOptions.mjs';
  5. const ruleName = 'comment-no-empty';
  6. const messages = ruleMessages(ruleName, {
  7. rejected: 'Unexpected empty comment',
  8. });
  9. const meta = {
  10. url: 'https://stylelint.io/user-guide/rules/comment-no-empty',
  11. };
  12. /** @type {import('stylelint').CoreRules[ruleName]} */
  13. const rule = (primary) => {
  14. return (root, result) => {
  15. const validOptions = validateOptions(result, ruleName, { actual: primary });
  16. if (!validOptions) {
  17. return;
  18. }
  19. root.walkComments((comment) => {
  20. // To ignore non-standard comments
  21. if (!isStandardSyntaxComment(comment)) {
  22. return;
  23. }
  24. // To ignore comments that are not empty
  25. if (comment.text && comment.text.length !== 0) {
  26. return;
  27. }
  28. report({
  29. message: messages.rejected,
  30. messageArgs: [],
  31. node: comment,
  32. result,
  33. ruleName,
  34. });
  35. });
  36. };
  37. };
  38. rule.ruleName = ruleName;
  39. rule.messages = messages;
  40. rule.meta = meta;
  41. export default rule;