Make WordPress Core

Opened 6 months ago

Last modified 3 days ago

#65278 new defect (bug)

PHPCS scans can fail after running `build:dev`

Reported by: desrosj Owned by:
Priority: normal Milestone: 7.3
Component: Build/Test Tools Version: 7.0
Severity: normal Keywords: has-patch needs-testing
Cc: Focuses:

Description

It seems that there are some cases where the PHPCS ruleset upstream within the gutenberg repository either differs or is not enforced the same way when compared to wordpress-develop.

@jorbin and I spotted this when running grunt prerelease locally after running build:dev in the 7.0 branch. The src/wp-includes/css/dist/registry.php file is not aligning array assignment operators (=>).

Change History (26)

#1 follow-up: @desrosj
6 months ago

A few thoughts on this:

  • This file is probably not being built into the best location. The folder name (css/dist) implies that it only contains built CSS files. But this registry.php file is an outlier.
  • I believe that this file is creating during the build script upstream, so it would either need to be formatted after being built, or the script/tool building it should be updated to align => operators.
  • This file should probably be added to the ignore list in phpcs.xml.dist (and also phpcompat.xml.dist) since it's not subject to version control. But if that were the case already, this would have been suppressed and not flagged to be fixed. If this path is chosen, then a full list of files that meet this criteria should be created and they should all be treated the same.
  • This file (and any other PHP files copied over wholesale from the gutenberg repository) should ideally be considered for being added to version control for better tracking of changes over time through tools like git bisect/git blame.

This ticket was mentioned in ​Slack in #core by desrosj. ​View the logs.


6 months ago

#3 in reply to: ↑ 1 @desrosj
6 months ago

  • Keywords needs-patch added

Replying to desrosj:

A few thoughts on this:

  • This file is probably not being built into the best location. The folder name (css/dist) implies that it only contains built CSS files. But this registry.php file is an outlier.

#65279 has been opened to address this.

Last edited 6 months ago by desrosj (previous) (diff)

This ticket was mentioned in ​PR #11924 on ​WordPress/wordpress-develop by ​@khokansardar.


6 months ago
#4

  • Keywords has-patch added; needs-patch removed

After running ​build:dev, the auto-generated registry.php file in css/dist is not formatted to WordPress coding standards and causes grunt prerelease PHPCS checks to fail.

Props desrosj.
Fixes #65278.

​@wildworks commented on ​PR #11924:


4 months ago
#5

Thanks for the PR. If I understand correctly, the fundamental solution is to either output WPCS-compliant PHP upstream or run phpcbf, etc. after the build to enforce formatting. This PR seems like a temporary workaround. Let's close this PR and discuss the ideal approach.

#6 @wildworks
4 months ago

  • Keywords needs-patch added; has-patch removed
  • Milestone 7.1 → 7.2

Thanks for the PR. If I understand correctly, the fundamental solution is to either output WPCS-compliant PHP upstream or run phpcbf, etc. after the build to enforce formatting. This PR seems like a temporary workaround. Let's close this PR and discuss the ideal approach.

I think ​PR 11924 is not the ideal approach, so I have closed it. A new patch or an upstream fix is needed, but given the time constraints for the 7.1 release, I'd like to punt this.

This ticket was mentioned in ​PR #12778 on ​WordPress/wordpress-develop by ​@benitoalba.


4 months ago
#7

  • Keywords has-patch added; needs-patch removed

Formats the generated Gutenberg style registry while it is copied into Core.

Gutenberg currently outputs registry.php with unaligned array operators and missing spaces inside non-empty dependency arrays. Running build:dev followed by a Core PHPCS scan therefore reports coding standards violations. The copy step now normalizes those known fields without requiring PHP or Composer in build-only jobs.

## Testing

  • npm run build:dev
  • npm run grunt jshint:grunt
  • php -l src/wp-includes/css/dist/registry.php
  • php ./vendor/squizlabs/php_codesniffer/bin/phpcs --standard=phpcs.xml.dist src/wp-includes/css/dist/registry.php
  • php ./vendor/squizlabs/php_codesniffer/bin/phpcs --standard=phpcompat.xml.dist src/wp-includes/css/dist/registry.php
  • git diff --check

Before the change, PHPCS reported 34 errors and 38 warnings in the generated registry. After the change, both PHPCS rulesets pass.

## Use of AI Tools

AI assistance: Yes
Tool(s): OpenAI Codex
Model(s): GPT-5
Used for: Issue research, implementation, and local validation.

