Skip to content
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

Merged
merged 5 commits into from Jan 29, 2017
Merged

Conversation

hudochenkov
Copy link
Member

Which issue, if any, is this issue related to?

#2249

Is there anything in the PR that needs further explanation?

No, it's self explanatory.

Copy link
Member

@jeddy3 jeddy3 left a 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; }",
Copy link
Member

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?

Copy link
Member Author

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; }",
Copy link
Member

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?

Copy link
Contributor

@davidtheclark davidtheclark left a 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.
Copy link
Contributor

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.
Copy link
Contributor

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; }
Copy link
Contributor

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; }",
Copy link
Contributor

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; }",
Copy link
Contributor

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?

Copy link
Member Author

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?

Copy link
Contributor

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`,
Copy link
Contributor

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)) {
Copy link
Contributor

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
Copy link
Contributor

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?

@hudochenkov
Copy link
Member Author

@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.

Copy link
Contributor

@davidtheclark davidtheclark left a 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`,
Copy link
Contributor

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} ...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@hudochenkov
Copy link
Member Author

hudochenkov commented Jan 28, 2017

There is an important question lost in outdated diff comments. What numbers should this rule check? And my opinion about it.

@davidtheclark
Copy link
Contributor

@hudochenkov I responded above, then realized it might be lost in the diff, too:

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.

@jeddy3 jeddy3 mentioned this pull request Jan 29, 2017
13 tasks
@davidtheclark davidtheclark merged commit 0464b2d into master Jan 29, 2017
@davidtheclark davidtheclark deleted the time-min-milliseconds branch January 29, 2017 17:33
@davidtheclark
Copy link
Contributor

Added to Changelog:

  • Added: time-min-milliseconds rule, to replace time-no-imperceptible (#2289).

sergesemashko pushed a commit to sergesemashko/stylelint that referenced this pull request Mar 3, 2017
* 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants