-
-
Notifications
You must be signed in to change notification settings - Fork 918
Option to disable phpstan-ignore-line and phpstan-ignore-next-line #11340
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
You can easily deny the old approach by some super-simple CI script. We did the same thing here: shipmonk-rnd/phpstan-rules#246 |
It would also be nice to have the option to enforce that a comment is always given with the ignore |
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: public function getNodeType(): string
{
return FileNode::class;
}
public function processNode(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 set
foreach ($linesToIgnore as $lineToIgnore => $identifiersToIgnore) {
// Skip line if specific identifiers are set
if (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 |
@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 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 |
PR has been submitted! |
Feature request
Hi,
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.
The text was updated successfully, but these errors were encountered: