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,85 @@
# selector-attribute-quotes
Require or disallow quotes for attribute values.
```css
[target="_blank"] {}
/** ↑ ↑
* These quotes */
```
## Options
`string`: `"always"|"never"`
### `"always"`
Attribute values *must always* be quoted.
The following patterns are considered warnings:
```css
[title=flower] {}
```
```css
[class^=top] {}
```
The following patterns are *not* considered warnings:
```css
[title] {}
```
```css
[target="_blank"] {}
```
```css
[class|="top"] {}
```
```css
[title~='text'] {}
```
```css
[data-attribute='component'] {}
```
### `"never"`
Attribute values *must never* be quoted.
The following patterns are considered warnings:
```css
[target="_blank"] {}
```
```css
[class|="top"] {}
```
```css
[title~='text'] {}
```
```css
[data-attribute='component'] {}
```
The following patterns are *not* considered warnings:
```css
[title] {}
```
```css
[title=flower] {}
```
```css
[class^=top] {}
```

View File

@@ -0,0 +1,70 @@
"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 ruleName = "selector-attribute-quotes"
const messages = ruleMessages(ruleName, {
expected: value => `Expected quotes around "${value}"`,
rejected: value => `Unexpected quotes around "${value}"`,
})
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 || rule.selector.indexOf("=") === -1) {
return
}
parseSelector(rule.selector, result, rule, selectorTree => {
selectorTree.walkAttributes(attributeNode => {
if (!attributeNode.operator) {
return
}
const attributeSelectorString = attributeNode.toString()
if (!attributeNode.quoted && expectation === "always") {
complain(messages.expected(attributeNode.raws.unquoted), attributeNode.sourceIndex + attributeSelectorString.indexOf(attributeNode.value))
}
if (attributeNode.quoted && expectation === "never") {
complain(messages.rejected(attributeNode.raws.unquoted), attributeNode.sourceIndex + attributeSelectorString.indexOf(attributeNode.value))
}
})
})
function complain(message, index) {
report({
message,
index,
result,
ruleName,
node: rule,
})
}
})
}
}
rule.ruleName = ruleName
rule.messages = messages
module.exports = rule