You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Option to disable phpstan-ignore-line and phpstan-ignore-next-line #11340
With the release of version 1.11, a new annotation, @phpstan-ignore, was introduced, allowing developers to specify an error identifier as a parameter. This feature provides a significant advantage over @phpstan-ignore-line and @phpstan-ignore-next-line, as it targets specific error identifiers rather than ignoring all potential errors on a given line. Consequently, it ensures that any new violations introduced on the same line are detected, improving overall code quality and reducing the risk of missing critical issues.
Given these benefits, I would like to request the addition of a configuration option to disable the use of @phpstan-ignore-line and @phpstan-ignore-next-line. By enabling this configuration, development teams can enforce the use of @phpstan-ignore with specific error identifiers, thereby promoting more precise and reliable error handling.
I believe that this feature will be a valuable addition to PHPStan, encouraging best practices and helping developers maintain higher standards of code quality.
Did PHPStan help you today? Did it make you happy in any way?
Thank you for considering this request. I appreciate your continued efforts in making PHPStan an indispensable tool for the PHP community.
We already have this information available in AnalyserResult (getLinesToIgnore, getUnmatchedLineIgnores) so it's something that could be easily achieved with a few lines in AnalyserResultFinalizer.
FWIW, I currently have this feature implemented in a custom rule like this:
publicfunctiongetNodeType(): string
{
return FileNode::class;
}
publicfunctionprocessNode(Node$node, Scope$scope): array
{
/** @var array<int, non-empty-list<string>|null> $linesToIgnore */$linesToIgnore = $node->getAttribute('linesToIgnore');
$errors = [];
// identifiersToIgnore is null in case no specific identifiers are set, and a (non-empty) array in case specific identifiers are setforeach ($linesToIgnoreas$lineToIgnore => $identifiersToIgnore) {
// Skip line if specific identifiers are setif (is_array($identifiersToIgnore)) {
continue;
}
$errors[] = RuleErrorBuilder::message('PHPStan ignored line without identifiers')
->tip('Add at least one identifier with the `@phpstan-ignore` directive or in the `parameters.ignoreErrors` config')
->nonIgnorable()
->line($lineToIgnore)
->identifier('someIdentifier')
->build()
;
}
return$errors;
}
Unfortunately, the interface of the FileNode doesn't seems to have a public getLinesToIgnore(), so I have to use the ->getAttribute('linesToIgnore') approach instead.
@ondrejmirtes You mentioned in the phpstan-strict-rules package that it should be a quick change using AnalyserResult; does this mean you're open to having this integrated into core PHPStan? I'd be happy to look into providing a PR for this.
Another feature we're looking into is requiring reasons for ignore lines; not sure if this is out of scope for this issue. Even with above custom rule it's possible to write an ignore line like @phpstan-ignore missingType.checkedException without providing a reason. Is this also something we could integrate?
@janedbal My plan is to deprecate these two completely and remove them in PHPStan 3.0.
The problem with them is that people use them with error identifiers, but they silently ignore all errors anyway. Since changing this behaviour would be a BC break, it's better to completely remove them.
And if there's still need, we can introduce something like @phpstan-ignore-all that would fail with anything else inside the comment, aside from comment inside (...).
The problem with them is that people use them with error identifiers, but they silently ignore all errors anyway.
Yes, we missed that (the documentation was not clear). As a consumer, I think we would be happy with the removal of all ignores apart from the one that allows specification of which warnings to ignore.
Alright, I changed my mind. reportIgnoresWithoutComments: true will also disallow @phpstan-ignore-line and @phpstan-ignore-next-line. Since this a new option and the default is false, this is not a BC break.
Also it makes sense in my eyes, because @phpstan-ignore-line and @phpstan-ignore-next-line don't have an actual syntax for comments. As opposed to @phpstan-ignore which has officially supported comments by the parser in parentheses.
Reacted by Bernhard O., Gottem and Alexander M. Turek
Activity
janedbal commentedon Jul 15, 2024
You can easily deny the old approach by some super-simple CI script. We did the same thing here: shipmonk-rnd/phpstan-rules#246
calebdw commentedon Jul 15, 2024
It would also be nice to have the option to enforce that a comment is always given with the ignore
ondrejmirtes commentedon Aug 8, 2024
We already have this information available in AnalyserResult (getLinesToIgnore, getUnmatchedLineIgnores) so it's something that could be easily achieved with a few lines in AnalyserResultFinalizer.
petski commentedon Sep 18, 2024
FWIW, I currently have this feature implemented in a custom rule like this:
Unfortunately, the interface of the FileNode doesn't seems to have a public
getLinesToIgnore(), so I have to use the->getAttribute('linesToIgnore')approach instead.NanoSector commentedon Apr 25, 2025
@petski Thank you, this also works well for us.
@ondrejmirtes You mentioned in the phpstan-strict-rules package that it should be a quick change using
AnalyserResult; does this mean you're open to having this integrated into core PHPStan? I'd be happy to look into providing a PR for this.Another feature we're looking into is requiring reasons for ignore lines; not sure if this is out of scope for this issue. Even with above custom rule it's possible to write an ignore line like
@phpstan-ignore missingType.checkedExceptionwithout providing a reason. Is this also something we could integrate?calebdw commentedon May 1, 2025
PR has been submitted!
phpstan-bot commentedon Feb 23, 2026
Closed via merging phpstan/phpstan-src#3976
janedbal commentedon Feb 23, 2026
Is this really closed by phpstan/phpstan-src#3976 ? That part about
phpstan-ignore-line+phpstan-ignore-next-lineseems not to be present there.ondrejmirtes commentedon Feb 23, 2026
@janedbal My plan is to deprecate these two completely and remove them in PHPStan 3.0.
The problem with them is that people use them with error identifiers, but they silently ignore all errors anyway. Since changing this behaviour would be a BC break, it's better to completely remove them.
And if there's still need, we can introduce something like
@phpstan-ignore-allthat would fail with anything else inside the comment, aside from comment inside(...).ondrejmirtes commentedon Feb 23, 2026
Reverting the PR for now, it didn't worked properly.
phpstan-bot commentedon Feb 23, 2026
Closed via merging phpstan/phpstan-src#5032
derrabus commentedon Feb 23, 2026
Is this really fixed by phpstan/phpstan-src#5032? I still cannot disallow the old ignore comments, can I?
ondrejmirtes commentedon Feb 23, 2026
@derrabus No, see: #11340 (comment)
The option only disallows
@phpstan-ignorewithout comment for each identifier.derrabus commentedon Feb 23, 2026
Shall we reopen this issue then? 🙂
[TASK] Specify the PHPStan errors to ignore for deprecation notices
[TASK] Specify the PHPStan errors to ignore for deprecation notices (#…
JakeQZ commentedon Mar 5, 2026
Yes, we missed that (the documentation was not clear). As a consumer, I think we would be happy with the removal of all
ignores apart from the one that allows specification of which warnings to ignore.ondrejmirtes commentedon Mar 16, 2026
Alright, I changed my mind.
reportIgnoresWithoutComments: truewill also disallow@phpstan-ignore-lineand@phpstan-ignore-next-line. Since this a new option and the default isfalse, this is not a BC break.Also it makes sense in my eyes, because
@phpstan-ignore-lineand@phpstan-ignore-next-linedon't have an actual syntax for comments. As opposed to@phpstan-ignorewhich has officially supported comments by the parser in parentheses.derrabus commentedon Mar 24, 2026
Awesome, thank you!
github-actions commentedon Apr 25, 2026
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.