-
-
Notifications
You must be signed in to change notification settings - Fork 4.6k
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: for-direction detection false positives/negatives #11254
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.
Thanks for contributing! Left one inline note.
In addition: Could you please add tests (if not already present) for cases where the for increment direction "could be wrong" but the step size is a variable?
For example:
for(var i = 0; i < MAX; i -= STEP_SIZE);
To me, those examples should be valid because we don't know if STEP_SIZE is positive or negative.
Also, since this change can introduce more warnings, the commit summary tag should say "Update". Would you mind making that change as well? (Simplest way to do that is to push new commits without squashing, then edit the PR title.)
tests/lib/rules/for-direction.js
Outdated
"for(var i = 10; i >= 0; i %= 2){}" | ||
"for(var i = 10; i >= 0; i %= 2){}", | ||
"for(var i = 0; i < MAX; i += STEP_SIZE);", | ||
"for(var i = MAX; i < MIN; i -= STEP_SIZE);" |
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.
Looks like this should say i > MIN
.
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.
It was meant as test which you requested and I was to lazy to change the variable names, so it seemed confusing afterwards. I fixed that now and added another one on top.
184efa5
to
904b9c0
Compare
@platinumazure Friendly ping, have your suggestions been addressed? |
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.
LGTM, thanks! Sorry for not following up sooner.
What is the purpose of this pull request? (put an "X" next to item)
[ ] Documentation update
[x] Bug fix (template)
[ ] New rule (template)
[ ] Changes an existing rule (template)
[ ] Add autofixing to a rule
[ ] Add a CLI option
[ ] Add something to the core
[ ] Other, please explain:
What changes did you make? (Give an overview)
I updated the for-direction rule to prevent false positives and false negatives.
Is there anything you'd like reviewers to focus on?
No