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,33 @@
# custom-media-pattern
Specify a pattern for custom media query names.
```css
@custom-media --foo (max-width: 30em);
/** ↑
* The pattern of this */
```
## Options
`regex|string`
A string will be translated into a RegExp like so `new RegExp(yourString)` so be sure to escape properly.
Given the string:
```js
"foo-.+"
```
The following patterns are considered warnings:
```css
@custom-media --bar (min-width: 30em);
```
The following patterns are *not* considered warnings:
```css
@custom-media --foo-bar (min-width: 30em);
```

View File

@@ -0,0 +1,54 @@
"use strict"
const _ = require("lodash")
const atRuleParamIndex = require("../../utils/atRuleParamIndex")
const report = require("../../utils/report")
const ruleMessages = require("../../utils/ruleMessages")
const validateOptions = require("../../utils/validateOptions")
const ruleName = "custom-media-pattern"
const messages = ruleMessages(ruleName, {
expected: "Expected custom media query name to match specified pattern",
})
const rule = function (pattern) {
return (root, result) => {
const validOptions = validateOptions(result, ruleName, {
actual: pattern,
possible: [
_.isRegExp,
_.isString,
],
})
if (!validOptions) {
return
}
const regexpPattern = _.isString(pattern) ? new RegExp(pattern) : pattern
root.walkAtRules(atRule => {
if (atRule.name.toLowerCase() !== "custom-media") {
return
}
const customMediaName = atRule.params.match(/^--(\S+)\b/)[1]
if (regexpPattern.test(customMediaName)) {
return
}
report({
message: messages.expected,
node: atRule,
index: atRuleParamIndex(atRule),
result,
ruleName,
})
})
}
}
rule.ruleName = ruleName
rule.messages = messages
module.exports = rule