UNPKG

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