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:
39
node_modules/stylelint/lib/rules/number-max-precision/README.md
generated
vendored
Normal file
39
node_modules/stylelint/lib/rules/number-max-precision/README.md
generated
vendored
Normal file
@@ -0,0 +1,39 @@
|
||||
# number-max-precision
|
||||
|
||||
Limit the number of decimal places allowed in numbers.
|
||||
|
||||
```css
|
||||
a { top: 3.245634px; }
|
||||
/** ↑
|
||||
* These decimal places */
|
||||
```
|
||||
|
||||
## Options
|
||||
|
||||
`int`: Maximum number of decimal places allowed.
|
||||
|
||||
For example, with `2`:
|
||||
|
||||
The following patterns are considered warnings:
|
||||
|
||||
```css
|
||||
a { top: 3.245px; }
|
||||
```
|
||||
|
||||
```css
|
||||
a { top: 3.245634px; }
|
||||
```
|
||||
|
||||
```css
|
||||
@media (min-width: 3.234em) {}
|
||||
```
|
||||
|
||||
The following patterns are *not* considered warnings:
|
||||
|
||||
```css
|
||||
a { top: 3.24px; }
|
||||
```
|
||||
|
||||
```css
|
||||
@media (min-width: 3.23em) {}
|
||||
```
|
79
node_modules/stylelint/lib/rules/number-max-precision/index.js
generated
vendored
Normal file
79
node_modules/stylelint/lib/rules/number-max-precision/index.js
generated
vendored
Normal file
@@ -0,0 +1,79 @@
|
||||
"use strict"
|
||||
|
||||
const atRuleParamIndex = require("../../utils/atRuleParamIndex")
|
||||
const declarationValueIndex = require("../../utils/declarationValueIndex")
|
||||
const report = require("../../utils/report")
|
||||
const ruleMessages = require("../../utils/ruleMessages")
|
||||
const validateOptions = require("../../utils/validateOptions")
|
||||
|
||||
const _ = require("lodash")
|
||||
const valueParser = require("postcss-value-parser")
|
||||
|
||||
const ruleName = "number-max-precision"
|
||||
|
||||
const messages = ruleMessages(ruleName, {
|
||||
expected: (number, precision) => `Expected "${number}" to be "${number.toFixed(precision)}"`,
|
||||
})
|
||||
|
||||
const rule = function (precision) {
|
||||
return (root, result) => {
|
||||
const validOptions = validateOptions(result, ruleName, {
|
||||
actual: precision,
|
||||
possible: [_.isNumber],
|
||||
})
|
||||
if (!validOptions) {
|
||||
return
|
||||
}
|
||||
|
||||
root.walkAtRules(atRule => {
|
||||
if (atRule.name.toLowerCase() === "import") {
|
||||
return
|
||||
}
|
||||
|
||||
check(atRule, atRule.params, atRuleParamIndex)
|
||||
})
|
||||
|
||||
root.walkDecls(decl => check(decl, decl.value, declarationValueIndex))
|
||||
|
||||
function check(node, value, getIndex) {
|
||||
// Get out quickly if there are no periods
|
||||
if (value.indexOf(".") === -1) {
|
||||
return
|
||||
}
|
||||
|
||||
valueParser(value).walk(valueNode => {
|
||||
// Ignore `url` function
|
||||
if (valueNode.type === "function" && valueNode.value.toLowerCase() === "url") {
|
||||
return false
|
||||
}
|
||||
|
||||
// Ignore strings, comments, etc
|
||||
if (valueNode.type !== "word") {
|
||||
return
|
||||
}
|
||||
|
||||
const match = /\d*\.(\d+)/.exec(valueNode.value)
|
||||
|
||||
if (match === null) {
|
||||
return
|
||||
}
|
||||
|
||||
if (match[1].length <= precision) {
|
||||
return
|
||||
}
|
||||
|
||||
report({
|
||||
result,
|
||||
ruleName,
|
||||
node,
|
||||
index: getIndex(node) + valueNode.sourceIndex + match.index,
|
||||
message: messages.expected(parseFloat(match[0]), precision),
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
rule.ruleName = ruleName
|
||||
rule.messages = messages
|
||||
module.exports = rule
|
Reference in New Issue
Block a user