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

Update: Add enforceForSwitchCase option to use-isnan #12106

Merged
merged 2 commits into from Sep 29, 2019
Merged

Update: Add enforceForSwitchCase option to use-isnan #12106

merged 2 commits into from Sep 29, 2019

Conversation

mdjermanovic
Copy link
Member

@mdjermanovic mdjermanovic commented Aug 17, 2019

What is the purpose of this pull request? (put an "X" next to item)

[X] Changes an existing rule

Refs #12207

What rule do you want to change?

use-isnan

Does this change cause the rule to produce more or fewer warnings?

More if the option is set.

How will the change be implemented? (New option, new default behavior, etc.)?

New option, which might be removed in major version to be new default behavior.

Please provide some example code that this change will affect:

/*eslint use-isnan: ["error", {"enforceForSwitchCase": true}]*/

switch (foo) {
    case NaN:
        bar();
        break;
    case 1:
        baz();
        break;
    // ...
}

What does the rule currently do for this code?

Nothing.

What will the rule do after it's changed?

Report warning.

case NaN is a possible error, basically the same as foo === NaN which the rule targets.

What changes did you make? (Give an overview)

New option.

Is there anything you'd like reviewers to focus on?

  • The message in general. Also, there was an issue use-isnan should recommand using Number.isNaN #375 should the rule recommend Number.isNaN.
  • The correct example in docs, is there a 'better' way to solve it?
  • Should the same option also report switch (NaN)?

I'll submit another PR for .indexOf() and .lastIndexOf(), that should be a separate option (and stay as an option) as it can cause false positives due to the limitations, so someone might want to turn these off.

@eslint-deprecated eslint-deprecated bot added the triage An ESLint team member will look at this issue soon label Aug 17, 2019
@mdjermanovic mdjermanovic added enhancement This change enhances an existing feature of ESLint evaluating The team will evaluate this issue to decide whether it meets the criteria for inclusion rule Relates to ESLint's core rules and removed triage An ESLint team member will look at this issue soon labels Aug 24, 2019
@mdjermanovic
Copy link
Member Author

Marking as accepted as the issue #12207 is accepted.

@mdjermanovic mdjermanovic added accepted There is consensus among the team that this change meets the criteria for inclusion and removed evaluating The team will evaluate this issue to decide whether it meets the criteria for inclusion labels Sep 9, 2019
Copy link
Member

@platinumazure platinumazure left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

@mdjermanovic
Copy link
Member Author

I think that it would be also good to report switch(NaN), I just forgot that in the first commit.

@mysticatea
Copy link
Member

  • Covering switch(NaN) sounds good.
  • About Number.isNaN, a rule like prefer-number-isnan may be useful?

@g-plane
Copy link
Member

g-plane commented Sep 13, 2019

About Number.isNaN, a rule like prefer-number-isnan may be useful?

@mysticatea There are also something like preferring parseInt to Number.parseInt and preferring parseFloat to Number.parseFloat, so that rule shouldn't be only for Number.isNaN.

@mdjermanovic
Copy link
Member Author

  • Covering switch(NaN) sounds good.

I'll do this behind the same option, so please don't merge this PR yet :)

  • About Number.isNaN, a rule like prefer-number-isnan may be useful?

I was asking for this particular rule, because in #375 was a discussion should the rule ever recommend Number.isNaN because it isn't available in all environments.

@mdjermanovic mdjermanovic added the do not merge This pull request should not be merged yet label Sep 17, 2019
@mdjermanovic mdjermanovic removed the do not merge This pull request should not be merged yet label Sep 17, 2019
@mdjermanovic
Copy link
Member Author

  • Covering switch(NaN) sounds good.

This is done, and the option is now ready for a re-review.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
accepted There is consensus among the team that this change meets the criteria for inclusion archived due to age This issue has been archived; please open a new issue for any further discussion enhancement This change enhances an existing feature of ESLint rule Relates to ESLint's core rules
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants