UNPKG

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