Skip to content

Add documentation for selective mutation ignore annotations support - #7

Draft
theofidry wants to merge 2 commits into
mainfrom
docs/selective-ignore-annotations
Draft

theofidry wants to merge 2 commits into
mainfrom
docs/selective-ignore-annotations

Conversation

@theofidry

@theofidry theofidry commented Nov 3, 2026 •

Copy link
Copy Markdown
Member

See infection/infection#3717.

Generated with Codex. I would not review it yet as there is still some questions about the syntax or what is possible.

Comment thread guide/usage.md
```php
class Example
{
/** @infection-ignore ArrayItemRemoval, FalseValue */

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/** @infection-ignore ArrayItemRemoval, FalseValue */
// @infection-ignore ArrayItemRemoval, FalseValue

@theofidry theofidry left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not too happy with the result tbh... But I think I need a deeper review of the whole page

theofidry added a commit to infection/infection that referenced this pull request Nov 5, 2026
## Description

When only one mutator produces unwanted mutations,
`@infection-ignore-all` also excludes mutations users want to keep. The
new `@infection-ignore` annotation lets users name the mutators to
exclude:

```php
class Example
{
    /** @infection-ignore ArrayItemRemoval, FalseValue */
    public function values(): array
    {
        return [false, true];
    }
}
```

The annotation applies to the annotated code and everything nested
inside it. Nested annotations add to the inherited exclusions. Ordinary
comments work too:

```php
/** @infection-ignore ArrayItemRemoval */
class Example
{
    public function values(): array
    {
        // @infection-ignore FalseValue
        $defaults = [false, true];

        return [false, true];
    }
}
```

`ArrayItemRemoval` is excluded throughout the class. `FalseValue` is
excluded only in the assignment to `$defaults`; it can still mutate the
`false` in the return statement. `TrueValue` remains enabled in both
statements.

An annotation on an array item doesn't exclude `ArrayItemRemoval`,
because that mutator targets the array itself. The same annotation on
the return statement covers the array and excludes the mutation:

```php
class Example
{
    public function itemAnnotation(): array
    {
        return [
            // @infection-ignore ArrayItemRemoval
            false,
        ]; // ArrayItemRemoval can still produce [].
    }

    public function statementAnnotation(): array
    {
        // @infection-ignore ArrayItemRemoval
        return [false]; // ArrayItemRemoval is excluded here.
    }
}
```

**Names are exact and case-sensitive**. Warnings for unknown names and
empty lists include the source file and the annotated node's line
number. Built-in mutator names are recognised even when disabled, along
with configured custom mutator names.

As with `@infection-ignore-all`, excluded mutations aren't generated and
don't contribute to the `Ignored` result count.

## Changes

- Introduce `ExcludeIgnoredMutatorsVisitor` to attach ignored mutator
names to nodes during AST enrichment.
- Adapt `NodeMutationGenerator` to filter out each node's ignored
mutators.
- Clarify in the nomenclature that these exclusions apply during
mutation generation, after node eligibility has been determined.

## Documentation

See infection/infection.github.io#7.

## Related issues

Closes #2291.
@theofidry

Copy link
Copy Markdown
Member Author

Actually could add a post for it too

This branch has not been deployed

No deployments
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