You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The ScopeIndent sniff suggests a quite strange indentation when processing multi-nested match-statements
// It's a copy of my bug report from the old repo (squizlabs/PHP_CodeSniffer#3875)
// Thank you, Juliette, for an amazing initiative in keeping the project going!
Code sample
<?phpecho match (1) {
0 => match (2) {
2 => match (3) {
3 => 3,
default => -1,
},
},
1 => match (2) {
1 => match (3) {
3 => 3,
default => -1,
},
2 => match (3) {
3 => 3,
default => -1,
},
},
};
How that code will look if formatted as suggested
<?phpecho match (1) {
0 => match (2) {
2 => match (3) {
3 => 3,
default => -1,
},
},
1 => match (2) {
1 => match (3) {
3 => 3,
default => -1,
},
2 => match (3) {
3 => 3,
default => -1,
},
},
};
Custom ruleset
N/A — reproducible with PSR12
To reproduce
Steps to reproduce the behavior:
Create a file called test.php with the code sample above
Run phpcs -s --standard=psr12 test.php
See errors displayed
------------------------------------------------------------------------------------------------------------------------------
FOUND 4 ERRORS AFFECTING 4 LINES
------------------------------------------------------------------------------------------------------------------------------
15 | ERROR | [x] Line indented incorrectly; expected at least 12 spaces, found 8
| | (Generic.WhiteSpace.ScopeIndent.Incorrect)
16 | ERROR | [x] Line indented incorrectly; expected at least 16 spaces, found 12
| | (Generic.WhiteSpace.ScopeIndent.Incorrect)
17 | ERROR | [x] Line indented incorrectly; expected at least 16 spaces, found 12
| | (Generic.WhiteSpace.ScopeIndent.Incorrect)
18 | ERROR | [x] Line indented incorrectly; expected 12 spaces, found 8 (Generic.WhiteSpace.ScopeIndent.IncorrectExact)
------------------------------------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 4 MARKED SNIFF VIOLATIONS AUTOMATICALLY
------------------------------------------------------------------------------------------------------------------------------
Expected behavior
No indentation errors.
Versions (please complete the following information)
Operating System
macOS 12.5
PHP version
8.0
PHP_CodeSniffer version
3.9.0
Standard
PSR2
Install type
Local composer
Additional context
none
Please confirm:
I have searched the issue list and am not opening a duplicate issue.
I confirm that this bug is a bug in PHP_CodeSniffer and not in one of the external standards.
I have verified the issue still exists in the master branch of PHP_CodeSniffer.
The text was updated successfully, but these errors were encountered:
@jrfnl I'm in no way rushing it, and I want to do a patch at some later date. Sorry if it sounded like an attack, that wasn't my intention :)
I just saw that there were some changes around the processing of match-es in the last releases, and I wanted to save some time on retesting to anybody stumbling upon this ticket. I probably should've just updated the PHP_CodeSniffer version in the initial message 😅 I'll do better next time.
Both the mentioned issues are fixed by the improvements to the `File::findStartOfStatement()` method in this same PR.
Fixes#110Fixes#437
Fixes squizlabs/PHP_CodeSniffer 3875
Describe the bug
The ScopeIndent sniff suggests a quite strange indentation when processing multi-nested
match
-statements// It's a copy of my bug report from the old repo (squizlabs/PHP_CodeSniffer#3875)
// Thank you, Juliette, for an amazing initiative in keeping the project going!
Code sample
How that code will look if formatted as suggested
Custom ruleset
N/A — reproducible with PSR12
To reproduce
Steps to reproduce the behavior:
test.php
with the code sample abovephpcs -s --standard=psr12 test.php
Expected behavior
No indentation errors.
Versions (please complete the following information)
Additional context
none
Please confirm:
master
branch of PHP_CodeSniffer.The text was updated successfully, but these errors were encountered: