mirror of
https://github.com/snachodog/just-the-docs.git
synced 2026-06-04 20:20:08 -06:00
Initial commit
This commit is contained in:
+37
@@ -0,0 +1,37 @@
|
||||
# root-no-standard-properties
|
||||
|
||||
***Deprecated: See [CHANGELOG](../../../CHANGELOG.md).***
|
||||
|
||||
Disallow standard properties inside `:root` rules.
|
||||
|
||||
```css
|
||||
:root { color: #333 }
|
||||
/** ↑ ↑
|
||||
* This selector and these types of standard properties */
|
||||
```
|
||||
|
||||
This rule ignores `$sass` and `@less` variables.
|
||||
|
||||
## Options
|
||||
|
||||
### `true`
|
||||
|
||||
The following patterns are considered warnings:
|
||||
|
||||
```css
|
||||
:root { color: pink; }
|
||||
```
|
||||
|
||||
```css
|
||||
a, :root { top: 0; }
|
||||
```
|
||||
|
||||
The following patterns are *not* considered warnings:
|
||||
|
||||
```css
|
||||
:root { --foo: 0; }
|
||||
```
|
||||
|
||||
```css
|
||||
a, :root { --foo: 0; }
|
||||
```
|
||||
+80
@@ -0,0 +1,80 @@
|
||||
"use strict"
|
||||
|
||||
const isCustomProperty = require("../../utils/isCustomProperty")
|
||||
const isStandardSyntaxProperty = require("../../utils/isStandardSyntaxProperty")
|
||||
const parseSelector = require("../../utils/parseSelector")
|
||||
const report = require("../../utils/report")
|
||||
const ruleMessages = require("../../utils/ruleMessages")
|
||||
const validateOptions = require("../../utils/validateOptions")
|
||||
|
||||
const ruleName = "root-no-standard-properties"
|
||||
|
||||
const messages = ruleMessages(ruleName, {
|
||||
rejected: property => `Unexpected standard property "${property}"`,
|
||||
})
|
||||
|
||||
const rule = function (actual) {
|
||||
return (root, result) => {
|
||||
const validOptions = validateOptions(result, ruleName, { actual })
|
||||
if (!validOptions) {
|
||||
return
|
||||
}
|
||||
|
||||
result.warn((
|
||||
`'${ruleName}' has been deprecated and in 8.0 will be removed.`
|
||||
), {
|
||||
stylelintType: "deprecation",
|
||||
stylelintReference: `https://stylelint.io/user-guide/rules/${ruleName}/`,
|
||||
})
|
||||
|
||||
root.walkRules(rule => {
|
||||
if (rule.selector.toLowerCase().indexOf(":root") === -1) {
|
||||
return
|
||||
}
|
||||
parseSelector(rule.selector, result, rule, checkSelector)
|
||||
|
||||
function checkSelector(selectorAST) {
|
||||
if (ignoreRule(selectorAST)) {
|
||||
return
|
||||
}
|
||||
|
||||
rule.each(function (node) {
|
||||
if (node.type !== "decl") {
|
||||
return
|
||||
}
|
||||
|
||||
const prop = node.prop
|
||||
|
||||
if (!isStandardSyntaxProperty(prop)) {
|
||||
return
|
||||
}
|
||||
if (isCustomProperty(prop)) {
|
||||
return
|
||||
}
|
||||
|
||||
report({
|
||||
message: messages.rejected(prop),
|
||||
node,
|
||||
result,
|
||||
ruleName,
|
||||
})
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
function ignoreRule(selectorAST) {
|
||||
let ignore = false
|
||||
selectorAST.walk(selectorNode => {
|
||||
// ignore `:root` selector inside a `:not()` selector
|
||||
if (selectorNode.value && selectorNode.value.toLowerCase() === ":root" && selectorNode.parent.parent.value && selectorNode.parent.parent.value.toLowerCase() === ":not") {
|
||||
ignore = true
|
||||
}
|
||||
})
|
||||
return ignore
|
||||
}
|
||||
|
||||
rule.ruleName = ruleName
|
||||
rule.messages = messages
|
||||
module.exports = rule
|
||||
Reference in New Issue
Block a user