mirror of
https://github.com/snachodog/just-the-docs.git
synced 2025-09-13 13:23:32 -06:00
Initial commit
This commit is contained in:
100
node_modules/stylelint/lib/rules/unit-whitelist/README.md
generated
vendored
Normal file
100
node_modules/stylelint/lib/rules/unit-whitelist/README.md
generated
vendored
Normal file
@@ -0,0 +1,100 @@
|
||||
# unit-whitelist
|
||||
|
||||
Specify a whitelist of allowed units.
|
||||
|
||||
```css
|
||||
a { width: 100px; }
|
||||
/** ↑
|
||||
* These units */
|
||||
```
|
||||
|
||||
## Options
|
||||
|
||||
`array|string`: `["array", "of", "units"]|"unit"`
|
||||
|
||||
Given:
|
||||
|
||||
```js
|
||||
["px", "em", "deg"]
|
||||
```
|
||||
|
||||
The following patterns are considered warnings:
|
||||
|
||||
```css
|
||||
a { width: 100%; }
|
||||
```
|
||||
|
||||
```css
|
||||
a { font-size: 10rem; }
|
||||
```
|
||||
|
||||
```css
|
||||
a { animation: animation-name 5s ease; }
|
||||
```
|
||||
|
||||
The following patterns are *not* considered warnings:
|
||||
|
||||
```css
|
||||
a { font-size: 1.2em; }
|
||||
```
|
||||
|
||||
```css
|
||||
a { line-height: 1.2; }
|
||||
```
|
||||
|
||||
```css
|
||||
a { height: 100px; }
|
||||
```
|
||||
|
||||
```css
|
||||
a { height: 100PX; }
|
||||
```
|
||||
|
||||
```css
|
||||
a { transform: rotate(30deg); }
|
||||
```
|
||||
|
||||
## Optional secondary options
|
||||
|
||||
### `ignoreProperties: { unit: ["property", "/regex/"] }`
|
||||
|
||||
Ignore units in the values of declarations with the specified properties.
|
||||
|
||||
For example, with `["px", "em"]`.
|
||||
|
||||
Given:
|
||||
|
||||
```js
|
||||
{
|
||||
"rem": [ "line-height", "/^border/" ],
|
||||
"%": [ "width" ]
|
||||
}
|
||||
```
|
||||
|
||||
The following patterns are *not* considered warnings:
|
||||
|
||||
```css
|
||||
a { line-height: 0.1rem; }
|
||||
```
|
||||
|
||||
```css
|
||||
a { border-bottom-width: 6rem; }
|
||||
```
|
||||
|
||||
```css
|
||||
a { width: 100%; }
|
||||
```
|
||||
|
||||
The following patterns are considered warnings:
|
||||
|
||||
```css
|
||||
a { margin: 0 20rem; }
|
||||
```
|
||||
|
||||
```css
|
||||
a { -moz-border-radius-topright: 20rem; }
|
||||
```
|
||||
|
||||
```css
|
||||
a { height: 100%; }
|
||||
```
|
73
node_modules/stylelint/lib/rules/unit-whitelist/index.js
generated
vendored
Normal file
73
node_modules/stylelint/lib/rules/unit-whitelist/index.js
generated
vendored
Normal file
@@ -0,0 +1,73 @@
|
||||
"use strict"
|
||||
|
||||
const atRuleParamIndex = require("../../utils/atRuleParamIndex")
|
||||
const declarationValueIndex = require("../../utils/declarationValueIndex")
|
||||
const getUnitFromValueNode = require("../../utils/getUnitFromValueNode")
|
||||
const optionsMatches = require("../../utils/optionsMatches")
|
||||
const report = require("../../utils/report")
|
||||
const ruleMessages = require("../../utils/ruleMessages")
|
||||
const validateOptions = require("../../utils/validateOptions")
|
||||
const _ = require("lodash")
|
||||
const validateObjectWithStringArrayProps = require("../../utils/validateObjectWithStringArrayProps")
|
||||
const valueParser = require("postcss-value-parser")
|
||||
|
||||
const ruleName = "unit-whitelist"
|
||||
|
||||
const messages = ruleMessages(ruleName, {
|
||||
rejected: unit => `Unexpected unit "${unit}"`,
|
||||
})
|
||||
|
||||
const rule = function (whitelistInput, options) {
|
||||
const whitelist = [].concat(whitelistInput)
|
||||
return (root, result) => {
|
||||
const validOptions = validateOptions(result, ruleName, {
|
||||
actual: whitelist,
|
||||
possible: [_.isString],
|
||||
}, {
|
||||
optional: true,
|
||||
actual: options,
|
||||
possible: {
|
||||
ignoreProperties: validateObjectWithStringArrayProps,
|
||||
},
|
||||
})
|
||||
if (!validOptions) {
|
||||
return
|
||||
}
|
||||
|
||||
function check(node, value, getIndex) {
|
||||
valueParser(value).walk(function (valueNode) {
|
||||
// Ignore wrong units within `url` function
|
||||
if (valueNode.type === "function" && valueNode.value.toLowerCase() === "url") {
|
||||
return false
|
||||
}
|
||||
|
||||
const unit = getUnitFromValueNode(valueNode)
|
||||
|
||||
if (!unit || unit && whitelist.indexOf(unit.toLowerCase()) !== -1) {
|
||||
return
|
||||
}
|
||||
|
||||
if (options && optionsMatches(options["ignoreProperties"], unit.toLowerCase(), node.prop)) {
|
||||
return
|
||||
}
|
||||
|
||||
report({
|
||||
index: getIndex(node) + valueNode.sourceIndex,
|
||||
message: messages.rejected(unit),
|
||||
node,
|
||||
result,
|
||||
ruleName,
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
root.walkAtRules(/^media$/i, atRule => check(atRule, atRule.params, atRuleParamIndex))
|
||||
root.walkDecls(decl => check(decl, decl.value, declarationValueIndex))
|
||||
}
|
||||
}
|
||||
|
||||
rule.primaryOptionArray = true
|
||||
|
||||
rule.ruleName = ruleName
|
||||
rule.messages = messages
|
||||
module.exports = rule
|
Reference in New Issue
Block a user