/
index.js
42 lines (36 loc) · 997 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 { vendor } from "postcss"
import { isString } from "lodash"
import {
isCustomProperty,
isStandardProperty,
matchesStringOrRegExp,
report,
ruleMessages,
validateOptions,
} from "../../utils"
export const ruleName = "property-whitelist"
export const messages = ruleMessages(ruleName, {
rejected: (p) => `Unexpected property "${p}"`,
})
export default function (whitelistInput) {
const whitelist = [].concat(whitelistInput)
return (root, result) => {
const validOptions = validateOptions(result, ruleName, {
actual: whitelist,
possible: [isString],
})
if (!validOptions) { return }
root.walkDecls(decl => {
const { prop } = decl
if (!isStandardProperty(prop)) { return }
if (isCustomProperty(prop)) { return }
if (matchesStringOrRegExp(vendor.unprefixed(prop), whitelist)) { return }
report({
message: messages.rejected(prop),
node: decl,
result,
ruleName,
})
})
}
}