-
-
Notifications
You must be signed in to change notification settings - Fork 60
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/OpeningFunctionBraceKernighanRichie: improve test coverage #707
Generic/OpeningFunctionBraceKernighanRichie: improve test coverage #707
Conversation
ea6c6ec
to
f8639a2
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 Thanks for this PR. I think it's a great start, but can be improved further.
Looking at the tests, I see the following:
Missing:
- Test with an abstract method (no scope opener).
- Live coding test missing the opening curly.
- Live coding test with an open curly, but missing the close curly x 3 - one with correct spacing, one with too much space before the curly, one with no space before the curly. Both these last two should be fixable (and fixed).
Superfluous:
- Live coding test missing open parentheses. The sniff is not looking at that.
Looking at the handling of tabs... I don't think the multi-tab situation is handled correctly.
If you run the sniff against test case file 2, you will get the following error for the multi-tab line:
10 | ERROR | [x] Expected 1 space before opening brace; found 3 (Generic.Functions.OpeningFunctionBraceKernighanRitchie.SpaceBeforeBrace)
... which has no indication that this is 3 tabs, not 3 spaces.
If tabs are called out separately anyway (as is done in this sniff), let's do it correctly and consistently.
And if we're talking redundant code, I think the whole code block from line 75 to line 82 can be removed as long as the $closeBracket
reference on line 85 is replaced with null
.
What do you think ?
src/Standards/Generic/Tests/Functions/OpeningFunctionBraceKernighanRitchieUnitTest.1.inc
Outdated
Show resolved
Hide resolved
src/Standards/Generic/Tests/Functions/OpeningFunctionBraceKernighanRitchieUnitTest.3.inc
Outdated
Show resolved
Hide resolved
e4f38f1
to
0111d93
Compare
Thanks for your detailed review, @jrfnl!
There is an abstract method declared in an interface, and I assumed it was enough as the sniff doesn't really check where the method is defined. That being said, having an abstract method declared in a class is not a problem, so I went ahead and added one.
👍
I might be missing something, but it seems to me the sniff will bail early in those three cases, as when there is no closing curly brace, This is one of the code examples that I have in mind reading your comment: function missingClosingCurlyBrace() { I'm assuming you are not suggesting that I change the behavior of the sniff to handle those cases.
I replaced this test with a test for the missing opening curly brace.
I agree, but I don't see an easy and straightforward way to fix it. Especially as there could be a mix of spaces and tabs used. Would it be ok to open an issue for this instead of fixing it in this PR?
Good catch! I removed it in a new commit. |
Well, sort of. I mean, this sniff is limiting its own ability by checking for the Having said that, I agree that should probably be left as "future scope" (and low priority).
I do see a straight-forward way to fix this, so I will submit a follow-up PR after merging this one. No need for the issue. |
…findPrevious() This commit removes a repeated call to findPrevious() to get the pointer to the end of the function declaration. The same `$prev` variable that was defined a few lines above can be reused and there is no need to define it again calling `findPrevious()` with exactly the same parameters.
… in a fixer This commit makes a tiny performance improvement to the sniff when handling fixing code with tabs. Before this change, the sniff would need two passes of the fixer for code with one tab before the opening brace. First, it would add a space between the tab and the opening brace. Then, on a second pass, it would replace the tab and the space with just one space. Now, it replaces the tab with the space directly without the need for a second pass.
Doing this to be able to create tests with syntax errors on separate files.
Includes removing unnecessary trailing spaces from empty lines in the test file.
…end of the function signature When finding the end of the function signature, the sniff had an unnecessary block of code to change the `$end` parameter passed to `findPrevious()` when handling a closure with a `use` statement. Since we are looking for the first non-empty token before the opening curly brace, it is not necessary to change the value of the `$end` parameter. Actually, we don't even need to limit the search and we can pass `null` (the default value). The returned first non-empty token will be the same anyway regardless if `$end` is the closing parenthesis before `use`, after `use` or `null`.
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 those updates @rodrigoprimo.
I'm going to rebase the PR and squash a few commits together. Merging once the build has passed.
0111d93
to
286cd81
Compare
Description
This PR improves code coverage for the
Generic.Functions.OpeningFunctionBraceKernighanRichie
sniff and makes some tiny improvements to the sniff code. No user-facing changes were made.Related issues/external references
Part of #146
Types of changes
PR checklist