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 | results.forEach((result) => {
|
16 | const settings = validateDisableSettings(
|
17 | result._postcssResult,
|
18 | 'reportDescriptionlessDisables',
|
19 | );
|
20 |
|
21 | if (!settings) return;
|
22 |
|
23 | const [enabled, options, stylelintResult] = settings;
|
24 |
|
25 | const rangeData = stylelintResult.disabledRanges;
|
26 |
|
27 |
|
28 | const alreadyReported = new Set();
|
29 |
|
30 | Object.keys(rangeData).forEach((rule) => {
|
31 | rangeData[rule].forEach((range) => {
|
32 | if (range.description) return;
|
33 |
|
34 | if (alreadyReported.has(range.comment)) return;
|
35 |
|
36 | if (enabled === optionsMatches(options, 'except', rule)) {
|
37 |
|
38 |
|
39 |
|
40 |
|
41 | if (!enabled && rule === 'all') alreadyReported.add(range.comment);
|
42 |
|
43 | return;
|
44 | }
|
45 |
|
46 | alreadyReported.add(range.comment);
|
47 |
|
48 |
|
49 |
|
50 | if (!range.comment.source || !range.comment.source.start) return;
|
51 |
|
52 | result.warnings.push({
|
53 | text: `Disable for "${rule}" is missing a description`,
|
54 | rule: '--report-descriptionless-disables',
|
55 | line: range.comment.source.start.line,
|
56 | column: range.comment.source.start.column,
|
57 | severity: options.severity,
|
58 | });
|
59 | });
|
60 | });
|
61 | });
|
62 | };
|