1
0
mirror of https://github.com/thangisme/notes.git synced 2024-11-01 10:17:42 -04:00
notes/node_modules/stylelint/lib/rules/media-feature-name-no-unknown/index.js

69 lines
2.1 KiB
JavaScript
Raw Normal View History

2017-03-09 13:16:08 -05:00
"use strict"
const atRuleParamIndex = require("../../utils/atRuleParamIndex")
const isCustomMediaQuery = require("../../utils/isCustomMediaQuery")
const isRangeContextMediaFeature = require("../../utils/isRangeContextMediaFeature")
const isStandardSyntaxMediaFeatureName = require("../../utils/isStandardSyntaxMediaFeatureName")
const optionsMatches = require("../../utils/optionsMatches")
const report = require("../../utils/report")
const ruleMessages = require("../../utils/ruleMessages")
const validateOptions = require("../../utils/validateOptions")
const _ = require("lodash")
const keywordSets = require("../../reference/keywordSets")
const mediaParser = require("postcss-media-query-parser").default
const postcss = require("postcss")
const ruleName = "media-feature-name-no-unknown"
const messages = ruleMessages(ruleName, {
rejected: mediaFeatureName => `Unexpected unknown media feature name "${mediaFeatureName}"`,
})
const rule = function (actual, options) {
return (root, result) => {
const validOptions = validateOptions(result, ruleName, { actual }, {
actual: options,
possible: {
ignoreMediaFeatureNames: [_.isString],
},
optional: true,
})
if (!validOptions) {
return
}
root.walkAtRules(/^media$/i, atRule => {
mediaParser(atRule.params).walk(/^media-feature$/i, mediaFeatureNode => {
const parent = mediaFeatureNode.parent,
sourceIndex = mediaFeatureNode.sourceIndex,
value = mediaFeatureNode.value
if (isRangeContextMediaFeature(parent.value) || !isStandardSyntaxMediaFeatureName(value) || isCustomMediaQuery(value)) {
return
}
if (optionsMatches(options, "ignoreMediaFeatureNames", value)) {
return
}
if (postcss.vendor.prefix(value) || keywordSets.mediaFeatureNames.has(value.toLowerCase())) {
return
}
report({
index: atRuleParamIndex(atRule) + sourceIndex,
message: messages.rejected(value),
node: atRule,
ruleName,
result,
})
})
})
}
}
rule.ruleName = ruleName
rule.messages = messages
module.exports = rule