UNPKG

1.35 kBJavaScriptView Raw
1'use strict';
2
3/** @typedef {import('stylelint').RangeType} RangeType */
4
5/**
6 * @param {import('stylelint').StylelintResult[]} results
7 */
8module.exports = function (results) {
9 results.forEach((result) => {
10 // File with `CssSyntaxError` have not `_postcssResult`
11 if (!result._postcssResult) {
12 return;
13 }
14
15 if (!result._postcssResult.stylelint.config) {
16 // Linting error
17 return;
18 }
19
20 const configRules = result._postcssResult.stylelint.config.rules || {};
21
22 const usedRules = new Set(Object.keys(configRules));
23
24 usedRules.add('all');
25
26 const rangeData = result._postcssResult.stylelint.disabledRanges;
27 const disabledRules = Object.keys(rangeData);
28
29 disabledRules.forEach((rule) => {
30 if (usedRules.has(rule)) {
31 return;
32 }
33
34 rangeData[rule].forEach((range) => {
35 if (!range.strictStart && !range.strictEnd) {
36 return;
37 }
38
39 // If the comment doesn't have a location, we can't report a useful error.
40 // In practice we expect all comments to have locations, though.
41 if (!range.comment.source || !range.comment.source.start) return;
42
43 result.warnings.push({
44 text: `Rule "${rule}" isn't enabled`,
45 rule: '--report-invalid-scope-disables',
46 line: range.comment.source.start.line,
47 column: range.comment.source.start.column,
48 severity: 'error',
49 });
50 });
51 });
52 });
53};