reportCommentProblem.cjs 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. // NOTICE: This file is generated by Rollup. To modify it,
  2. // please instead edit the ESM counterpart and rebuild with Rollup (npm run build).
  3. 'use strict';
  4. const constants = require('../constants.cjs');
  5. /**
  6. * @param {{
  7. * rule: string;
  8. * message: string;
  9. * severity: import('stylelint').Severity;
  10. * node: import('postcss').Node;
  11. * postcssResult: import('stylelint').PostcssResult;
  12. * }} args
  13. * @returns {void}
  14. */
  15. function reportCommentProblem({ rule, message, severity, node, postcssResult }) {
  16. const { source } = node;
  17. // If the comment doesn't have a location, we can't report a useful error.
  18. // In practice we expect all comments to have locations, though.
  19. if (!source?.start) return;
  20. postcssResult.warn(message, {
  21. rule,
  22. severity,
  23. node,
  24. start: source.start,
  25. end: source.end,
  26. });
  27. switch (severity) {
  28. case constants.SEVERITY_ERROR:
  29. postcssResult.stylelint.stylelintError = true;
  30. break;
  31. case constants.SEVERITY_WARNING:
  32. postcssResult.stylelint.stylelintWarning = true;
  33. break;
  34. default:
  35. // no-op
  36. break;
  37. }
  38. }
  39. module.exports = reportCommentProblem;