New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add "time-min-milliseconds" rule #2289
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@hudochenkov Thanks for this!
config: [MIN_VALUE], | ||
|
||
accept: [ { | ||
code: "a { transition-delay: 0.2s; }", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we get a test for 0.1s
please?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great catch! It was failing for 0.1s
and 100ms
:)
}, { | ||
code: "a { transition-delay: 3s; }", | ||
}, { | ||
code: "a { transition-delay: 200ms; }", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we get a test for 100ms
please?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Left a few comments.
@@ -62,6 +62,7 @@ Here are all the rules within stylelint, grouped by the [*thing*](http://apps.wo | |||
|
|||
### Time | |||
|
|||
- [`time-min-milliseconds`](../../lib/rules/time-min-milliseconds/README.md): Limit the minimum number of milliseconds for time values. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think "Specify" is a better word here than "Limit": "Specify the minimum number ..."
|
||
## Options | ||
|
||
`int`: Minimum number milliseconds for time values. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
number of milliseconds
``` | ||
|
||
```css | ||
a { animation: horse-dance 1s linear 0.01s; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I find this to be an ambiguous example. A reader might reasonably come away thinking both 1s
and 0.01s
are not ok. Let's just have one time value in each example, since no text specifies which particular value is the violator.
Same applies to the example below.
}, { | ||
code: "a { animation-duration: 0.15s; }", | ||
}, { | ||
code: "a { -webkitanimation-duration: 0.15s; }", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing hyphen, I think.
}, { | ||
code: "a { animation: foo 0.8s 200ms ease-in-out; }", | ||
}, { | ||
code: "a { animation-delay: -2.5s; }", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a little confusing and needs to be clarified in the docs. Do any negative values work? Or is the "minimum" actually an absolute value applying on both sides of zero?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good question! I think we should check only positive values.
According to specs transition-duration
and animation-duration
can't be negative. Negative values can be in shorthand properties transition
and animation
, but it's hard to parse what time is which in shorthands.
Also, negative delay is a rare case. Developer could set negative value in two cases: intentionally for some reason, or by mistake.
What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I agree: if transition-duration
and animation-duration
cannot be negative, then let's not use the absolute value here, and only check positive values.
const ruleName = "time-min-milliseconds" | ||
|
||
const messages = ruleMessages(ruleName, { | ||
expected: time => `Expected no less than ${time} milliseconds`, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's say Expected of a minimum of ${time} milliseconds
to avoid quarrels about "less" vs "fewer".
|
||
root.walkDecls(decl => { | ||
if (keywordSets.longhandTimeProperties.has(postcss.vendor.unprefixed(decl.prop.toLowerCase()))) { | ||
if (isNotAcceptableTime(decl.value)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These two conditions could be combined into one if statement.
} | ||
|
||
function complain(decl) { | ||
const offset = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ugh this is awkward. Can you use an explicit argument instead?
@davidtheclark Thank you for an excellent review. To be honest, I just took an old rule and changed few things to be a new rule ¯\_(ツ)_/¯ Will cleanup things. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One wording comment; and we also need changes to rules/index.js
and the example config when adding a new rule.
@@ -12,7 +12,7 @@ const valueParser = require("postcss-value-parser") | |||
const ruleName = "time-min-milliseconds" | |||
|
|||
const messages = ruleMessages(ruleName, { | |||
expected: time => `Expected no less than ${time} milliseconds`, | |||
expected: time => `Expected of a minimum of ${time} milliseconds`, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cut the first "of" here: Expected a minimum of ${time} ...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
There is an important question lost in outdated diff comments. What numbers should this rule check? And my opinion about it. |
@hudochenkov I responded above, then realized it might be lost in the diff, too:
|
Added to Changelog:
|
* Add "time-min-milliseconds" rule * Fix warnings if time is equals to config time * Fixes based on a feedback * Fix typo * Check only positive numbers
#2249
No, it's self explanatory.