-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
PSR2.Methods.FunctionCallSignature.SpaceBeforeCloseBracket bug #3477
Comments
The problem here is the trailing comma after the last function argument. The fixer is getting into a loop where There is nothing in the standard that forbids a trailing comma after the last argument, but you don't see this very often so it is assumed to never be there. I could change
But it's technically invalid PSR2 code because the standards says:
and also says:
The other option is to write a new sniff to enforce no trailing comma after the last argument. PSR2 doesn't explicitly state this this is not allowed, but the rule can be inferred from the code samples. This is probably cleaner. Either way, it's a BC break. I may consider a change for version 3.7.0, so I'll add it to the roadmap. |
Why not just also removing this trailing comma here? That would make most sense IMO, as the comma is not expected there as you said, so it should be safe to do that given that a closing brace follows after
would be the result which is fine and prevents any such loop - and minimizes side effects. If a sniff changes those two lines and merged them I think it is expected for this now wrong comma to be removed. |
That's exactly what I said in my comment. I'd need a new sniff to do it because the other sniffs are not enforcing trailing commas. But whatever I do, it's a BC break because PHPCS is working differently than before. |
Interesting, I would have placed it in the same sniff as this one on its own (without others) is responsible for a safe and complete replace of the two lines into one. |
I dont think so, it is currently failing (breaking hard as it not further being able to fix the file at all) due to the loop issue. I see two options:
|
It's a potentially useful sniff all by itself, so some developers may want to include it in their standard without including all the side effects of the other sniffs that enforce specific formatting.
It's not.
You and I might not, but don't assume nobody does. If I make the change and someone cares, it's my time that's wasted doing a revert and re-release. |
Just for context: PSR2 (and PSR12 for that matter) were published before trailing comma's in function calls were allowed (PHP 7.3), so the fact that the PSRs don't allow/forbid those specifically, actually doesn't mean anything. It just wasn't something for which a rule was needed yet. |
Sure, but then they wouldnt use any of those sniffs in the first place. People either use that sniff as fully working, or they use sth else. But I dont see how keeping the sniff half-working is a fair option in this case. I silenced the side effect issue for now, which works for us: <rule ref="Generic.Functions.FunctionCallArgumentSpacing.NoSpaceAfterComma">
<severity>0</severity>
</rule> |
We managed to add spryker/code-sniffer#313 in order to remove the silencing again. |
I'll remove this from the 3.7 milestone as it's no longer a priority, but will leave open to see if other developers encounter this and it becomes a bigger issues. |
@gsherwood with newer php versions trailing commas are more and more common thing. Also it confuses people because they don't really know why fixer failed on the file. |
Closing as fixed via PR #3805. The fix will be included in PHPCS 3.8.0. |
FYI: the fix for this issue is included in today's PHP_CodeSniffer 3.8.0 release. As per #3932, development on PHP_CodeSniffer will continue in the PHPCSStandards/PHP_CodeSniffer repository. If you want to stay informed, you may want to start "watching" that repo (or watching releases from that repo). |
Describe the bug
The rule breaks with an fail to fix.
Code sample
shows
Trying to fix it (phpcbf):
It breaks here hard.
Note: The code uses tabs and is configured as such (
<arg name="tab-width" value="4"/>
).Expected behavior
Auto fixing this , or not reporting it to be fixable.
I need to manually fix it to this for sniffer to work again and also fix the other things in this file:
The text was updated successfully, but these errors were encountered: