descriptionlessDisables.cjs 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. const optionsMatches = require('./utils/optionsMatches.cjs');
  6. const reportCommentProblem = require('./utils/reportCommentProblem.cjs');
  7. const validateDisableSettings = require('./validateDisableSettings.cjs');
  8. /**
  9. * @param {import('stylelint').PostcssResult} postcssResult
  10. * @returns {void}
  11. */
  12. function descriptionlessDisables(postcssResult) {
  13. const [enabled, options] = validateDisableSettings(
  14. postcssResult,
  15. 'reportDescriptionlessDisables',
  16. );
  17. if (!options) return;
  18. /** @type {Set<import('postcss').Node>} */
  19. const alreadyReported = new Set();
  20. for (const [rule, ruleRanges] of Object.entries(postcssResult.stylelint.disabledRanges)) {
  21. for (const range of ruleRanges) {
  22. if (range.description) continue;
  23. const node = range.node;
  24. if (alreadyReported.has(node)) continue;
  25. if (enabled === optionsMatches(options, 'except', rule)) {
  26. // An 'all' rule will get copied for each individual rule. If the
  27. // configuration is `[false, {except: ['specific-rule']}]`, we
  28. // don't want to report the copies that match except, so we record
  29. // the comment as already reported.
  30. if (!enabled && rule === constants.RULE_NAME_ALL) alreadyReported.add(node);
  31. continue;
  32. }
  33. alreadyReported.add(node);
  34. reportCommentProblem({
  35. rule: '--report-descriptionless-disables',
  36. message: `Disable for "${rule}" is missing a description`,
  37. severity: options.severity,
  38. node,
  39. postcssResult,
  40. });
  41. }
  42. }
  43. }
  44. module.exports = descriptionlessDisables;