Skip to content

fix: honor a bare @pest-mutate-ignore regardless of trailing text - #46

Open
bpmore wants to merge 1 commit into
pestphp:5.xfrom
bpmore:fix/pest-mutate-ignore-parsing
Open

bpmore wants to merge 1 commit into
pestphp:5.xfrom
bpmore:fix/pest-mutate-ignore-parsing

Conversation

@bpmore

@bpmore bpmore commented Oct 2, 2026

Copy link
Copy Markdown

This fixes defects 1 and 2 reported in pestphp/pest#1942. It is the fix offered in that issue, unchanged, with tests.

What changes

  • src/Support/NodeVisitor.php: the captured tail is trimmed before the empty test. Previously // @pest-mutate-ignore (with a trailing space) and /** @pest-mutate-ignore */ produced a non-empty tail. That tail matched no mutator name, so the annotation suppressed nothing.
  • src/Support/MutationGenerator.php: $mutatorsToIgnore is reset for each annotated line. Previously, once any earlier line used the @pest-mutate-ignore: form, a later bare annotation was recorded with that earlier line's mutator list, because ?? ['all'] could no longer fire.

The meaning of a named list is unchanged: an unknown mutator name still suppresses nothing.

Tests

Added to tests/Unit/MutationGeneratorTest.php:

  • a bare annotation with trailing whitespace suppresses every mutator on the statement below it;
  • a bare single-line doc block suppresses every mutator on the function;
  • a bare annotation after a @pest-mutate-ignore: IfNegated line suppresses every mutator, rather than only IfNegated;
  • an unknown mutator name still suppresses nothing, in three forms: plain, with trailing whitespace, and in a doc block.

With the two source changes reverted, the first three fail and the unknown-name cases still pass. Reverting NodeVisitor.php alone fails the first two. Reverting MutationGenerator.php alone fails the third.

The full suite on PHP 8.4, macOS, reads 3 failed, 322 passed, against 3 failed, 316 passed on 5.x without this change. The 3 failures are the same visual snapshot tests on both. composer test:types reports the same 2 errors before and after, in AbstractFunctionCallUnwrapMutator.php and RemoveEarlyReturn.php, which this change does not touch. Pint passes.

Not in this pull request

- Trim the captured tail before testing it for empty, so a trailing space or a single-line doc block's closing `*/` no longer makes a bare annotation suppress nothing.
- Reset the per-line mutator list in the line scan, so a bare annotation means all mutators instead of inheriting the list from an earlier `@pest-mutate-ignore:` line.
- Add tests for both, and for an unknown mutator name still suppressing nothing.

Fixes defects 1 and 2 of pestphp/pest#1942.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
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