Update WordPress Coding Standards to 3.4.1 - #759
Closed
obenland wants to merge 1 commit into
Closed
Conversation
WPCS was pinned to `2.*`, resolving to 2.3.0 (released March 2020). On PHP 8.1+
it emits an implicit-nullable deprecation from `PHPCSHelper::ignore_annotations()`,
which PHPCS turns into "checking has been aborted" — files hitting that code path
were silently skipped rather than linted.
Bump `wp-coding-standards/wpcs` to `^3.4` and, as 3.x requires,
`dealerdirect/phpcodesniffer-composer-installer` to `^1.0`. This pulls in
phpcsutils and phpcsextra as transitive dependencies.
Reconcile `phpcs.xml.dist` with the 3.x ruleset:
* Two excluded sniffs moved to PHPCSExtra and were silently no longer matching,
so the rules they were meant to suppress had come back:
`Generic.Arrays.DisallowShortArraySyntax` is now
`Universal.Arrays.DisallowShortArraySyntax` (119 hits) and
`WordPress.PHP.DisallowShortTernary` is now
`Universal.Operators.DisallowShortTernary` (13 hits).
* `customPropertiesWhitelist` was renamed to `allowed_custom_properties` in
WPCS 3.0; the old name is now a hard error.
* `text_domain` was passing an array as a comma-separated string, deprecated
since PHPCS 3.3.0. Use `<element>` nodes.
* `PEAR.Files.IncludingFile.BracketsNotRequired` cannot be excluded from the
`WordPress-Core` block, because the later `WordPress-Extra` rule re-includes
`WordPress-Core` and reinstates it. Silence it after that rule instead.
* Exclude `PSR12.Files.FileHeader`, new in WPCS 3.0. It fixes the order of the
docblock, namespace and `use` groups and forbids interleaving them, which
conflicts with the import grouping used throughout this codebase — the same
preference already recorded for
`PSR2.Namespaces.NamespaceDeclaration.BlankLineAfter`.
The remaining 84 violations came from sniffs new in 3.x and were fixed with
phpcbf: space after `function` in closures, no space before the return type
colon, `dirname( __FILE__ )` to `__DIR__`, and one `else { if }` to `elseif`.
All are formatting-only except the `dirname()` calls, which are exactly
equivalent. phpcbf mis-indented the `elseif` in `bin/check-spam.php`; corrected
by hand.
`phpcs` now exits 0.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Member
Author
|
Closing as a duplicate — #756 already landed the WPCS 3.4.1 upgrade on trunk, which I'd missed before starting this branch. The branches reformat the same files in incompatible directions, so there's nothing here worth rebasing. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Why
wp-coding-standards/wpcswas pinned to2.*, resolving to 2.3.0 — released March 2020 and the last of the 2.x line. PHPCS itself was already current (3.13.2); only the WordPress standard was stale.On PHP 8.1+ WPCS 2.3.0 emits an implicit-nullable deprecation from
PHPCSHelper::ignore_annotations(), which PHPCS converts intoAn error occurred during processing; checking has been aborted. Any file hitting that code path was silently skipped instead of linted — so the local lint was quietly under-reporting. On this branch, running theWordPress.Security.*sniffs over the same four directories goes from 27 findings (withthemes/…-2024/functions.phpnever actually scanned) to 34.What changed
Dependencies
wp-coding-standards/wpcsdealerdirect/phpcodesniffer-composer-installersquizlabs/php_codesnifferphpcsstandards/phpcsutilsphpcsstandards/phpcsextraphpcs.xml.distreconciliationThe upgrade is not drop-in — several existing directives had gone stale, two of them silently:
Generic.Arrays.DisallowShortArraySyntax→Universal.Arrays.DisallowShortArraySyntax(moved to PHPCSExtra). The old exclude no longer matched, so short array syntax was flagged 119 times.WordPress.PHP.DisallowShortTernary→Universal.Operators.DisallowShortTernary. Same story, 13 hits.customPropertiesWhitelist→allowed_custom_properties(renamed in WPCS 3.0). This one is a hard error, not silent.text_domainwas passing an array as a comma-separated string — deprecated since PHPCS 3.3.0, removed in 4.0. Now uses<element>nodes.PEAR.Files.IncludingFile.BracketsNotRequiredcannot be excluded from inside theWordPress-Coreblock: the laterWordPress-Extrarule re-includesWordPress-Corewholesale and reinstates it. Moved to a<severity>0</severity>rule positioned afterWordPress-Extra.PSR12.Files.FileHeadernewly excluded — see the judgement call below.Code (auto-fixed with
phpcbf)The remaining 84 violations all came from sniffs new in 3.x, and are formatting-only except where noted:
Squiz.Functions.MultiLineFunctionDeclaration.SpaceAfterFunction(39) —function(→function (in closuresPSR12.Functions.ReturnTypeDeclaration.SpaceBeforeColon(34) —) : array→): arrayModernize.FunctionCalls.Dirname.FileConstant(4) —dirname( __FILE__ )→__DIR__; exactly equivalent, verified each call siteUniversal.ControlStructures.DisallowLonelyIf(1) —else { if }→elseifinbin/check-spam.phpphpcbf mis-indented the
elseifit produced inbin/check-spam.phpand left a stray blank line; corrected by hand.Judgement call worth a second opinion
PSR12.Files.FileHeaderis new in WPCS 3.0 and accounted for the last 9 violations. It imposes a fixed order on the file header — docblock,declare,namespace, classuse, functionuse, constuse— and forbids interleaving them.This codebase consistently groups imports by what they import rather than by kind, e.g.
functions.php:It also reads
/** Actions and filters. */above a block ofadd_action()calls as a misplaced file docblock, which it isn't.Satisfying the sniff means reordering imports across 9 files and fighting a preference the ruleset already records —
PSR2.Namespaces.NamespaceDeclaration.BlankLineAfteris excluded with the comment "I think it's better to have all theusestatements come right after the namespace line", which PSR-12 also forbids. Excluding seemed the coherent choice, but happy to reformat the 9 files instead if you'd rather adopt the rule.Testing
npm run lint:phpexits 0 on PHP 8.5.php -lclean across all 31 modified files.npm run test:phpcouldn't execute. CI will cover it. The code changes are whitespace plus the two equivalence-preserving rewrites noted above.Follow-up, not fixed here
phpcs.xml.distnests a<rule ref="WordPress.Arrays.MultipleStatementAlignment">inside the<rule ref="WordPress-Core">block, carrying an@todo This isn't workingcomment. It still doesn't work — PHPCS doesn't process a nested<rule>as an include, so thosealignMultilineItems/ignoreNewlinesproperties have never applied. Moving it to the top level fixes that, but it's a pre-existing issue unrelated to this upgrade and changes alignment enforcement, so I left it alone. Worth its own PR.🤖 Generated with Claude Code