-
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.ControlStructures.ControlStructureSpacing.SpacingAfterOpenBrace false positive #1829
Comments
I found #460 now. GitHub search is not fuzzy it seems. So the problem would be that the fix would not play well together with the fixer tool? |
The problem is that PSR-2 does not describe this as valid syntax and nobody from the PHP-FIG has ever said otherwise, or added errata about it. So the only rule to go on is:
Which I think is pretty clear. You can't have whitespace after the opening parenthesis, so the first condition can't start on the next line. If you want to read the full discussion, you can do so on the issue you linked, but no additional information has ever been made available, so my position needs to stay the same: redefining "space" in PSR-2 to only mean a space character and not newlines would completely break PSR-2, so I'm not going to change PHPCS in this way. Hopefully that explains things. |
I see. Thanks for the clarification. Will probably just disable the sniff on my end to make multiline conditionals more readable (in my opinion). :) We can take a look at this later on if PSR2 is clarified on this point. Thanks! |
* Add newlineCount as option on LongFunctionSniff * Run Prettier on LongFunctionSniff * Ignore SpacingAfterOpenBrace rule See squizlabs/PHP_CodeSniffer#1829 * Add new fixture for LongFunctionSniff * Add tests for maxFunctionLines
For anyone coming here in 2023+ as I did, PSR-2 has been deprecated in favour of PSR-12 which fixes this issue. |
When using the
PSR2
ruleset I'm getting an error for the following:Error states the following
When I alter the code as follows then the error disappears:
From my understanding PSR2 does allow a newline after the opening parenthesis if the
if
conditions are split to multiple lines. Or am I wrong and the sniff is working as expected?Also the sniff is a bit confusing as it says the newline is next to a bracket instead of the opening parenthesis.
The text was updated successfully, but these errors were encountered: