-
-
Notifications
You must be signed in to change notification settings - Fork 61
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 fixer conflict: PSR12
/ Squiz.Functions.FunctionDeclarationArgumentSpacing
#620
base: master
Are you sure you want to change the base?
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.
Hi @fredden, thanks for this PR and for your continued work on the fixer conflicts.
I've reviewed the PR in detail and have a couple of remarks:
- First of all, please use a descriptive commit message.
In my opinion, it is important to have the information about the reason for the change and what problem is being solved codified in the commit message which is part of the code base. Now the information is only in the PR description, which makes agit blame
more involved and adds a dependency on the code hosting platform for finding the context for a commit (and those can change/go away, think: Sourceforge -> PEAR -> GitHub -> ??) - Second, please have a look at the text of the updated error message.
Previously, an error for the code snippet added in the tests would be reported like so:Note: the3 | ERROR | [x] Expected 1 space between type hint and argument "$number"; 0 found
0 found
which was wrong and should probably have readnewline found
.
However, now it is reported like so:... which I don't think is very informative.3 | ERROR | [x] Expected 1 space between type hint and argument "$number"; | | found
- I think the fixer code can be made more straight-forward by:
- Always adding a single whitespace to the
$param['type_hint_end_token']
. - Then looping over any whitespace tokens after the
$param['type_hint_end_token']
token and removing them.
- Always adding a single whitespace to the
- On that note: is the nondescript
$i
variable (in two places) really needed ? The$typeHintToken
(which would be better named$typeHintEndToken
) can be reset to the value of$param['type_hint_end_token']
at any time, so not sure the extra$i
variable has value. - Looking at the test now added, that test doesn't fully test the change being made as it still only fixes a single whitespace token.
I suggest adding a second test with an indented function declaration to ensure that multiple whitespace tokens are handled correctly and in one go:Also thefunction multipleWhitespaceTokensAfterType(int $number) {}
public
should probably be removed from the test already added, as it is a parse error outside of a class and is not needed for the test to be of value.
Other observations outside the scope of this PR/future scope:
- Should the error still be auto-fixable if there is a comment between the type and the variable ?
function commentBetweenTypeAndVariable(int //comment $number) {}
- Looking at other parts of the sniff, it seems that nearly all errors/fixers suffer from the same presumption - that a parameter declaration is always on one line - and only handle one whitespace token at a time.
Small PRs fixing it for one error at a time or a single PR with one commit per fix would allow for such a fix to stay reviewable.
Both of these last points should probably get their own ticket until these are solved.
…flict/PSR12/Squiz.Functions.FunctionDeclarationArgumentSpacing
Description
While looking into a fixer conflict for the PSR12 standard regarding the
tests/Core/File/GetMethodParametersTest.inc
file, it was noted that there is a conflict betweenSquiz.Functions.FunctionDeclarationArgumentSpacing
andSquiz.WhiteSpace.SuperfluousWhitespace
.To see this, run:
php bin/phpcbf --standard=PSR12 -v tests/Core/File/GetMethodParametersTest.inc
With verbosity increased, we can see the conflict:
Here is a small reproducible test case. Note the newline after the parameter type.
This pull request fixes the conflict by changing the logic within the sniff to no longer look at only one
T_WHITESPACE
token (and its length), but instead allT_WHITESPACE
tokens between the type and parameter tokens, and validate on their content (not length).Suggested changelog entry
Fix a fixer conflict:
PSR12
/Squiz.Functions.FunctionDeclarationArgumentSpacing
- newlines after type are now fixed properly.Related issues/external references
#152
Types of changes
PR checklist