Skip to content

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

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

Closed
eliashaeussler opened this issue Aug 7, 2024 · 6 comments

Comments

@eliashaeussler
Copy link

Hi,

I built a custom rule in eliashaeussler/phpstan-config#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
Copy link

janedbal commented Aug 7, 2024

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
Copy link
Contributor

ruudk commented Aug 7, 2024

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
Copy link

janedbal commented Aug 7, 2024

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
Copy link
Member

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
Copy link
Member

Duplicate of phpstan/phpstan#11340

@ondrejmirtes ondrejmirtes marked this as a duplicate of phpstan/phpstan#11340 Aug 8, 2024
Copy link

github-actions bot commented Sep 9, 2024

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 9, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants