index.js 1.1 KB

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