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
@tfrommen you are correct about Slevomat. I was going to add it and then I realized the problem. I was trying Squiz.Arrays.ArrayBracketSpacing locally but I had some problem with it. If it works as expected, it is fine to add it for me.
Is your feature request related to a problem?
At the current moment, we don't have any specific rule for spaces around keys in array square brackets.
This means that all the following lines are accepted by our rules:
$array['key'];
$array[ 'key' ];
$array[$key];
$array[ $key ];
$array = [ 'test', 'test2']
$array = [ 'test', 'test2' ]
$array = ['test', 'test2']
Describe the desired solution
No space should be enforced. Specifically, we could use the rule SlevomatCodingStandard.Arrays.SingleLineArrayWhitespace, which allows to configure the number of accepted spaces.
Accepted cases would be:
$array['test'];
$array[123];
$array[$test];
$array[TEST];
$array['test' . $test];
$array = ['test', 'test2']
Describe the alternatives that you have considered
An alternative solution is using the rule WordPress.Arrays.ArrayKeySpacingRestrictions, from WordPress Coding Standard, it enforces no space around the key, except if the key is a variable, a constant or a concatenated string.
In this case, accepted cases would become:
$array['test'];
$array[123];
$array[ $test ];
$array[ TEST ];
$array[ 'test' . $test ];
Additional context
No response
Props
Code of Conduct
The text was updated successfully, but these errors were encountered: