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,56 @@
# property-blacklist
Specify a blacklist of disallowed properties.
```css
a { text-rendering: optimizeLegibility; }
/** ↑
* These properties */
```
## Options
`array|string`: `["array", "of", "unprefixed", "properties" or "regex"]|"property"|"/regex/"`
If a string is surrounded with `"/"` (e.g. `"/^background/"`), it is interpreted as a regular expression. This allows, for example, easy targeting of shorthands: `/^background/` will match `background`, `background-size`, `background-color`, etc.
Given:
```js
[ "text-rendering", "animation", "/^background/" ]
```
The following patterns are considered warnings:
```css
a { text-rendering: optimizeLegibility; }
```
```css
a {
animation: my-animation 2s;
color: pink;
}
```
```css
a { -webkit-animation: my-animation 2s; }
```
```css
a { background: pink; }
```
```css
a { background-size: cover; }
```
The following patterns are *not* considered warnings:
```css
a { color: pink; }
```
```css
a { no-background: sure; }
```

View File

@@ -0,0 +1,55 @@
"use strict"
const isCustomProperty = require("../../utils/isCustomProperty")
const isStandardSyntaxProperty = require("../../utils/isStandardSyntaxProperty")
const matchesStringOrRegExp = require("../../utils/matchesStringOrRegExp")
const report = require("../../utils/report")
const ruleMessages = require("../../utils/ruleMessages")
const validateOptions = require("../../utils/validateOptions")
const _ = require("lodash")
const postcss = require("postcss")
const ruleName = "property-blacklist"
const messages = ruleMessages(ruleName, {
rejected: property => `Unexpected property "${property}"`,
})
const rule = function (blacklist) {
return (root, result) => {
const validOptions = validateOptions(result, ruleName, {
actual: blacklist,
possible: [_.isString],
})
if (!validOptions) {
return
}
root.walkDecls(decl => {
const prop = decl.prop
if (!isStandardSyntaxProperty(prop)) {
return
}
if (isCustomProperty(prop)) {
return
}
if (!matchesStringOrRegExp(postcss.vendor.unprefixed(prop), blacklist)) {
return
}
report({
message: messages.rejected(prop),
node: decl,
result,
ruleName,
})
})
}
}
rule.primaryOptionArray = true
rule.ruleName = ruleName
rule.messages = messages
module.exports = rule