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,53 @@
# selector-pseudo-class-parentheses-space-inside
Require a single space or disallow whitespace on the inside of the parentheses within pseudo-class selectors.
```css
input:not( [type="submit"] ) {}
/** ↑ ↑
* The space inside these two parentheses */
```
## Options
`string`: `"always"|"never"`
### `"always"`
There *must always* be a single space inside the parentheses.
The following patterns are considered warnings:
```css
input:not([type="submit"]) {}
```
```css
input:not([type="submit"] ) {}
```
The following patterns are *not* considered warnings:
```css
input:not( [type="submit"] ) {}
```
### `"never"`
There *must never* be whitespace on the inside the parentheses.
The following patterns are considered warnings:
```css
input:not( [type="submit"] ) {}
```
```css
input:not( [type="submit"]) {}
```
The following patterns are *not* considered warnings:
```css
input:not([type="submit"]) {}
```

View File

@@ -0,0 +1,88 @@
"use strict"
const isStandardSyntaxRule = require("../../utils/isStandardSyntaxRule")
const parseSelector = require("../../utils/parseSelector")
const report = require("../../utils/report")
const ruleMessages = require("../../utils/ruleMessages")
const validateOptions = require("../../utils/validateOptions")
const _ = require("lodash")
const styleSearch = require("style-search")
const ruleName = "selector-pseudo-class-parentheses-space-inside"
const messages = ruleMessages(ruleName, {
expectedOpening: "Expected single space after \"(\"",
rejectedOpening: "Unexpected whitespace after \"(\"",
expectedClosing: "Expected single space before \")\"",
rejectedClosing: "Unexpected whitespace before \")\"",
})
const rule = function (expectation) {
return (root, result) => {
const validOptions = validateOptions(result, ruleName, {
actual: expectation,
possible: [
"always",
"never",
],
})
if (!validOptions) {
return
}
root.walkRules(rule => {
if (!isStandardSyntaxRule(rule)) {
return
}
if (rule.selector.indexOf("(") === -1) {
return
}
parseSelector(rule.selector, result, rule, selectorTree => {
selectorTree.walkPseudos(pseudoNode => {
if (_.get(pseudoNode, "parent.parent.type") === "pseudo") {
return
}
const pseudoSelectorString = pseudoNode.toString()
styleSearch({ source: pseudoSelectorString, target: "(" }, match => {
const nextCharIsSpace = pseudoSelectorString[match.startIndex + 1] === " "
const index = pseudoNode.sourceIndex + match.startIndex + 1
if (nextCharIsSpace && expectation === "never") {
complain(messages.rejectedOpening, index)
}
if (!nextCharIsSpace && expectation === "always") {
complain(messages.expectedOpening, index)
}
})
styleSearch({ source: pseudoSelectorString, target: ")" }, match => {
const prevCharIsSpace = pseudoSelectorString[match.startIndex - 1] === " "
const index = pseudoNode.sourceIndex + match.startIndex - 1
if (prevCharIsSpace && expectation === "never") {
complain(messages.rejectedClosing, index)
}
if (!prevCharIsSpace && expectation === "always") {
complain(messages.expectedClosing, index)
}
})
})
})
function complain(message, index) {
report({
message,
index,
result,
ruleName,
node: rule,
})
}
})
}
}
rule.ruleName = ruleName
rule.messages = messages
module.exports = rule