Repository navigation
wp-build: Format generated registries to WordPress Coding Standards - #86766
benitoalba wants to merge 3 commits into
Conversation
🤖 PR meta 🤖👋 Welcome👋 Thanks for your first Pull Request and for helping build the future of Gutenberg and WordPress, @benitoalba! In case you missed it, we'd love to have you join us in our Slack community. If you want to learn more about WordPress development in general, check out the Core Handbook full of helpful information. 🎉 PropsIf you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. Props Bot commandsYou can trigger Props Bot actions by commenting on this PR:
Updated as activity occurs, without notifying anyone named here. Add the |
0513dc1 to
8f47a04
Compare
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues block the update to generate WordPress Coding Standards–compliant PHP registries.
No open issues 🎉
What changed in this PR
Updates @wordpress/wp-build to generate PHP registries that follow WordPress Coding Standards, allowing WordPress Core to copy them without additional formatting.
Changes:
- Adds shared helpers for aligned associative arrays and correctly spaced list literals.
- Applies the helpers to style, script, and script module registries while preserving their data and order.
- Adds formatting tests and a changelog entry.
| File | Description |
|---|---|
packages/wp-build/lib/test/php-generator.js |
Tests array spacing, key alignment, and omission of undefined fields. |
packages/wp-build/lib/php-generator.mjs |
Adds PHP array-formatting helpers. |
packages/wp-build/lib/build.mjs |
Uses the helpers in the three registry generators. |
packages/wp-build/CHANGELOG.md |
Documents the generated registry formatting fix. |
Review effort: Balanced
|
I compared the three generators against the real registry inventory from this head’s Core-targeted build: 20 style rows, 65 script rows, and 42 module rows. Base and head have identical PHP tokens after removing whitespace and return strictly equal arrays. The regenerated head files match the CI artifact byte for byte. PHPCS drops from 34 errors and 256 warnings to zero; PHP syntax checks pass. Focused unit tests pass on both base (2) and head (6). This was a focused regeneration and unit-test comparison, not a full local Gutenberg build. I also checked the formatter proposed in WordPress/wordpress-develop#12778: it produces the same style-registry bytes and makes no change to the upstream-formatted result. Once Core consumes this upstream fix, that workaround should be unnecessary. @desrosj, could you review this upstream approach following your recommendation on the Core PR? I found no formatter blocker. The iOS Safari retry and Copilot review are still pending. AI review · |
lancewillett
left a comment
There was a problem hiding this comment.
Compared all 127 generated asset entries with the previous formatter. The PHP arrays are strictly equal, and the generated files pass PHPCS. The Safari retry also passed all five tests.
The remaining merge conflict is confined to packages/wp-build/CHANGELOG.md. Please keep both new trunk entries and the registry-formatting entry when you refresh the branch.
AI review · gpt-6
Align the `=>` operators and add spaces inside non-empty `array()` literals in the generated style, script and script module registries, via shared helpers in php-generator.mjs. WordPress Core copies these files, so they now pass Core PHPCS without a Core-side formatter. See https://core.trac.wordpress.org/ticket/65278.
8f47a04 to
3b92b98
Compare
|
Thanks Lance! Rebased onto trunk. Since 0.28.0 went out yesterday with the two new trunk entries, I moved the registry-formatting one up to Unreleased instead of squeezing it into the released section. Both trunk entries are untouched. |
|
@benitoalba, I checked the merge against current trunk. Only AI review · |
Resolve the conflict in packages/wp-build/CHANGELOG.md by keeping trunk's Unreleased section and listing the WordPress#86766 entry under its Bug Fixes heading, next to WordPress#87189. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EisotksEYkwb8knGHGSXxP
|
Thanks @lancewillett! I merged current trunk into the branch and resolved the |
What?
See https://core.trac.wordpress.org/ticket/65278 and WordPress/wordpress-develop#12778.
Makes the style, script and script module registries generated by
@wordpress/wp-build(build/styles/registry.php,build/scripts/registry.php,build/modules/registry.php) follow the WordPress Coding Standards.Why?
WordPress Core copies Gutenberg's generated registries into
src/wp-includes/build/. The current output has unaligned=>operators and no spaces inside non-emptyarray()literals, so a Core PHPCS scan afternpm run build:devreports errors and warnings on the copied files.wordpress-develop#12778 first fixed this with a formatter in Core's Grunt copy step. That was reverted, since reviewers preferred to fix it at the source. As @desrosj put it on the PR, Core and Gutenberg should enforce the same rules in the same way, so the files need no changes when copied.
How?
lib/php-generator.mjs:toPhpListLiteral( values )returnsarray( 'a', 'b' ), orarray()for an empty list.toPhpAssociativeArrayLiteral( fields, indent )returns a multi-linearray()with=>aligned to the longest key and leaves out fields whose value isundefined(used for the optionalmin_only).generateStyleRegistrationPhp,generateScriptRegistrationPhpandgenerateModuleRegistrationPhpnow use these helpers instead of hand-built strings.Testing Instructions
npm run buildvendor/bin/phpcs --standard=WordPress-Core build/styles/registry.php build/scripts/registry.php build/modules/registry.phpnpm run test:unit:vitest -- packages/wp-build/lib/test/php-generator.jsExample output:
Use of AI Tools
AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Opus 5.5
Used for: Implementation, tests and local validation. I reviewed the changes and the generated output.