#8 @lancewillett
8 weeks ago

In 63883:

Build/Test Tools: Format the copied Gutenberg style registry.

Align array assignment operators and normalize dependency array spacing when copying the generated style registry into Core. This allows PHPCS scans after ​build:dev to pass without requiring PHP tooling in build-only jobs.

Developed in: ​https://github.com/WordPress/wordpress-develop/pull/12778

Props benitoalba, desrosj, jorbin, wildworks.
See #65278.

#10 @lancewillett
8 weeks ago

[63883] fixes the reported PHPCS failure by formatting the style registry during the copy step. I left this ticket open to follow up on comment:1.

My reading of the remaining points:

  • Location: #65279 already tracks PHP files being placed in CSS/JS directories.
  • Formatting: Addressed by [63883]. Fixing Gutenberg's generator would still be worthwhile and could eventually let us remove the Core formatter.
  • Scan exclusions: I suggest retaining PHPCS and PHPCompatibility coverage. The ignore-list proposal was conditional, and excluding the generated files would hide defects in PHP shipped with WordPress.
  • Version control: #64393 restored much of the imported PHP to version control. In the current build, 31 copied PHP files remain ignored: the style registry, the module registry, and 29 module asset manifests.

I suggest auditing those remaining files before deciding to track them all. I found no direct Core source reference to either registry. Most module manifests feed the tracked aggregate, but the boot manifest is also loaded directly. We should confirm build/release consumers before removing any copied output.

That gives #65279 a concrete follow-up: stop copying unnecessary PHP, then decide placement and version control for the required files. This ticket can track that decision until the follow-up scope is agreed.

We should also decide whether to apply [63883] to 7.0 and 7.1; neither branch currently has this formatter, and the original report was on 7.0.

@desrosj, would that address the remaining concerns from comment:1?

#11 @jorbin
7 weeks ago

fixes the reported PHPCS failure by formatting the style registry during the copy step

This feels like a hacky solution. I think it should be reverted and we should focus on getting the file correct before it is copied over.

#12 @lancewillett
7 weeks ago

In 63918:

Build/Test Tools: Revert the build file-type check.

Revert [63917] pending agreement on the placement of generated PHP files and the exceptions allowed by the check.

See #65279, #65278.

#13 @lancewillett
7 weeks ago

In 63919:

Build/Test Tools: Revert copied style registry formatting.

Revert [63883] so the generated style registry can be corrected upstream rather than reformatted during the copy into Core.

See #65278.

​@lancewillett commented on ​PR #12778:


7 weeks ago
#14

Reopening after the revert in https://core.trac.wordpress.org/changeset/63919.

Next step: settle the file-placement exceptions and upstream formatting approach before moving these forward.

Discussion: ​https://wordpress.slack.com/archives/C08D0Q6BHNY/p1790267518339219

#15 @wildworks
7 weeks ago

This feels like a hacky solution. I think it should be reverted and we should focus on getting the file correct before it is copied over.

I agree. Furthermore, regarding the files synced from Gutenberg, there are still many that do not comply with the core PHPCS rules.

I think the underlying issue is that ​PHPCS on the Gutenberg side excludes the build directory, allowing PHP files within it to bypass PHPCS checks and be synced to Core. Perhaps we should file a tracking issue on Gutenberg and fix the problematic files one by one.

This ticket was mentioned in ​Slack in #core by im3dabasia1. ​View the logs.


10 days ago

#17 @im3dabasia1
10 days ago

As per today’s 7.2 bug scrub:

The earlier workaround was reverted, so this still needs a fix. Is this in the plan for 7.2?

#18 @desrosj
9 days ago

  • Keywords needs-testing added
  • Milestone 7.2 → 7.3

While it would be great to address this in 7.2, I'm going to punt because it's not mission critical. If it's ready before 7.2's final release we can move it back.

​@lancewillett commented on ​PR #12778:


8 days ago
#19

@desrosj following up: this is waiting on your call on file placement and upstream formatting for the copied style registry. Once you decide, I can land or adjust it.

<sub>AI review · <code>claude-opus-5-5</code></sub>

#20 @dhrupo
8 days ago

Patch Testing Report

Patch tested: ​https://github.com/WordPress/wordpress-develop/pull/12778 (head 4265f7fb873deb577dd474ddc8951decb36352fb), applied on top of trunk b6091aa18de761053ae94d79c5005d2eae4833a5.

