Skip to content

Fix two blink false positives surfaced on rector-src - #197

Merged
TomasVotruba merged 2 commits into
mainfrom
fix-blink-rector-false-positives
Oct 10, 2026
Merged

TomasVotruba merged 2 commits into
mainfrom
fix-blink-rector-false-positives

Conversation

@TomasVotruba

Copy link
Copy Markdown
Member

Running ecs check --blink on rector-src reported 840 fixable files; the PHP engine reports the codebase clean. Two independent bugs caused this.

1. Net-zero fixer runs reported with an empty diff (836 files)

UnaryOperatorSpacesFixer (full) strips the space after ! (! $a -> !$a) and NotOperatorWithSuccessorSpaceFixer adds it back. On files with ! $x, the two fight to a draw: the rendered output is identical to the original, but both rules returned changed=true, so the file was listed as fixable with an empty diff.

The runner now reports a change only when the final rendered content differs from the original, matching PHP-CS-Fixer (which reports real diffs only).

2. ClassDefinition mangled code after a keyword-named reference

The lexer tags a class name like Enum (in Enum::MODE_ADD) as the enum keyword. ClassDefinitionFixer treated it as a declaration and, with single_line: true, flattened every newline between it and the next { (a later method brace), collapsing a multi-line array and merging statements:

-            new ConstantStringType(Enum::MODE_ADD),
-            new ConstantStringType(Enum::MODE_EDIT),
-        ]);
+            new ConstantStringType(Enum::MODE_ADD), new ConstantStringType(Enum::MODE_EDIT), ]);

A genuine declaration is always followed by the type-name identifier, so a class-like keyword not followed by one (Enum::, Enum() is skipped.

Verification

Regression tests added for both (internal/runner, internal/fixer/rules). After the fix, ecs check --blink on rector-src reports no errors, matching the PHP engine.

When one rule edits the stream and another reverts it (e.g. UnaryOperatorSpaces strips the space after "!" and NotOperatorWithSuccessorSpace adds it back), the rendered file equals the original. Those files were reported as fixable with an empty diff. Report a change only when the final content differs from the original, matching PHP-CS-Fixer.
The lexer tags a class name like "Enum" (in "Enum::MODE_ADD") as the "enum" keyword. ClassDefinition treated it as a declaration and, with single_line, flattened everything up to the next brace, mangling unrelated code. A real declaration is followed by the type-name identifier, so skip a class-like keyword not followed by one.
@TomasVotruba
TomasVotruba enabled auto-merge (squash) October 10, 2026 09:01
@TomasVotruba
TomasVotruba merged commit 8713160 into main Oct 10, 2026
21 checks passed
@TomasVotruba
TomasVotruba deleted the fix-blink-rector-false-positives branch October 10, 2026 09:02
Sign up for free to 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