-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Squiz.Arrays.ArrayDeclaration.KeyNotAligned w/ short arrays inconsitent #649
Comments
I wanted to drop in and add more detail here. I recently had a few problems with the class A {
protected $validFields = [
'os',
'pid',
'user',
'process',
];
} The values are reported to need 30 spaces instead of 8. This seems odd, but perhaps I'm in the wrong here. Nested arrays are also wonky: protected $validMods = [
'os' => [
'=',
'!',
],
'pid' => [
'=',
'!',
],
'user' => [
'=',
'!',
],
'process' => [
'=',
'!',
'~=',
'~!',
],
]; and phpcbf really mangles this array. However it should be noted that I've disabled |
The Squiz sniff wants your arrays formatted in a very specific way. In this case of your first code example, it wants it like this: <?php
class A {
protected $validFields = [
'os',
'pid',
'user',
'process',
];
} Which is also the exact way it want's arrays that are defined using the regular syntax. There are no other sniffs that come with PHP_CodeSniffer that format arrays as no other coding standards actually have a strict standard for arrays. If you don't like the way this particular sniff formats arrays, you'll need to write your own checks. And yes, your second example would work fine if you enabled the while sniff. You get this code: <?php
protected $validMods = [
'os' => [
'=',
'!',
],
'pid' => [
'=',
'!',
],
'user' => [
'=',
'!',
],
'process' => [
'=',
'!',
'~=',
'~!',
],
]; |
Verified that phpcbf converted it to that, and that it was considered valid. Thanks Greg, this one wasn't so great on my part, I should have done more careful research. As always you are a fountain of patience and support. As you said, if I don't like this formatting I'll make my own sniff. |
No problem. I would like to create a more generic single-indent based sniff for arrays, or even change the Squiz standard in time, but a custom sniff will have to do in the meantime. |
…r-name Generic/ConstructorName: fix minor bug
The sniff error message
Squiz.Arrays.ArrayDeclaration.KeyNotAligned
does not seem to be working properly for short arrays[]
, it is inconsistent with the same formatting usingarray()
.It is possible that
Squiz.Arrays.ArrayDeclaration.CloseBraceNotAligned
also needs to be fixed, as end brace spacing is also suspect.The text was updated successfully, but these errors were encountered: