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/at-rule-no-unknown/index.js
Patrick Marsceill b7b0d0d7bf
Initial commit
2017-03-09 13:16:08 -05:00

59 lines
1.3 KiB
JavaScript

"use strict"
const _ = require("lodash")
const keywordSets = require("../../reference/keywordSets")
const optionsMatches = require("../../utils/optionsMatches")
const postcss = require("postcss")
const report = require("../../utils/report")
const ruleMessages = require("../../utils/ruleMessages")
const validateOptions = require("../../utils/validateOptions")
const ruleName = "at-rule-no-unknown"
const messages = ruleMessages(ruleName, {
rejected: atRule => `Unexpected unknown at-rule "${atRule}"`,
})
const rule = function (actual, options) {
return (root, result) => {
const validOptions = validateOptions(result, ruleName, { actual }, {
actual: options,
possible: {
ignoreAtRules: [_.isString],
},
optional: true,
})
if (!validOptions) {
return
}
root.walkAtRules(atRule => {
const name = atRule.name
// Return early if at-rule is to be ignored
if (optionsMatches(options, "ignoreAtRules", atRule.name)) {
return
}
if (
postcss.vendor.prefix(name)
|| keywordSets.atRules.has(name.toLowerCase())
) {
return
}
report({
message: messages.rejected(`@${name}`),
node: atRule,
ruleName,
result,
})
})
}
}
rule.ruleName = ruleName
rule.messages = messages
module.exports = rule