-
-
Notifications
You must be signed in to change notification settings - Fork 63
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.WhiteSpace.ScopeIndent false positive with nested match
-es
#110
Comments
The issues is still present in v3.9.0. |
@andrey-yantsen You are welcome to submit a patch... |
@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 |
Pff.. this was complex one. PR #502 should fix it though. Testing appreciated. |
Thank you, @jrfnl! I just checked the master branch — the issue is gone for all the examples I had at hand. |
Thanks @andrey-yantsen for testing and confirming! |
@andrey-yantsen @jrfnl Can we re-open this? I can confirm that this ticket solved a lot of issues but I found another scenario where this isn't fixed yet. In case where a method has attributes, formatted like this, the false positive would still occur. Note that this only occurs when a method has attributes and only when exactly formatted like this. Attributes on the class have no effect. <?php
class Foo
{
#[
AttributeA(),
AttributeB()
]
public function foo(): int
{
$bar = 'bar';
$result = match ($bar) {
'foo' => true,
'bar' => 300,
'baz' => 'hello world',
default => null
};
if ($result === null) {
return 404;
}
return 200;
}
} Output --- test.php
+++ PHP_CodeSniffer
@@ -17,10 +17,10 @@
default => null
};
- if ($result === null) {
- return 404;
- }
+ if ($result === null) {
+ return 404;
+ }
- return 200;
+ return 200;
}
} When formatted like this either with one or multiple attributes, everything is ok and the output is empty. <?php
class Foo
{
#[AttributeA()]
#[AttributeB()]
public function foo(): int
{
$bar = 'bar';
$result = match ($bar) {
'foo' => true,
'bar' => 300,
'baz' => 'hello world',
default => null
};
if ($result === null) {
return 404;
}
return 200;
}
} |
@mdeboer Please open a new issue. |
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: