reportCommentProblem.mjs 929 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. import { SEVERITY_ERROR, SEVERITY_WARNING } from '../constants.mjs';
  2. /**
  3. * @param {{
  4. * rule: string;
  5. * message: string;
  6. * severity: import('stylelint').Severity;
  7. * node: import('postcss').Node;
  8. * postcssResult: import('stylelint').PostcssResult;
  9. * }} args
  10. * @returns {void}
  11. */
  12. export default function reportCommentProblem({ rule, message, severity, node, postcssResult }) {
  13. const { source } = node;
  14. // If the comment doesn't have a location, we can't report a useful error.
  15. // In practice we expect all comments to have locations, though.
  16. if (!source?.start) return;
  17. postcssResult.warn(message, {
  18. rule,
  19. severity,
  20. node,
  21. start: source.start,
  22. end: source.end,
  23. });
  24. switch (severity) {
  25. case SEVERITY_ERROR:
  26. postcssResult.stylelint.stylelintError = true;
  27. break;
  28. case SEVERITY_WARNING:
  29. postcssResult.stylelint.stylelintWarning = true;
  30. break;
  31. default:
  32. // no-op
  33. break;
  34. }
  35. }