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

Fix: no-plusplus allow comma operands in for afterthought (fixes #13005) #13024

Merged
merged 2 commits into from Mar 18, 2020

Conversation

mdjermanovic
Copy link
Member

Prerequisites checklist

  • I have read the contributing guidelines.
  • The team has reached consensus on the changes proposed in this pull request. If not, I understand that the evaluation process will begin with this pull request and won't be merged until the team has reached consensus.

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

[X] Bug fix

fixes #13005

What changes did you make? (Give an overview)

allowForLoopAfterthoughts in the no-plusplus rule will now additionally allow ++ and -- in sequence expressions:

/*eslint no-plusplus: ["error", { "allowForLoopAfterthoughts": true }]*/

for (i = 0, j = 0; i < l; i++, j++); // ok

Also fixed false negatives when the node isn't the update node:

for (i++;;);

for (; i++;);

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

@mdjermanovic mdjermanovic added bug ESLint is working incorrectly rule Relates to ESLint's core rules accepted There is consensus among the team that this change meets the criteria for inclusion labels Mar 10, 2020
Copy link
Member

@yeonjuan yeonjuan 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 👍

}]
},
{
code: "for (;; i++, f(--j));",
Copy link
Member

@yeonjuan yeonjuan Mar 10, 2020

Choose a reason for hiding this comment

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

non-blocking.Just questions for understanding the proper behavior of this option.

It seems the option{allowForLoopAfterthoughts: true} changed to allow update expressions in sequence expression which has exactly one depth from for-loop update.

so the case like f(--j) is still warned.

And so, the below cases(nested sequence expression) are intended in the same manner?

for (;; (++a, (++b, ++c) ) {}  // it's warned in the PR version. no-plusplus for `b` and `c`

Copy link
Member Author

Choose a reason for hiding this comment

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

Didn't think of that. It's done now, thanks!

* @param {ASTNode} node The node to check.
* @returns {boolean} `true` if the node is a for loop afterthought.
*/
function isForLoopAfterthought(node) {
Copy link
Member

Choose a reason for hiding this comment

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

As @yeonjuan mentioned, it appears that this check only looks up one level, which could mean some patterns will still be flagged as incorrect.

for (;; (++a, (++b, ++c) ) {}  // it's warned in the PR version. no-plusplus for `b` and `c`

It may be an unlikely case, but for the sake of completeness, it probably makes sense to continue looking up the AST if the parent is a SequenceExpression.

Copy link
Member Author

Choose a reason for hiding this comment

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

It's done now! It makes sense to me, too.

Copy link
Member

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

@nzakas nzakas left a comment

Choose a reason for hiding this comment

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

Awesome job, thanks!

@kaicataldo
Copy link
Member

LGTM, thanks!

@kaicataldo kaicataldo merged commit 7224eee into master Mar 18, 2020
@kaicataldo kaicataldo deleted the issue13005 branch March 18, 2020 01:36
anikethsaha pushed a commit to anikethsaha/eslint that referenced this pull request Mar 23, 2020
…nt#13005) (eslint#13024)

* Fix: no-plusplus allow comma operands in for afterthought (fixes eslint#13005)

* Allow deep sequence operands
@eslint-deprecated eslint-deprecated bot locked and limited conversation to collaborators Sep 16, 2020
@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 Sep 16, 2020
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
4 participants