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,53 @@
# time-min-milliseconds
Specify the minimum number of milliseconds for time values.
```css
a { animation: slip-n-slide 150ms linear; }
/** ↑
* This time */
```
This rule checks positive numbers in `transition-duration`, `transition-delay`, `animation-duration`, `animation-delay`, and those times as they manifest in the `transition` and `animation` shorthands.
## Options
`int`: Minimum number of milliseconds for time values.
For example, with `100`:
The following patterns are considered warnings:
```css
a { animation: 80ms; }
```
```css
a { transition-duration: 0.08s; }
```
```css
a { transition: background-color 6ms linear; }
```
```css
a { animation-delay: 0.01s; }
```
The following patterns are *not* considered warnings:
```css
a { animation: 8s; }
```
```css
a { transition-duration: 0.8s; }
```
```css
a { transition: background-color 600ms linear; }
```
```css
a { animation-delay: 1s; }
```

View File

@@ -0,0 +1,85 @@
"use strict"
const _ = require("lodash")
const declarationValueIndex = require("../../utils/declarationValueIndex")
const report = require("../../utils/report")
const ruleMessages = require("../../utils/ruleMessages")
const validateOptions = require("../../utils/validateOptions")
const keywordSets = require("../../reference/keywordSets")
const postcss = require("postcss")
const valueParser = require("postcss-value-parser")
const ruleName = "time-min-milliseconds"
const messages = ruleMessages(ruleName, {
expected: time => `Expected a minimum of ${time} milliseconds`,
})
const rule = function (minimum) {
return (root, result) => {
const validOptions = validateOptions(result, ruleName, {
actual: minimum,
possible: _.isNumber,
})
if (!validOptions) {
return
}
root.walkDecls(decl => {
const propertyName = postcss.vendor.unprefixed(decl.prop.toLowerCase())
if (
keywordSets.longhandTimeProperties.has(propertyName)
&& !isAcceptableTime(decl.value)
) {
complain(decl)
}
if (keywordSets.shorthandTimeProperties.has(propertyName)) {
const valueList = postcss.list.space(decl.value)
for (const value of valueList) {
if (!isAcceptableTime(value)) {
complain(decl, decl.value.indexOf(value))
}
}
}
})
function isAcceptableTime(time) {
const parsedTime = valueParser.unit(time)
if (!parsedTime) return true
if (parsedTime.number <= 0) {
return true
}
if (parsedTime.unit.toLowerCase() === "ms" && parsedTime.number < minimum) {
return false
}
if (parsedTime.unit.toLowerCase() === "s" && parsedTime.number * 1000 < minimum) {
return false
}
return true
}
function complain(decl, offset) {
offset = offset || 0
report({
result,
ruleName,
message: messages.expected(minimum),
index: declarationValueIndex(decl) + offset,
node: decl,
})
}
}
}
rule.ruleName = ruleName
rule.messages = messages
module.exports = rule