Skip to content

[Feature Request]: Enforce no spaces in array brackets #91

@antonioeatgoat

Description

@antonioeatgoat

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

  • I agree to follow this project's Code of Conduct

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions