3 const isStandardSyntaxRule = require("../utils/isStandardSyntaxRule");
4 const parseSelector = require("../utils/parseSelector");
5 const report = require("../utils/report");
7 module.exports = function(opts) {
8 opts.root.walkRules(rule => {
9 if (!isStandardSyntaxRule(rule)) {
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)) {
22 const parentParentNode = node.parent && node.parent.parent;
24 // Ignore pseudo-classes selector like `.foo:nth-child(2n + 1) {}`
25 if (parentParentNode && parentParentNode.type === "pseudo") {
29 const sourceIndex = node.sourceIndex;
31 node.value.length > 1 && opts.locationType === "before"
33 : sourceIndex + node.value.length - 1;
35 check(selector, node.value, index, rule, sourceIndex);
41 function check(source, errTarget, index, node, sourceIndex) {
42 opts.locationChecker({
52 ruleName: opts.checkedRuleName