forked from stylelint/stylelint
-
Notifications
You must be signed in to change notification settings - Fork 0
/
valueListCommaWhitespaceChecker.js
55 lines (47 loc) · 1.13 KB
/
valueListCommaWhitespaceChecker.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
'use strict';
const isStandardSyntaxDeclaration = require('../utils/isStandardSyntaxDeclaration');
const isStandardSyntaxProperty = require('../utils/isStandardSyntaxProperty');
const report = require('../utils/report');
const styleSearch = require('style-search');
module.exports = function(opts) {
opts.root.walkDecls((decl) => {
if (!isStandardSyntaxDeclaration(decl) || !isStandardSyntaxProperty(decl.prop)) {
return;
}
const declString = decl.toString();
styleSearch(
{
source: declString,
target: ',',
functionArguments: 'skip',
},
(match) => {
const indexToCheckAfter = opts.determineIndex
? opts.determineIndex(declString, match)
: match.startIndex;
if (indexToCheckAfter === false) {
return;
}
checkComma(declString, indexToCheckAfter, decl);
},
);
});
function checkComma(source, index, node) {
opts.locationChecker({
source,
index,
err: (m) => {
if (opts.fix && opts.fix(node, index)) {
return;
}
report({
message: m,
node,
index,
result: opts.result,
ruleName: opts.checkedRuleName,
});
},
});
}
};