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

56 lines
1.3 KiB
JavaScript

"use strict"
const isCustomProperty = require("../../utils/isCustomProperty")
const isStandardSyntaxProperty = require("../../utils/isStandardSyntaxProperty")
const report = require("../../utils/report")
const ruleMessages = require("../../utils/ruleMessages")
const validateOptions = require("../../utils/validateOptions")
const ruleName = "property-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.walkDecls(decl => {
const prop = decl.prop
if (!isStandardSyntaxProperty(prop)) {
return
}
if (isCustomProperty(prop)) {
return
}
const expectedProp = expectation === "lower" ? prop.toLowerCase() : prop.toUpperCase()
if (prop === expectedProp) {
return
}
report({
message: messages.expected(prop, expectedProp),
node: decl,
ruleName,
result,
})
})
}
}
rule.ruleName = ruleName
rule.messages = messages
module.exports = rule