-
-
Notifications
You must be signed in to change notification settings - Fork 57
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
Generic/JumbledIncrementer: fix non-problematic bug and improve test coverage #385
Generic/JumbledIncrementer: fix non-problematic bug and improve test coverage #385
Conversation
8bdf838
to
257630b
Compare
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.
@rodrigoprimo Thank you for this PR and my apologies for taking a while before reviewing it.
Generally speaking, all looking good! Thank you for making these changes.
There's a few small nitpicks, but nothing major.
While reviewing this PR, I noticed a few other things the sniff does not correctly take into account. I will open separate issues for those.
src/Standards/Generic/Sniffs/CodeAnalysis/JumbledIncrementerSniff.php
Outdated
Show resolved
Hide resolved
src/Standards/Generic/Tests/CodeAnalysis/JumbledIncrementerUnitTest.1.inc
Outdated
Show resolved
Hide resolved
src/Standards/Generic/Tests/CodeAnalysis/JumbledIncrementerUnitTest.1.inc
Outdated
Show resolved
Hide resolved
src/Standards/Generic/Tests/CodeAnalysis/JumbledIncrementerUnitTest.3.inc
Outdated
Show resolved
Hide resolved
src/Standards/Generic/Tests/CodeAnalysis/JumbledIncrementerUnitTest.1.inc
Show resolved
Hide resolved
21de8ad
to
346d211
Compare
346d211
to
f0845e5
Compare
Thanks for the review, @jrfnl! I believe I addressed the points that you raised. I had to force push commits to the branch as I dropped the commit that renamed a variable in the sniff code and added a new commit in between commits to rename variables for the pre-existing tests. This PR is ready for a final check. |
f0845e5
to
fc724d5
Compare
As per the comment I left in my previous review, I've now opened two issues for potential follow-up improvements for the sniff: #440 and #441 I also realized that I hadn't answered the questions you included in the description yet.
Good catch and yes, please feel invited to improve the documentation (docblock + XML ?). And as you already surmised, changing the sniff name would be a breaking change, so is not on the table.
I fully agree with you that this is a bug. Issue #441 contains a range of additional code samples running into the same issue. Please add your code sample in a comment to that ticket so it won't be overlooked by whomever starts working on that ticket. |
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.
@rodrigoprimo Thank you for working on this and making the requested updates.
I'll go ahead and reorganize the commits and rebase the PR before merging it.
I will fix up that comment change which got undone while doing that.
Doing this to be able to create tests with syntax errors on separate files.
Using `$same` instead of `$i` should help highlight which variable is expected to trigger the sniff when reading the test code.
The sniff was wrongly assuming that the inner for loop would always have a closing parenthesis which is not true when PHPCS is used with live coding. This meant that `$end` could be set to `null` (https://github.com/PHPCSStandards/PHP_CodeSniffer/blob/84acf4e56f110db8e75cb9a575c5727df637643c/src/Standards/Generic/Sniffs/CodeAnalysis/JumbledIncrementerSniff.php#L116). This did not cause any issues as `$next <= $end` when `$end` is `null` is always false, so the for loop that looks for incrementers was not executed. The code was changed to bail early when the inner for loop is missing the closing parenthesis and a test was added.
This commit adds tests for: - for alternative syntax - for loops missing one or more condition parts - sniff bails early when it encounters a parse error (missing for body and inner for loop missing opening parenthesis - for loops with more than one incrementer - for loops with decrementers
fc724d5
to
fd7b175
Compare
Description
This PR adds a few commits related to the Generic.CodeAnalysis.JumbledIncrementer sniff:
$end
would be set tonull
(src/Standards/Generic/Sniffs/CodeAnalysis/JumbledIncrementerSniff.php#L116) instead of set to the index of the closing parenthesis token. This problem did not cause any issues as$next <= $end
when$end
isnull
is always false, and the for loop that looks for incrementers ends early.Improve the name of a variableA few things that I noticed while working on this PR that I would like to confirm if they are indeed issues (probably in separate PRs):
Suggested changelog entry
Generic.CodeAnalysis.JumbledIncrementer: fixed a non-problematic bug when the inner for loop is missing the closing parenthesis
Related issues/external references
Part of #146
Types of changes
PR checklist