.gitignore added
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-prettier / node_modules / stylelint / lib / rules / selectorCombinatorSpaceChecker.js
1 "use strict";
2
3 const isStandardSyntaxRule = require("../utils/isStandardSyntaxRule");
4 const parseSelector = require("../utils/parseSelector");
5 const report = require("../utils/report");
6
7 module.exports = function(opts) {
8   opts.root.walkRules(rule => {
9     if (!isStandardSyntaxRule(rule)) {
10       return;
11     }
12     // Check each selector individually, instead of all as one string,
13     // in case some that aren't the first begin with combinators (nesting syntax)
14     rule.selectors.forEach(selector => {
15       parseSelector(selector, opts.result, rule, selectorTree => {
16         selectorTree.walkCombinators(node => {
17           // Ignore spaced descendant combinator
18           if (/\s/.test(node.value)) {
19             return;
20           }
21
22           const parentParentNode = node.parent && node.parent.parent;
23
24           // Ignore pseudo-classes selector like `.foo:nth-child(2n + 1) {}`
25           if (parentParentNode && parentParentNode.type === "pseudo") {
26             return;
27           }
28
29           const sourceIndex = node.sourceIndex;
30           const index =
31             node.value.length > 1 && opts.locationType === "before"
32               ? sourceIndex
33               : sourceIndex + node.value.length - 1;
34
35           check(selector, node.value, index, rule, sourceIndex);
36         });
37       });
38     });
39   });
40
41   function check(source, errTarget, index, node, sourceIndex) {
42     opts.locationChecker({
43       source,
44       index,
45       errTarget,
46       err: m =>
47         report({
48           message: m,
49           node,
50           index: sourceIndex,
51           result: opts.result,
52           ruleName: opts.checkedRuleName
53         })
54     });
55   }
56 };