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

View File

@@ -0,0 +1,47 @@
# selector-pseudo-class-blacklist
Specify a blacklist of disallowed pseudo-class selectors.
```css
a:hover {}
/** ↑
* These pseudo-class selectors */
```
This rule ignores selectors that use variable interpolation e.g. `:#{$variable} {}`.
## Options
`array|string|regex`: `["array", "of", "unprefixed", "pseudo-classes" or "regex"]|"pseudo-class"|/regex/`
If a string is surrounded with `"/"` (e.g. `"/^nth-/"`), it is interpreted as a regular expression. This allows, for example, easy targeting of shorthands: `/^nth-/` will match `nth-child`, `nth-last-child`, `nth-of-type`, etc.
Given:
```js
["hover", "/^nth-/"]
```
The following patterns are considered warnings:
```css
a:hover {}
```
```css
a:nth-of-type(5) {}
```
```css
a:nth-child(2) {}
```
The following patterns are *not* considered warnings:
```css
a:focus {}
```
```css
a:first-of-type {}
```

View File

@@ -0,0 +1,71 @@
"use strict"
const isStandardSyntaxSelector = require("../../utils/isStandardSyntaxSelector")
const matchesStringOrRegExp = require("../../utils/matchesStringOrRegExp")
const parseSelector = require("../../utils/parseSelector")
const report = require("../../utils/report")
const ruleMessages = require("../../utils/ruleMessages")
const validateOptions = require("../../utils/validateOptions")
const _ = require("lodash")
const postcss = require("postcss")
const ruleName = "selector-pseudo-class-blacklist"
const messages = ruleMessages(ruleName, {
rejected: selector => `Unexpected pseudo-class "${selector}"`,
})
const rule = function (blacklist) {
return (root, result) => {
const validOptions = validateOptions(result, ruleName, {
actual: blacklist,
possible: [_.isString],
})
if (!validOptions) {
return
}
root.walkRules(rule => {
const selector = rule.selector
if (!isStandardSyntaxSelector(selector)) {
return
}
if (selector.indexOf(":") === -1) {
return
}
parseSelector(selector, result, rule, selectorTree => {
selectorTree.walkPseudos(pseudoNode => {
const value = pseudoNode.value
// Ignore pseudo-elements
if (value.slice(0, 2) === "::") {
return
}
const name = value.slice(1)
if (!matchesStringOrRegExp(postcss.vendor.unprefixed(name).toLowerCase(), blacklist)) {
return
}
report({
index: pseudoNode.sourceIndex,
message: messages.rejected(name),
node: rule,
result,
ruleName,
})
})
})
})
}
}
rule.primaryOptionArray = true
rule.ruleName = ruleName
rule.messages = messages
module.exports = rule