phpstan / phpstan-strict-rules

Extra strict and opinionated rules for PHPStan
MIT License
606 stars 48 forks source link

Feature request: Rule to disallow usage of `@phpstan-ignore-*` annotations without error identifier #245

Closed eliashaeussler closed 3 months ago

eliashaeussler commented 3 months ago

Hi,

I built a custom rule in https://github.com/eliashaeussler/phpstan-config/pull/53 that disallows the usage of @phpstan-ignore-line and @phpstan-ignore-next-line annotations without error identifiers.

Is this something you'd consider useful as a part of the strict-rules package? If so, I'd be happy to provide a PR. If not, that's fine as well :)

Cheers!

janedbal commented 3 months ago

Just for a reference, the same thing can be achieved with ~30 lines of php code. Example: https://github.com/shipmonk-rnd/phpstan-rules/pull/246/files

ruudk commented 3 months ago

Another approach could be to introduce a config parameter that allows for skipping reading of this token. Then PHPStan acts as if the token is not there at all, and thus the error that it tries to hide still shows up. Might even require less code.

janedbal commented 3 months ago

Another approach could be to introduce a config parameter that allows for skipping reading of this token.

I like that. Super simple and easy to do. Just one more config param to be passed to PHPStan\Parser\RichParser. If @ondrejmirtes likes that too, I can implement that.

ondrejmirtes commented 3 months ago

Not a fan. Less code isn't always better. I'd rather write more code and have the error messages under control.

In my opinion @phpstan-ignore-line and @phpstan-ignore-next-line should always work to ignore errors because it's a core feature. But we should report usage of these comments as a new error if the user chooses to.

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.

ondrejmirtes commented 3 months ago

Duplicate of https://github.com/phpstan/phpstan/issues/11340

github-actions[bot] commented 2 months ago

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.