Closed michalbundyra closed 8 months ago
Confirmed. Thanks for reporting this @michalbundyra .
The Squiz.Arrays.ArrayDeclaration
sniff is known to be problematic and has been for years.
The problem is largely that as soon as something is excluded from that sniff, the sniff is broken. This is a design flaw in the sniff.
I've been building up a (highly configurable) NormalizedArrays
standard in PHPCSExtra to replace it, but that's not complete yet. Would be lovely if I could find some time to finish that at some point.
With that in mind, I will not be working on this issue. If someone would submit a PR with a small/simple fix for this issue, I will accept it, but other than that, this sniff is out of bounds for large fixes/rewrites as it is just not worth the time.
In the mean time, rewriting the code to the below will prevent running into this particular problem with the sniff:
class HelloWorld
public static function dataProvider(): \Generator
{
yield 'test case' => [
[1.1, 2.5, 3.14],
static fn (float $item): float => match ($item) {
1.1, 2.5 => 1.1,
default => $item
},
[1.1, 3.14]
];
}
}
@jrfnl thanks for checking this out. I should have mentioned that this is the issue we actually have in doctrine/coding-standard
rules:
https://github.com/doctrine/coding-standard/blob/3e88327e4bb74e5538787642a59a45919376e0a9/lib/Doctrine/ruleset.xml#L517-L531
I'll see if I can provide a quick fix. Thanks
@michalbundyra I realize it may be a difficult case to advocate in the context of Doctrine, but if you want a solution in the mean time (aside from the fix you are preparing), you could consider using the NormalizedArrays
sniffs in combination with one or two of the WordPressCS
array sniffs (which are also customizable).
@jrfnl it turns out to be a quick fix: https://github.com/PHPCSStandards/PHP_CodeSniffer/pull/369
Thanks
Describe the bug
A clear and concise description of what the bug is.
Code sample
Custom ruleset
To reproduce
Steps to reproduce the behavior:
test.php
with the code sample above...phpcs test.php ...
Expected behavior
When I run:
the code is fixed as below:
so it looks like it's breaking the closure in the wrong place, and because of that it causes issue with:
rules.
Versions (please complete the following information)
Additional context
Add any other context about the problem here.
Please confirm:
master
branch of PHP_CodeSniffer.