DEV Community

Cover image for WPCS: Use short array syntax
Dave Kellam for Plank

Posted on

WPCS: Use short array syntax

At Plank, we use the WordPress Coding Standards in our development process. It helps ensure that everyone is writing code in a similar style, and that we follow best practices (like escaping and sanitizing data).

That said, we don't necessarily agree with all of the rules. In particular, we prefer using the short array syntax for php arrays. We find it easier to find when an array closes, rather than searching through a sea of closing parentheses ();););).

If you're using your own custom ruleset to extend the default standards, you do something like this to allow the short array syntax. If you really don't like the long array syntax, you can disallow it, and phpcbf should convert to short arrays with the second pattern.

<!-- Allow short syntax arrays. -->
<rule ref="Generic.Arrays.DisallowLongArraySyntax"/>

<!-- Disallow long array syntax -->
<rule ref="Generic.Arrays.DisallowShortArraySyntax.Found">
    <exclude-pattern>*</exclude-pattern>
</rule>
Enter fullscreen mode Exit fullscreen mode

Top comments (1)

Collapse
 
meganmcewan profile image
Megan McEwan

Short array syntax ftw!