-
-
Notifications
You must be signed in to change notification settings - Fork 929
/
index.js
39 lines (35 loc) · 966 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import selectorParser from "postcss-selector-parser"
import {
isStandardRule,
isStandardSelector,
report,
ruleMessages,
validateOptions,
} from "../../utils"
export const ruleName = "selector-no-combinator"
export const messages = ruleMessages(ruleName, {
rejected: "Unexpected combinator",
})
export default function (actual) {
return (root, result) => {
const validOptions = validateOptions(result, ruleName, { actual })
if (!validOptions) { return }
root.walkRules(rule => {
if (!isStandardRule(rule)) { return }
const { selector } = rule
if (!isStandardSelector(selector)) { return }
selectorParser(selectorAST => {
selectorAST.eachCombinator(combinator => {
report({
message: messages.rejected,
node: rule,
index: combinator.sourceIndex,
ruleName,
result,
})
})
})
.process(selector)
})
}
}