1 | 'use strict';
|
2 |
|
3 | const optionsMatches = require('./utils/optionsMatches');
|
4 | const validateDisableSettings = require('./validateDisableSettings');
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 | module.exports = function descriptionlessDisables(results) {
|
15 | for (const result of results) {
|
16 | const settings = validateDisableSettings(
|
17 | result._postcssResult,
|
18 | 'reportDescriptionlessDisables',
|
19 | );
|
20 |
|
21 | if (!settings) continue;
|
22 |
|
23 | const [enabled, options, stylelintResult] = settings;
|
24 |
|
25 |
|
26 | const alreadyReported = new Set();
|
27 |
|
28 | for (const [rule, ruleRanges] of Object.entries(stylelintResult.disabledRanges)) {
|
29 | for (const range of ruleRanges) {
|
30 | if (range.description) continue;
|
31 |
|
32 | if (alreadyReported.has(range.comment)) continue;
|
33 |
|
34 | if (enabled === optionsMatches(options, 'except', rule)) {
|
35 |
|
36 |
|
37 |
|
38 |
|
39 | if (!enabled && rule === 'all') alreadyReported.add(range.comment);
|
40 |
|
41 | continue;
|
42 | }
|
43 |
|
44 | alreadyReported.add(range.comment);
|
45 |
|
46 |
|
47 |
|
48 | if (!range.comment.source || !range.comment.source.start) continue;
|
49 |
|
50 | result.warnings.push({
|
51 | text: `Disable for "${rule}" is missing a description`,
|
52 | rule: '--report-descriptionless-disables',
|
53 | line: range.comment.source.start.line,
|
54 | column: range.comment.source.start.column,
|
55 | endLine: range.comment.source.end && range.comment.source.end.line,
|
56 | endColumn: range.comment.source.end && range.comment.source.end.column,
|
57 | severity: options.severity,
|
58 | });
|
59 | }
|
60 | }
|
61 | }
|
62 | };
|