Skip to content
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

Core: Add upstream Generic.Arrays.DisallowShortArraySyntax sniff #1770

Merged
merged 1 commit into from Jul 21, 2019

Conversation

jrfnl
Copy link
Member

@jrfnl jrfnl commented Jul 20, 2019

Recently a new section has been added to the handbook which forbids the use of short arrays.

Using long array syntax ( array( 1, 2, 3 ) ) for declaring arrays is generally more readable than short array syntax ( [ 1, 2, 3 ] ), particularly for those with vision difficulties. Additionally, it’s much more descriptive for beginners.

Arrays must be declared using long array syntax.

https://make.wordpress.org/core/handbook/best-practices/coding-standards/php/#declaring-arrays

This PR add an existing upstream sniff which addresses this.
Includes auto-fixer.

Also see: https://make.wordpress.org/core/2019/07/12/php-coding-standards-changes/

Loosely related to #764

Recently a new section has been added to the handbook which forbids the use of short arrays.

> Using long array syntax ( array( 1, 2, 3 ) ) for declaring arrays is generally more readable than short array syntax ( [ 1, 2, 3 ] ), particularly for those with vision difficulties. Additionally, it’s much more descriptive for beginners.
>
> Arrays must be declared using long array syntax.

https://make.wordpress.org/core/handbook/best-practices/coding-standards/php/#declaring-arrays

This PR add an existing upstream sniff which addresses this.
Includes auto-fixer.

Also see: https://make.wordpress.org/core/2019/07/12/php-coding-standards-changes/

Loosely related to 764
@dingo-d dingo-d merged commit 80e82a2 into develop Jul 21, 2019
@dingo-d dingo-d deleted the feature/add-disallow-short-arrays-to-core branch July 21, 2019 07:58
@GaryJones
Copy link
Member

I presume to override this, folks can do something like:

<rule ref="Generic.Arrays.DisallowShortArraySyntax">
	<severity>0</severity>
</rule>

...with an optional:

<rule ref="Generic.Arrays.DisallowLongArraySyntax"/>

@jrfnl
Copy link
Member Author

jrfnl commented Jul 21, 2019

@GaryJones Correct. Alternatively for the first code snippet, you can use:

<rule ref="WordPresss">
    <exclude name="Generic.Arrays.DisallowShortArraySyntax"/>
</rule>

(within WPCS we use severity to make it clear to people how to re-enable an excluded rule, in a "end-user" custom ruleset you normally would use the above exclude).

@GaryJones
Copy link
Member

Since https://make.wordpress.org/core/2019/07/12/php-coding-standards-changes/ explicitly says these changes are only intended for WP core itself:

While reading these changes, it’s important to keep in mind that they only apply to WordPress Core:

I'm wondering whether the addition could have been made to https://core.trac.wordpress.org/browser/trunk/phpcs.xml.dist instead of to the standards that all of the community would be using.

@jrfnl
Copy link
Member Author

jrfnl commented Nov 6, 2019

@GaryJones I hear you, but I believe that discussion has been had numerous times already and the conclusion was always that the rulesets in WPCS follow the Core rules.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants