UNPKG

1.61 kBJavaScriptView Raw
1'use strict';
2
3const optionsMatches = require('./utils/optionsMatches');
4const validateDisableSettings = require('./validateDisableSettings');
5
6/** @typedef {import('stylelint').RangeType} RangeType */
7
8/**
9 * @param {import('stylelint').LintResult[]} results
10 */
11module.exports = function invalidScopeDisables(results) {
12 for (const result of results) {
13 const settings = validateDisableSettings(result._postcssResult, 'reportInvalidScopeDisables');
14
15 if (!settings) continue;
16
17 const [enabled, options, stylelintResult] = settings;
18
19 const configRules = (stylelintResult.config || {}).rules || {};
20
21 const usedRules = new Set(Object.keys(configRules));
22
23 usedRules.add('all');
24
25 for (const [rule, ruleRanges] of Object.entries(stylelintResult.disabledRanges)) {
26 if (usedRules.has(rule)) continue;
27
28 if (enabled === optionsMatches(options, 'except', rule)) continue;
29
30 for (const range of ruleRanges) {
31 if (!range.strictStart && !range.strictEnd) continue;
32
33 // If the comment doesn't have a location, we can't report a useful error.
34 // In practice we expect all comments to have locations, though.
35 if (!range.comment.source || !range.comment.source.start) continue;
36
37 result.warnings.push({
38 text: `Rule "${rule}" isn't enabled`,
39 rule: '--report-invalid-scope-disables',
40 line: range.comment.source.start.line,
41 column: range.comment.source.start.column,
42 endLine: range.comment.source.end && range.comment.source.end.line,
43 endColumn: range.comment.source.end && range.comment.source.end.column,
44 severity: options.severity,
45 });
46 }
47 }
48 }
49};