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/property-whitelist/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 matchesStringOrRegExp = require("../../utils/matchesStringOrRegExp")
const report = require("../../utils/report")
const ruleMessages = require("../../utils/ruleMessages")
const validateOptions = require("../../utils/validateOptions")
const _ = require("lodash")
const postcss = require("postcss")
const ruleName = "property-whitelist"
const messages = ruleMessages(ruleName, {
rejected: property => `Unexpected property "${property}"`,
})
const rule = function (whitelist) {
return (root, result) => {
const validOptions = validateOptions(result, ruleName, {
actual: whitelist,
possible: [_.isString],
})
if (!validOptions) {
return
}
root.walkDecls(decl => {
const prop = decl.prop
if (!isStandardSyntaxProperty(prop)) {
return
}
if (isCustomProperty(prop)) {
return
}
if (matchesStringOrRegExp(postcss.vendor.unprefixed(prop), whitelist)) {
return
}
report({
message: messages.rejected(prop),
node: decl,
result,
ruleName,
})
})
}
}
rule.primaryOptionArray = true
rule.ruleName = ruleName
rule.messages = messages
module.exports = rule