index.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports["default"] = rule;
  6. exports.ruleName = exports.meta = exports.messages = void 0;
  7. var _stylelint = require("stylelint");
  8. var _utils = require("../../utils");
  9. var ruleName = (0, _utils.namespace)("comment-no-loud");
  10. exports.ruleName = ruleName;
  11. var messages = _stylelint.utils.ruleMessages(ruleName, {
  12. expected: "Expected // for comments instead of /*"
  13. });
  14. exports.messages = messages;
  15. var meta = {
  16. url: (0, _utils.ruleUrl)(ruleName)
  17. };
  18. exports.meta = meta;
  19. function rule(primary) {
  20. return function (root, result) {
  21. var validOptions = _stylelint.utils.validateOptions(result, ruleName, {
  22. actual: primary
  23. });
  24. if (!validOptions) {
  25. return;
  26. }
  27. root.walkComments(function (comment) {
  28. if (isLoudComment(comment)) {
  29. _stylelint.utils.report({
  30. message: messages.expected,
  31. node: comment,
  32. result: result,
  33. ruleName: ruleName
  34. });
  35. }
  36. });
  37. };
  38. }
  39. rule.ruleName = ruleName;
  40. rule.messages = messages;
  41. rule.meta = meta;
  42. function isLoudComment(comment) {
  43. var regex = new RegExp(/^[ \t\n]*\/\*/);
  44. var splitComment = comment.source.input.css.split("\n");
  45. var commentFirstLine = splitComment[comment.source.start.line - 1];
  46. return regex.test(commentFirstLine);
  47. }