Improve WordPress coding standards compliance #99
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Improve the WordPress (WP) coding standards formatter (
--wp
flag) to achieve closer compliance with the official WordPress PHP Coding Standards. While full parity isn’t possible with existing formatters, this configuration achieves close to full coverage.Changes
Expanded the
WP
class infmt.stub.php
with rules for additional formatting passes.Disabled PSR-2 Rules
PSR2IndentWithSpace
: WP uses real tabs, not spaces for indentation.PSR2CurlyOpenNextLine
: WP uses same-line braces.Added WordPress Rules
LongArray
/ disableShortArray
: WP prescribes longarray()
syntax instead of short[]
due to readability and beginner friendliness.MergeElseIf
/ disableSplitElseIf
: Due to colon syntax compatibility,elseif
is preferred.ExtraCommaInArray
/ disableStripExtraCommaInArray
: Trailing commas are recommended for easier reordering and cleaner diffs.YodaComparisons
: Left-side constant placement is advised for==
,!=
,===
and!==
conditions(5 === $value)
, but not for<
,>
,<=
,>=
. While not 100% compliant, enforcing yoda conditions expresses WP intent better.SpaceAroundControlStructures
,SpaceAfterExclamationMark
,SpaceAroundParentheses
: WP uses spaces in control structures and around operators:if ( ! $condition )
,array( 1, 2, 3 )
,foo() && bar()
.AutoPreincrement
: WP favors pre-increment (++$a
) and pre-decrement (--$a
) forms to post-increment/decrement ($a++
/$a--
) due to performance and bug prevention.AddMissingParentheses
: Parentheses must be used for instantiationnew Foo()
.AlignEquals
: WP uses spaces to align consecutive lines of code for readability.AlignGroupDoubleArrow
/ disableAlignDoubleArrow
: Alignment is determined contextually within code blocks.EncapsulateNamespaces
: Curly brace syntax not allowed for namespace declarations.StripSpaceWithinControlStructures
: WP encourages brace style without empty lines.Removed Rules
StripNewlineWithinClassBody
: Not required by WP coding standards.Motivation
The original WordPress standards implementation (#33) provided only partial support and used some inconsistent PSR-2 defaults. This update expands the rule set for near-complete compliance with the WordPress PHP Coding Standards, making the formatter more reliable for WordPress plugin and theme developers.
References