Initial commit

This commit is contained in:
Patrick Marsceill
2017-03-09 13:16:08 -05:00
commit b7b0d0d7bf
4147 changed files with 401224 additions and 0 deletions
+37
View File
@@ -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
View File
@@ -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