Environment

  • OS: macOS 26.6.2 (arm64)
  • Node.js: 24.18.1 (from .nvmrc), npm 11.16.0
  • PHP (CLI): 7.4.33
  • Composer: 2.10.3, PHP_CodeSniffer 3.13.5
  • Gutenberg build: c035c1a649ef68f5c1646694cf440df1d7ae6e62 (the gutenberg.sha pinned in package.json)
  • Fresh worktree, npm ci and composer install

Steps taken

  1. On trunk, ran npm run build:dev.
  2. Ran vendor/bin/phpcs --standard=phpcs.xml.dist src/wp-includes/css/dist/registry.php. Result: FOUND 34 ERRORS AND 40 WARNINGS AFFECTING 57 LINES, exit 2. All are WordPress.Arrays.MultipleStatementAlignment.DoubleArrowNotAligned and NormalizedArrays.Arrays.ArrayBraceSpacing.
  3. Ran a full scan with errors only, vendor/bin/phpcs -n. Result: A TOTAL OF 34 ERRORS AND 0 WARNINGS WERE FOUND IN 1 FILE. The only file is src/wp-includes/css/dist/registry.php.
  4. Ran the grunt prerelease step that fails, npx grunt format:php:error. Result: phpcbf fixed src/wp-includes/css/dist/registry.php (74), then Aborted due to warnings.
  5. Ran npm run build (production). The build passes, but PHPCS fails the same way: the 34 errors are in src/wp-includes/css/dist/registry.php, and the copy in build/ has the same 34 errors.
  6. Applied the PR and ran npm run build:dev again.
  7. Ran phpcs --standard=phpcs.xml.dist and --standard=phpcompat.xml.dist on registry.php: both exit 0. php -l reports no syntax errors.
  8. Full scan vendor/bin/phpcs -n: exit 0. Full scan with warnings: 0 errors and 271 warnings in 53 files. On trunk the result was 34 errors and 311 warnings in 54 files. The 40 fewer warnings are the 40 registry.php warnings.
  9. Checked the output against phpcbf. The file the PR writes is byte-identical to what phpcbf writes for the trunk file (sha1 ff11baed7cb3cc3f91ad6dae75df71fd7d794c1e for both). The 124 CSS files in css/dist are also identical to the trunk build. The array that include returns is the same on trunk and with the PR (20 entries, === is true).
  10. Ran the formatter again on its own output: nothing changes.
  11. Ran npm run build (production) with the PR: exit 0. src/ and build/ registry.php are identical and pass PHPCS.
  12. Ran npm run grunt jshint:grunt: 1 file lint free.

✅ The patch fixes the PHPCS errors from registry.php after build:dev and after build.

Expected result

After npm run build:dev or npm run build, PHPCS and PHPCompatibility report no errors for the generated src/wp-includes/css/dist/registry.php. The file content is unchanged except for whitespace.

Additional Notes

  • Binary files: the PR adds a process function to the gutenberg-styles copy target. Grunt then reads every file in that target as UTF-8 text, not only registry.php. Today the folder has only CSS files and registry.php, so the output is identical. As a test, I put a PNG into gutenberg/build/styles/ and ran copy:gutenberg-styles. With the PR, the copy changed from 3113 to 5543 bytes (corrupted). On trunk, the copy was identical. Adding noProcess: [ '**/*', '!**/registry.php' ] to the target options kept the PNG identical, and registry.php still passed PHPCS.
  • Fixed key list: the formatter pads only handle, path and dependencies, and it aligns them to the length of dependencies. If Gutenberg adds another key (for example version), that line stays unaligned and the alignment warnings come back. Single-line array(...) is the only form it fixes: short arrays ([]) and multi-line arrays pass through unchanged. Nothing fails at build time when the output shape changes.
  • Other copied Gutenberg PHP: in this build, registry.php is the only untracked generated PHP file that the ruleset scans. The other 44 untracked PHP files are under src/wp-includes/js/. The tracked Gutenberg PHP is under src/wp-includes/build/. phpcs.xml.dist excludes both folders. With those two exclusions removed, a scan reports 469 errors and 106 warnings in 56 files there. So the PR fixes the reported failure, but it does not fix the wider issue raised in comment:15.
  • Unrelated to this ticket: on current trunk, grunt format:php:error still fails with the PR. phpcbf also fixes alignment in two tracked files, src/wp-includes/class-wp-theme.php (1) and src/wp-includes/rest-api/endpoints/class-wp-rest-template-autosaves-controller.php (2). grunt prerelease only passes when those are fixed as well.
  • The upstream generator is packages/wp-build/lib/build.mjs in Gutenberg (the style entries are built with 'handle' => , 'path' => and 'dependencies' => array(...)). A fix there would remove the need for the Core formatter, as comment:11 and comment:15 suggest. This report covers only the behaviour of the PR, not that decision.

