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,57 @@
# at-rule-whitelist
Specify a whitelist of allowed at-rules.
```css
@keyframes name {}
/** ↑
* At-rules like this */
```
## Options
`array|string`: `["array", "of", "unprefixed", "at-rules"]|"at-rule"`
Given:
```js
["extend", "keyframes"]
```
The following patterns are considered warnings:
```css
@import "path/to/file.css";
```
```css
@media screen and (max-width: 1024px) {
a { display: none; }
}
```
The following patterns are *not* considered warnings:
```css
a { @extend placeholder; }
```
```css
@keyframes name {
from { top: 10px; }
to { top: 20px; }
}
```
```css
@KEYFRAMES name {
from { top: 10px; }
to { top: 20px; }
}
```
```css
@-moz-keyframes name {
from { top: 10px; }
to { top: 20px; }
}

View File

@@ -0,0 +1,48 @@
"use strict"
const _ = require("lodash")
const postcss = require("postcss")
const report = require("../../utils/report")
const ruleMessages = require("../../utils/ruleMessages")
const validateOptions = require("../../utils/validateOptions")
const ruleName = "at-rule-whitelist"
const messages = ruleMessages(ruleName, {
rejected: name => `Unexpected at-rule "${name}"`,
})
const rule = function (whitelistInput) {
// To allow for just a string as a parameter (not only arrays of strings)
const whitelist = [].concat(whitelistInput)
return (root, result) => {
const validOptions = validateOptions(result, ruleName, {
actual: whitelist,
possible: [_.isString],
})
if (!validOptions) {
return
}
root.walkAtRules(atRule => {
const name = atRule.name
if (whitelist.indexOf(postcss.vendor.unprefixed(name).toLowerCase()) !== -1) {
return
}
report({
message: messages.rejected(name),
node: atRule,
result,
ruleName,
})
})
}
}
rule.primaryOptionArray = true
rule.ruleName = ruleName
rule.messages = messages
module.exports = rule