-
Notifications
You must be signed in to change notification settings - Fork 23
Closed
Description
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
- @widoz suggested it.
Code of Conduct
- I agree to follow this project's Code of Conduct
widoz, o-samaras and Chrico