1 | 'use strict';
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 | module.exports = function (results) {
|
15 | for (const result of results) {
|
16 |
|
17 | if (!result._postcssResult) {
|
18 | continue;
|
19 | }
|
20 |
|
21 |
|
22 | const rangeData = result._postcssResult.stylelint.disabledRanges;
|
23 |
|
24 | if (!rangeData) continue;
|
25 |
|
26 | const config = result._postcssResult.stylelint.config;
|
27 |
|
28 | if (!config || !config.rules) continue;
|
29 |
|
30 |
|
31 |
|
32 | if (!Object.values(config.rules).some((rule) => reportDisablesForRule(rule))) {
|
33 | continue;
|
34 | }
|
35 |
|
36 | for (const [rule, ranges] of Object.entries(rangeData)) {
|
37 | for (const range of ranges) {
|
38 | if (!reportDisablesForRule(config.rules[rule] || [])) continue;
|
39 |
|
40 |
|
41 |
|
42 | if (!range.comment.source || !range.comment.source.start) continue;
|
43 |
|
44 | result.warnings.push({
|
45 | text: `Rule "${rule}" may not be disabled`,
|
46 | rule: 'reportDisables',
|
47 | line: range.comment.source.start.line,
|
48 | column: range.comment.source.start.column,
|
49 | endLine: range.comment.source.end && range.comment.source.end.line,
|
50 | endColumn: range.comment.source.end && range.comment.source.end.column,
|
51 | severity: 'error',
|
52 | });
|
53 | }
|
54 | }
|
55 | }
|
56 | };
|
57 |
|
58 |
|
59 |
|
60 |
|
61 |
|
62 | function reportDisablesForRule(options) {
|
63 | if (!options || !options[1]) return false;
|
64 |
|
65 | return Boolean(options[1].reportDisables);
|
66 | }
|