|
1 | 1 | import optionsMatches from './utils/optionsMatches.mjs'; |
| 2 | +import reportCommentProblem from './utils/reportCommentProblem.mjs'; |
2 | 3 | import validateDisableSettings from './validateDisableSettings.mjs'; |
3 | 4 |
|
4 | | -/** @typedef {import('postcss').Comment} PostcssComment */ |
5 | | -/** @typedef {import('stylelint').DisableReportRange} DisableReportRange */ |
6 | | -/** @typedef {import('stylelint').DisableOptionsReport} StylelintDisableOptionsReport */ |
7 | | - |
8 | 5 | /** |
9 | | - * @param {import('stylelint').LintResult[]} results |
| 6 | + * @param {import('stylelint').PostcssResult} postcssResult |
| 7 | + * @returns {void} |
10 | 8 | */ |
11 | | -export default function descriptionlessDisables(results) { |
12 | | - for (const result of results) { |
13 | | - const settings = validateDisableSettings( |
14 | | - result._postcssResult, |
15 | | - 'reportDescriptionlessDisables', |
16 | | - ); |
17 | | - |
18 | | - if (!settings) continue; |
19 | | - |
20 | | - const [enabled, options, stylelintResult] = settings; |
21 | | - |
22 | | - /** @type {Set<PostcssComment>} */ |
23 | | - const alreadyReported = new Set(); |
24 | | - |
25 | | - for (const [rule, ruleRanges] of Object.entries(stylelintResult.disabledRanges)) { |
26 | | - for (const range of ruleRanges) { |
27 | | - if (range.description) continue; |
28 | | - |
29 | | - if (alreadyReported.has(range.comment)) continue; |
30 | | - |
31 | | - if (enabled === optionsMatches(options, 'except', rule)) { |
32 | | - // An 'all' rule will get copied for each individual rule. If the |
33 | | - // configuration is `[false, {except: ['specific-rule']}]`, we |
34 | | - // don't want to report the copies that match except, so we record |
35 | | - // the comment as already reported. |
36 | | - if (!enabled && rule === 'all') alreadyReported.add(range.comment); |
37 | | - |
38 | | - continue; |
39 | | - } |
40 | | - |
41 | | - alreadyReported.add(range.comment); |
42 | | - |
43 | | - // If the comment doesn't have a location, we can't report a useful error. |
44 | | - // In practice we expect all comments to have locations, though. |
45 | | - if (!range.comment.source || !range.comment.source.start) continue; |
46 | | - |
47 | | - result.warnings.push({ |
48 | | - text: `Disable for "${rule}" is missing a description`, |
49 | | - rule: '--report-descriptionless-disables', |
50 | | - line: range.comment.source.start.line, |
51 | | - column: range.comment.source.start.column, |
52 | | - endLine: range.comment.source.end && range.comment.source.end.line, |
53 | | - endColumn: range.comment.source.end && range.comment.source.end.column, |
54 | | - severity: options.severity, |
55 | | - }); |
| 9 | +export default function descriptionlessDisables(postcssResult) { |
| 10 | + const [enabled, options] = validateDisableSettings( |
| 11 | + postcssResult, |
| 12 | + 'reportDescriptionlessDisables', |
| 13 | + ); |
| 14 | + |
| 15 | + if (!options) return; |
| 16 | + |
| 17 | + /** @type {Set<import('postcss').Comment>} */ |
| 18 | + const alreadyReported = new Set(); |
| 19 | + |
| 20 | + for (const [rule, ruleRanges] of Object.entries(postcssResult.stylelint.disabledRanges)) { |
| 21 | + for (const range of ruleRanges) { |
| 22 | + if (range.description) continue; |
| 23 | + |
| 24 | + const commentNode = range.comment; |
| 25 | + |
| 26 | + if (alreadyReported.has(commentNode)) continue; |
| 27 | + |
| 28 | + if (enabled === optionsMatches(options, 'except', rule)) { |
| 29 | + // An 'all' rule will get copied for each individual rule. If the |
| 30 | + // configuration is `[false, {except: ['specific-rule']}]`, we |
| 31 | + // don't want to report the copies that match except, so we record |
| 32 | + // the comment as already reported. |
| 33 | + if (!enabled && rule === 'all') alreadyReported.add(commentNode); |
| 34 | + |
| 35 | + continue; |
56 | 36 | } |
| 37 | + |
| 38 | + alreadyReported.add(commentNode); |
| 39 | + |
| 40 | + reportCommentProblem({ |
| 41 | + rule: '--report-descriptionless-disables', |
| 42 | + message: `Disable for "${rule}" is missing a description`, |
| 43 | + severity: options.severity, |
| 44 | + commentNode, |
| 45 | + postcssResult, |
| 46 | + }); |
57 | 47 | } |
58 | 48 | } |
59 | 49 | } |
0 commit comments