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