/
index.js
42 lines (36 loc) · 986 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
40
41
42
import {
isCustomProperty,
isStandardProperty,
report,
ruleMessages,
validateOptions,
} from "../../utils"
export const ruleName = "property-case"
export const messages = ruleMessages(ruleName, {
expected: (actual, expected) => `Expected "${actual}" to be "${expected}"`,
})
export default function (expectation) {
return (root, result) => {
const validOptions = validateOptions(result, ruleName, {
actual: expectation,
possible: [
"lower",
"upper",
],
})
if (!validOptions) { return }
root.walkDecls(decl => {
const { prop } = decl
if (!isStandardProperty(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,
})
})
}
}