UNPKG

907 BJavaScriptView Raw
1// @ts-nocheck
2
3'use strict';
4
5const declarationValueIndex = require('../utils/declarationValueIndex');
6const report = require('../utils/report');
7const styleSearch = require('style-search');
8
9module.exports = function (opts) {
10 opts.root.walkDecls((decl) => {
11 const indexOffset = declarationValueIndex(decl);
12 const declString = decl.toString();
13 const valueString = decl.toString().slice(indexOffset);
14
15 if (!valueString.includes('!')) {
16 return;
17 }
18
19 styleSearch({ source: valueString, target: '!' }, (match) => {
20 check(declString, match.startIndex + indexOffset, decl);
21 });
22 });
23
24 function check(source, index, node) {
25 opts.locationChecker({
26 source,
27 index,
28 err: (m) => {
29 if (opts.fix && opts.fix(node, index)) {
30 return;
31 }
32
33 report({
34 message: m,
35 node,
36 index,
37 result: opts.result,
38 ruleName: opts.checkedRuleName,
39 });
40 },
41 });
42 }
43};