Repository navigation
fix: honor an ignore marker on the annotated statement - #51
Open
joshdaugherty wants to merge 1 commit into
Open
joshdaugherty wants to merge 1 commit into
joshdaugherty wants to merge 1 commit into
Conversation
- `NodeVisitor::enterNode()` returns `DONT_TRAVERSE_CURRENT_AND_CHILDREN` for a node whose comment carries a matching `@pest-mutate-ignore` marker, but `nikic/php-parser` still calls `leaveNode()` on that node, so a mutator that targets the statement itself (`RemoveFunctionCall`, `RemoveMethodCall`, `RemoveEarlyReturn`) still mutated it - remember such nodes by object id in `enterNode()` and skip them in `leaveNode()` - add tests for a statement with a specific marker, a bare marker, an early return, a marker naming another mutator, and the statement after an annotated one Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What:
Description:
Fixes pestphp/pest#1993.
A
// @pest-mutate-ignore: <Mutator>comment on the line above a statement does not suppress that mutator when the mutator changes the statement itself. For example:still produces a
RemoveFunctionCallmutation forksort(). A marker naming a mutator that changes something inside the statement (such as a comparison in aforloop) already works.Cause: when a node's comment carries a matching marker,
NodeVisitor::enterNode()returnsNodeTraverser::DONT_TRAVERSE_CURRENT_AND_CHILDREN.nikic/php-parserskips the node's children for that value but still callsleaveNode()on the node itself, andleaveNode()is where the mutation is applied.RemoveFunctionCallandRemoveMethodCalltargetStmt\ExpressionandRemoveEarlyReturntargetsStmt\Return_, the node the comment is attached to, so they are not suppressed.Fix:
enterNode()records the node (byspl_object_id()) before returningDONT_TRAVERSE_CURRENT_AND_CHILDREN, andleaveNode()returns early for a recorded node. A newNodeVisitoris created for each traversal, so the record does not carry over between mutators or offsets.Tests added to
tests/Unit/MutationGeneratorTest.php:RemoveEarlyReturn: no mutation;Without the change to
NodeVisitor, the first three and the fifth fail; with it, all six pass.CI: this repository's workflows install with the branch name as the root version, which does not satisfy
pestphp/pest's^5.0.1requirement on this package, so a fork branch fails at Install Dependencies. Run on the fork withCOMPOSER_ROOT_VERSION=5.x-devset, this branch and unchanged5.xgive the same result: on PHP 8.4 withprefer-stable, the same threeTests\Visualsnapshot tests fail on both (316 passed on5.x, 322 with this change), and the PHPStan step reports the same two errors on both, in files this change does not touch. Theprefer-lowestjobs that ran pass on both.This touches the same two
returnstatements inenterNode()as #46, so whichever merges second needs a small rebase.