Skip to content

Align the prep-diff tool with the exporter's normalization rules - #279

Open
sirreal wants to merge 2 commits into
fix-254from
prep-diff-updates
Open

Align the prep-diff tool with the exporter's normalization rules#279
sirreal wants to merge 2 commits into
fix-254from
prep-diff-updates

Conversation

@sirreal

Copy link
Copy Markdown
Member

Stacked on #262 (base branch: fix-254). Extracts the diff-tool work from that PR so it can be reviewed separately from the export-semantics changes.

Two commits:

  • Normalize global names in the diff tool — the prep-diff changes originally bundled into Preserve documentation and hook string semantics #262's "Preserve expression output" commit: normalization rules for the fields whose output Preserve documentation and hook string semantics #262 changes, so before/after exports can be compared without the intended changes showing as noise.
  • Run the diff normalization tests and match the exporter's rules — relocates tests/prep-diff-test.php to tests/phpunit/tests/prep-diff.php as a PHPUnit class so composer test and CI actually execute it (previously no runner invoked it), and replaces the tool's hand-rolled prose-style regex with the exporter's own \WP_Parser\strip_global_namespace_prefix(). The old regex matched inside string literals, so it normalized 'see \Foo bar' to 'see Foo bar' on both sides of a diff — masking exactly the string-corruption class Preserve documentation and hook string semantics #262 fixes. With the shared helper, a regression re-introducing that corruption shows up in the diff instead of vanishing.

Suite on this branch: 173 tests green (the 9 prep-diff tests on top of #262's 164). prep-diff.php still runs standalone (php prep-diff.php < export.json).

🤖 Generated with Claude Code

Extracted from the original "Preserve expression output" commit so the
diff tool's changes can land separately from the exporter's.
The diff normalization must follow the same rules the exporter uses when
it strips PHP-Parser's synthetic global namespace prefixes, otherwise the
normalized output no longer matches what the exporter produces.
`tests/prep-diff-test.php` was a standalone script that nothing executed:
`phpunit.xml.dist` only loads `tests/phpunit/tests/`, and both `composer test`
and CI run PHPUnit with that configuration. Move it under `tests/phpunit/tests/`
as a test case so that it runs with the rest of the suite.
`prep-diff.php` normalized printed expressions with its own prose-oriented
regular expression, which also matched global names appearing inside string
literals. An argument default of `'see \Foo bar'` was rewritten to
`'see Foo bar'`, which is exactly the mangled output the script is meant to
expose, so a regression in expression printing diffed clean. Reuse the
exporter's `WP_Parser\strip_global_namespace_prefix()` instead, which only
strips a prefix at the start of a value.
Inline documentation references are unaffected: they never contain whitespace,
so both rules produce the same result for them. Diffs of output generated
before and after this branch now show the string-literal fix instead of hiding
it, which is intended.
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

@sirreal