1
0
mirror of https://github.com/thangisme/notes.git synced 2024-11-01 08:17:34 -04:00
notes/node_modules/stylelint/lib/rules/selector-pseudo-element-case/index.js
Patrick Marsceill b7b0d0d7bf
Initial commit
2017-03-09 13:16:08 -05:00

75 lines
2.1 KiB
JavaScript

"use strict"
const isStandardSyntaxRule = require("../../utils/isStandardSyntaxRule")
const isStandardSyntaxSelector = require("../../utils/isStandardSyntaxSelector")
const parseSelector = require("../../utils/parseSelector")
const report = require("../../utils/report")
const ruleMessages = require("../../utils/ruleMessages")
const validateOptions = require("../../utils/validateOptions")
const keywordSets = require("../../reference/keywordSets")
const ruleName = "selector-pseudo-element-case"
const messages = ruleMessages(ruleName, {
expected: (actual, expected) => `Expected "${actual}" to be "${expected}"`,
})
const rule = function (expectation) {
return (root, result) => {
const validOptions = validateOptions(result, ruleName, {
actual: expectation,
possible: [
"lower",
"upper",
],
})
if (!validOptions) {
return
}
root.walkRules(rule => {
if (!isStandardSyntaxRule(rule)) {
return
}
const selector = rule.selector
const startIndexPseudoElement = selector.indexOf(":")
if (startIndexPseudoElement === -1) {
return
}
parseSelector(selector, result, rule, selectorTree => {
selectorTree.walkPseudos(pseudoNode => {
const pseudoElement = pseudoNode.value
if (!isStandardSyntaxSelector(pseudoElement)) {
return
}
if (pseudoElement.indexOf("::") === -1 && !keywordSets.levelOneAndTwoPseudoElements.has(pseudoElement.toLowerCase().slice(1))) {
return
}
const expectedPseudoElement = expectation === "lower" ? pseudoElement.toLowerCase() : pseudoElement.toUpperCase()
if (pseudoElement === expectedPseudoElement) {
return
}
report({
message: messages.expected(pseudoElement, expectedPseudoElement),
node: rule,
index: pseudoNode.sourceIndex,
ruleName,
result,
})
})
})
})
}
}
rule.ruleName = ruleName
rule.messages = messages
module.exports = rule