PHPCSStandards / PHP_CodeSniffer

PHP_CodeSniffer tokenizes PHP files and detects violations of a defined set of coding standards.
BSD 3-Clause "New" or "Revised" License
856 stars 53 forks source link

Expanded Squiz.Arrays.ArrayDeclaration.SpaceBeforeComma support #477

Closed earthiverse closed 3 months ago

earthiverse commented 3 months ago

Is your feature request related to a problem?

Right now, the following code is correctly sniffed with Squiz.Arrays.ArrayDeclaration.SpaceBeforeComma

$arr1 = [
    'a' => 1,
    'b' => 2
    , // Correctly errors with Squiz.Arrays.ArrayDeclaration.SpaceBeforeComma
    'c' => 3,
];

However, if you have different "length" keys (in this example, aa is two characters), it no longer warns

$arr1 = [
    'a' => 1,
    'b' => 2
    , // No error
    'aa' => 3,
];

Describe the solution you'd like

I would like the ability to enable this sniff even if keys are of different "lengths"

Additional context (optional)

jrfnl commented 3 months ago

@earthiverse The issue you have identified is due to a long-time known design-flaw (one error hiding behind another) in the sniff and will not be fixed. Instead, new, more configurable sniffs will be made available to eventually replace the Squiz.Arrays.ArrayDeclaration sniff.

In the mean time, I'd like to suggest the Universal.WhiteSpace.CommaSpacing sniff as a way to still check the spacing around the comma, even when you have the Squiz.Arrays.ArrayDeclaration.DoubleArrowNotAligned eror silenced.

earthiverse commented 3 months ago

Universal.WhiteSpace.CommaSpacing works, thanks!