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