1
0
mirror of https://github.com/thangisme/notes.git synced 2024-11-01 03:27:29 -04:00
notes/node_modules/stylelint/lib/rules/selectorCombinatorSpaceChecker.js
Patrick Marsceill b7b0d0d7bf
Initial commit
2017-03-09 13:16:08 -05:00

49 lines
1.3 KiB
JavaScript

"use strict"
const report = require("../utils/report")
const _ = require("lodash")
const punctuationSets = require("../reference/punctuationSets")
const styleSearch = require("style-search")
module.exports = function (opts) {
opts.root.walkRules(rule => {
// Check each selector individually, instead of all as one string,
// in case some that aren't the first begin with combinators (nesting syntax)
rule.selectors.forEach(selector => {
styleSearch({
source: selector,
target: _.toArray(punctuationSets.nonSpaceCombinators),
parentheticals: "skip",
}, match => {
const endIndex = match.endIndex,
startIndex = match.startIndex,
target = match.target
// Catch ~= in attribute selectors
if (target === "~" && selector[endIndex] === "=") {
return
}
// Catch escaped combinator-like character
if (selector[startIndex - 1] === "\\") {
return
}
check(selector, startIndex, rule)
})
})
})
function check(source, index, node) {
opts.locationChecker({ source, index, err: m => report({
message: m,
node,
index,
result: opts.result,
ruleName: opts.checkedRuleName,
}),
})
}
}