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
This is a known issue and not easy to solve in PHPCS itself. Loosely related to #1984
There is an alternative for this sniff available in PHPCSExtra which does distinguish between short lists and short arrays correctly: Universal.Arrays.DisallowShortArraySyntax. I'd strongly suggest you switch to using that sniff instead.
As a side-note: the Universal rule collection also contains a Universal.Lists.DisallowShortListSyntax sniff which will correctly detect and fix short lists to long lists.
Could this issue get fixed in the way PHPCSExtra does?
The code needed to determine short array vs short list is not to be underestimated. It is in PHPCSUtils and is two classes by themselves just and only for that analysis and has a significant impact on performance (which is why PHPCSUtils has caching build around it as well), so no, this is not something which can be fixed in PHPCS itself "in the same way", at least not unless PHPCS adds a dependency on PHPCSUtils or the issues I raised related to this are fixed (see #1984).
I inherit this rule from WPCS, should I bring the issue up there too? (asking since you're contributing there too)
This has already been fixed in WPCS develop. As of WPCS 3.0.0, the Generic.Arrays.DisallowShortArraySyntax sniff will no longer be used and has been replaced with the Universal.Arrays.DisallowShortArraySyntax sniff.
Describe the bug
Generic.Arrays.DisallowShortArraySyntax.Found
creates a fatal when it's an array assignment, where it should replace with list, not arrayCode sample
Will be changed to:
which is invalid and a fatal error.
If short array is followed by assignment (=), it should be changed to:
Custom ruleset
To reproduce
use the above code sample with the custom ruleset and run
phpcbf --standard=custom-ruleset.xml code-sample.php
on itExpected behavior
Change it to:
Versions (please complete the following information):
The text was updated successfully, but these errors were encountered: