Skip to content

wp-build: Format generated registries to WordPress Coding Standards - #86766

Open
benitoalba wants to merge 3 commits into
WordPress:trunkfrom
benitoalba:fix/wp-build-registry-php-coding-standards
Open

benitoalba wants to merge 3 commits into
WordPress:trunkfrom
benitoalba:fix/wp-build-registry-php-coding-standards

Conversation

@benitoalba

Copy link
Copy Markdown

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-empty array() literals, so a Core PHPCS scan after npm run build:dev reports 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?

  • Adds two helpers to lib/php-generator.mjs:
    • toPhpListLiteral( values ) returns array( 'a', 'b' ), or array() for an empty list.
    • toPhpAssociativeArrayLiteral( fields, indent ) returns a multi-line array() with => aligned to the longest key and leaves out fields whose value is undefined (used for the optional min_only).
  • generateStyleRegistrationPhp, generateScriptRegistrationPhp and generateModuleRegistrationPhp now use these helpers instead of hand-built strings.
  • The route and widget registries are already aligned by hand, so they are unchanged.
  • The registries contain the same keys, values and order as before. Only whitespace changes.

Testing Instructions

  1. npm run build
  2. Check the generated registries against Core's ruleset:
    vendor/bin/phpcs --standard=WordPress-Core build/styles/registry.php build/scripts/registry.php build/modules/registry.php
  3. Expect no errors or warnings. On trunk, the same command reports alignment and array-spacing violations.
  4. npm run test:unit:vitest -- packages/wp-build/lib/test/php-generator.js

Example output:

	array(
		'handle'       => 'wp-block-editor',
		'path'         => 'block-editor/style',
		'dependencies' => array( 'wp-commands', 'wp-components', 'wp-notices', 'wp-preferences' ),
	),

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.

@github-actions github-actions Bot added the [Package] wp-build /packages/wp-build label Nov 12, 2026
@github-actions

github-actions Bot commented Nov 12, 2026 •

Copy link
Copy Markdown

🤖 PR meta 🤖

Preview in WordPress Playground Preview in Storybook

👋 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.

🎉 Props

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: benitoalba <benitoalba@git.wordpress.org>
Co-authored-by: lancewillett <lancewillett@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.


Props Bot commands

You can trigger Props Bot actions by commenting on this PR:

  • @propsbot add <username> to give props to a GitHub user. Requires write access.
  • @propsbot remove <username> to leave a user out of the props. Requires write access.
  • @propsbot refresh to refresh this list. Adding the props-bot label works too.

Updated as activity occurs, without notifying anyone named here. Add the props-bot label to refresh.

@github-actions github-actions Bot added the First-time Contributor Pull request opened by a first-time contributor to Gutenberg repository label Nov 12, 2026
@benitoalba
benitoalba force-pushed the fix/wp-build-registry-php-coding-standards branch from 0513dc1 to 8f47a04 Compare November 17, 2026 01:15
@lancewillett
lancewillett requested a balanced review from Copilot November 17, 2026 22:34
@lancewillett lancewillett added the [Type] Build Tooling Issues or PRs related to build tooling label Nov 17, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 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

@lancewillett

Copy link
Copy Markdown
Member

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 · gpt-6

@lancewillett
lancewillett requested a review from desrosj November 17, 2026 22:36

@lancewillett lancewillett left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.
@benitoalba
benitoalba force-pushed the fix/wp-build-registry-php-coding-standards branch from 8f47a04 to 3b92b98 Compare November 19, 2026 00:12
@benitoalba

Copy link
Copy Markdown
Author

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.

@lancewillett

Copy link
Copy Markdown
Member

@benitoalba, I checked the merge against current trunk. Only packages/wp-build/CHANGELOG.md conflicts. Could you refresh the branch and put the #86766 bullet alongside #87189 under the existing Unreleased → Bug Fixes heading? Git merged build.mjs cleanly. Once CI runs on the refreshed branch, we can recheck the generated registries for the Core follow-up.

AI review · gpt-6.2-astra

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
@benitoalba

Copy link
Copy Markdown
Author

Thanks @lancewillett! I merged current trunk into the branch and resolved the CHANGELOG.md conflict: the #86766 entry is now under Unreleased → Bug Fixes, next to #87189. build.mjs merged cleanly, so CI on the refreshed branch should be good for rechecking the generated registries for the Core follow-up.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

First-time Contributor Pull request opened by a first-time contributor to Gutenberg repository [Package] wp-build /packages/wp-build [Type] Build Tooling Issues or PRs related to build tooling

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants