UNPKG

1.05 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 (
11 !isStandardSyntaxDeclaration(decl) ||
12 !isStandardSyntaxProperty(decl.prop)
13 ) {
14 return;
15 }
16
17 styleSearch(
18 {
19 source: decl.toString(),
20 target: ",",
21 functionArguments: "skip"
22 },
23 match => {
24 checkComma(decl.toString(), match.startIndex, decl);
25 }
26 );
27 });
28
29 function checkComma(source, index, node) {
30 opts.locationChecker({
31 source,
32 index,
33 err: m => {
34 if (opts.fix && opts.fix(node, index)) {
35 return;
36 }
37
38 report({
39 message: m,
40 node,
41 index,
42 result: opts.result,
43 ruleName: opts.checkedRuleName
44 });
45 }
46 });
47 }
48};