​@dhrupo commented on ​PR #12778:


8 days ago
#21

Tested this on trunk b6091aa18d with the PR head 4265f7fb87 applied (macOS arm64, Node 24.18.1, PHP 7.4.33, PHPCS 3.13.5, Gutenberg c035c1a649).

Before: after npm run build:dev, vendor/bin/phpcs -n reports 34 ERRORS ... IN 1 FILE, and the file is src/wp-includes/css/dist/registry.php. grunt format:php:error aborts on the same file. npm run build produces the same 34 errors.

After: phpcs and phpcompat both exit 0 on registry.php, and the full phpcs -n scan is clean. The output is byte-identical to what phpcbf writes for the trunk file. Running the formatter on its own output changes nothing. The other 124 files in css/dist are unchanged. npm run build also works.

One problem: adding process to the gutenberg-styles target makes grunt read every file in it as UTF-8 text. Today there are only CSS files and registry.php, so nothing breaks. As a test, I put a PNG into gutenberg/build/styles/: with this PR it was copied as 5543 bytes instead of 3113 (corrupted). On trunk the copy was identical. Adding noProcess: [ '**/*', '!**/registry.php' ] to the options fixed that, and registry.php was still formatted.

A smaller point: the key list and the padding are hard-coded. A new key from the generator, or a []/multi-line dependency array, would pass through with no error. The alignment warnings would then come back.

Full report is on the Trac ticket.

​@lancewillett commented on ​PR #12778:


8 days ago
#22

@benitoalba @dhrupo found one change worth making before this lands.

Setting process on the gutenberg-styles target makes grunt read and write every file in it as UTF-8 text, not just registry.php (node_modules/grunt/lib/grunt/file.js, lines 314–320). Today that's harmless: gutenberg/build/styles holds 768 CSS files and the one PHP file. But a binary file added upstream would be copied corrupted, with no error.

Please scope the processing to the registry:

options: {
        noProcess: [ '**/*', '!**/registry.php' ],
        process: function( content, srcpath ) {

With that, the path.basename() check inside process becomes redundant and can go.

The hard-coded key list is lower risk. A new key would pass through unformatted rather than break the build, so it's fine to leave.

My approval stands with that change. This still waits on @desrosj's file-placement call.

<sub>AI review · <code>claude-opus-5-5</code></sub>

​@benitoalba commented on ​PR #12778:


8 days ago
#23

Thanks @lancewillett and @dhrupo! Added noProcess and removed the filename check in 62922a2462. Verified that binary files copy unchanged and the registry formatting stays the same.

​@benitoalba commented on ​PR #12778:


5 days ago
#24

Following comment:11 and comment:15 on Trac, I'd like to fix this upstream in Gutenberg instead: the style, script, and module registry generators in packages/wp-build/lib/build.mjs would align => and add spaces inside non-empty arrays, the same way the route and widget registries already do. That would make the copied registry.php pass Core's PHPCS without a formatter in Core, and this PR could then be closed. @desrosj, does that match what you had in mind in comment:1? I'll link the Gutenberg PR here once it's up.

​@desrosj commented on ​PR #12778:


3 days ago
#25

​@desrosj, does that match what you had in mind in comment:1? I'll link the Gutenberg PR here once it's up.

Yes, that is my preference as well. Core = Gutenberg, Gutenberg = Core, so it makes sense that both repositories are enforcing the same rules in the same ways. Once parity is achieved there, there won't be any PHPCS issues after copying.

​@benitoalba commented on ​PR #12778:


3 days ago
#26

Thanks @desrosj! The Gutenberg PR is up: ​https://github.com/WordPress/gutenberg/pull/86766

It formats the generated style, script and script module registries in @wordpress/wp-build so they follow the WordPress Coding Standards. After npm run build, all three pass phpcs --standard=WordPress-Core with no errors or warnings. Once it's merged and the next Gutenberg version reaches Core, this PR won't be needed, so I'll close it then.

Note: See TracTickets for help on using tickets.