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,54 @@
# declaration-block-no-shorthand-property-overrides
Disallow shorthand properties that override related longhand properties.
```css
a { background-repeat: repeat; background: green; }
/** ↑
* This overrides the longhand property before it */
```
In almost every case, this is just an authorial oversight. For more about this behavior, see [MDN's documentation of shorthand properties](https://developer.mozilla.org/en-US/docs/Web/CSS/Shorthand_properties).
## Options
### `true`
The following patterns are considered warnings:
```css
a {
padding-left: 10px;
padding: 20px;
}
```
```css
a {
transition-property: opacity;
transition: opacity 1s linear;
}
```
```css
a {
border-top-width: 1px;
top: 0;
bottom: 3px;
border: 2px solid blue;
}
```
The following patterns are *not* considered warnings:
```css
a { padding: 10px; padding-left: 20px; }
```
```css
a { transition-property: opacity; } a { transition: opacity 1s linear; }
```
```css
a { transition-property: opacity; -webkit-transition: opacity 1s linear; }
```

View File

@@ -0,0 +1,57 @@
"use strict"
const report = require("../../utils/report")
const ruleMessages = require("../../utils/ruleMessages")
const shorthandData = require("../../reference/shorthandData")
const validateOptions = require("../../utils/validateOptions")
const ruleName = "declaration-block-no-shorthand-property-overrides"
const messages = ruleMessages(ruleName, {
rejected: (shorthand, original) => `Unexpected shorthand "${shorthand}" after "${original}"`,
})
const rule = function (actual) {
return (root, result) => {
const validOptions = validateOptions(result, ruleName, { actual })
if (!validOptions) {
return
}
root.walkRules(check)
root.walkAtRules(check)
function check(statement) {
const declarations = {}
// Shallow iteration so nesting doesn't produce
// false positives
statement.each(node => {
if (node.type !== "decl") {
return
}
const prop = node.prop
const overrideables = shorthandData[prop.toLowerCase()]
if (!overrideables) {
declarations[prop.toLowerCase()] = prop
return
}
overrideables.forEach(longhandProp => {
if (!declarations.hasOwnProperty(longhandProp)) {
return
}
report({
ruleName,
result,
node,
message: messages.rejected(prop, declarations[longhandProp]),
})
})
})
}
}
}
rule.ruleName = ruleName
rule.messages = messages
module.exports = rule