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: fix false positive/negative of yoda rule (fixes #7676) #7695

Merged
merged 4 commits into from Dec 9, 2016

Conversation

mysticatea
Copy link
Member

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

[X] Bug fix (template)

See #7676 for the template.

What changes did you make? (Give an overview)

The yoda rule has a false positive and a false negative.
This PR fixes those bugs.

  • c62b847 fixed the false negative about computed properties in the range check.

    /*eslint yoda: [error, never, {exceptRange: true}] */
    if (0 <= a.b && a[b] < 10) {}

    The yoda rule has been handling a.b and a[b] as the same then it determines the condition is a range check wrongly. As the result, it should warn the 0 <= a.b but does not warn it. After this PR is applied, the yoda rule will warn the 0 <= a.b correctly. (semver-minor)

  • bf9982f fixed the false positive about variables in the range check.

    /*eslint yoda: [error, never, {exceptRange: true}] */
    if (0 <= index && index < list.length) {}

    The yoda rule has not been handling 0 <= index && index < list.length as a range check wrongly. As the result, it should not warn 0 <= index but warns it. After this PR is applied, the yoda rule will ignore the 0 <= index && index < list.length correctly. (semver-patch)

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

Nothing in particular.

@mysticatea mysticatea added accepted There is consensus among the team that this change meets the criteria for inclusion bug ESLint is working incorrectly rule Relates to ESLint's core rules labels Dec 4, 2016
@mention-bot
Copy link

@mysticatea, thanks for your PR! By analyzing the history of the files in this pull request, we identified @btmills, @vitorbal and @not-an-aardvark to be potential reviewers.

@eslintbot
Copy link

LGTM

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.

Could we have a test which checks that 0 <= a.b && a["b"] <= 100 is valid with exceptRange, if one doesn't exist?

@eslintbot
Copy link

LGTM

@mysticatea
Copy link
Member Author

@platinumazure Thank you!
I updated this PR for it.

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!

Copy link
Member

@btmills btmills left a comment

Choose a reason for hiding this comment

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

Just the one request for the JSDoc comment, otherwise LGTM. Thanks @mysticatea!

@@ -54,13 +54,15 @@ function looksLikeLiteral(node) {
/**
* Attempts to derive a Literal node from nodes that are treated like literals.
* @param {ASTNode} node Node to normalize.
* @param {number} [defaultValue] The default value to be returned if the node
* is not a Literal.
* @returns {ASTNode} The original node if the node is already a Literal, or a
* normalized Literal node with the negative number as the
* value if the node represents a negative number literal,
* otherwise null if the node cannot be converted to a
* normalized literal.
Copy link
Member

Choose a reason for hiding this comment

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

Can you update the return value description to note when it will return the default value?

Copy link
Member Author

Choose a reason for hiding this comment

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

Thank you, I updated the JSDoc comment.

Copy link
Member

@not-an-aardvark not-an-aardvark 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!

@eslintbot
Copy link

LGTM

Copy link
Member

@btmills btmills 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 @mysticatea!

Copy link
Member

@kaicataldo kaicataldo 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!

@btmills btmills merged commit e569225 into master Dec 9, 2016
@alberto alberto deleted the issue7676 branch December 15, 2016 22:06
@eslint-deprecated eslint-deprecated bot locked and limited conversation to collaborators Feb 6, 2018
@eslint-deprecated eslint-deprecated bot added the archived due to age This issue has been archived; please open a new issue for any further discussion label Feb 6, 2018
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 bug ESLint is working incorrectly rule Relates to ESLint's core rules
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants