.gitignore added
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-prettier / node_modules / stylelint / lib / rules / selectorAttributeOperatorSpaceChecker.js
1 "use strict";
2
3 const isStandardSyntaxRule = require("../utils/isStandardSyntaxRule");
4 const parseSelector = require("../utils/parseSelector");
5 const report = require("../utils/report");
6 const styleSearch = require("style-search");
7
8 module.exports = function(options) {
9   options.root.walkRules(rule => {
10     if (!isStandardSyntaxRule(rule)) {
11       return;
12     }
13     if (
14       rule.selector.indexOf("[") === -1 ||
15       rule.selector.indexOf("=") === -1
16     ) {
17       return;
18     }
19
20     parseSelector(rule.selector, options.result, rule, selectorTree => {
21       selectorTree.walkAttributes(attributeNode => {
22         const operator = attributeNode.operator;
23
24         if (!operator) {
25           return;
26         }
27
28         const attributeNodeString = attributeNode.toString();
29
30         styleSearch(
31           { source: attributeNodeString, target: operator },
32           match => {
33             const index = options.checkBeforeOperator
34               ? match.startIndex
35               : match.endIndex - 1;
36             checkOperator(
37               attributeNodeString,
38               index,
39               rule,
40               attributeNode.sourceIndex,
41               operator
42             );
43           }
44         );
45       });
46     });
47
48     function checkOperator(source, index, node, attributeIndex, operator) {
49       options.locationChecker({
50         source,
51         index,
52         err: m =>
53           report({
54             message: m.replace(
55               options.checkBeforeOperator
56                 ? operator[0]
57                 : operator[operator.length - 1],
58               operator
59             ),
60             node,
61             index: attributeIndex + index,
62             result: options.result,
63             ruleName: options.checkedRuleName
64           })
65       });
66     }
67   });
68 };