phptools-docs
phptools-docs copied to clipboard
Autocompletion for `@phpstan-ignore`
Since PHPStan 1.11.0, it supports ignoring errors using identifiers (https://phpstan.org/user-guide/ignoring-errors).
- When I type
@phps, I would like to get autocomplete suggestion@phpstan-ignore, - When I type
@phpstan-ignore ar, I would like to get autocomplete suggestions with all identifiers starting withar. List of all identifiers is available here: human-readable, JSON, - I would like to see a warning when I use
@phpstan-ignore-lineor@phpstan-ignore-next-lineinstead of@phpstan-ignore.
Thank you for the suggestion!
- [x] 1. will be implemented
- [ ] 2. I'll look into it, it would be nice to also respect it by our in-editor linter.
- [ ] 3. Question - is
@phpstan-ignore-linedeprecated or not recommended in some way? Or is it a personal preference?
A side note - our linter may not respect the @phpstan-ignore directive.
Is
@phpstan-ignore-lineline deprecated or not recommended in some way? Or is it a personal preference?
It's not deprecated. PHPStan Pro has a feature to migrate @phpstan-ignore-line to @phpstan-ignore, so it seems like it's a recommended approach. It's stricter, more specific, and prevents you from accidentally ignoring more errors than you wanted.
I'll look into it, it would be nice to also respect it by our in-editor linter.
Do you mean “validate whether given error identifier exists”, or “ignore specific PHP Tools errors when @phpstan-ignore is used”?
I don't think that 1 is viable, because third-party plugins may provide their own error identifiers.
As for 2, since PHPStan and PHP Tools are completely different tools, I don't really expect ignoring errors to be interoperable between them (although it could be useful).
I see, thank you for the explanation.
We can add a code action to migrate @phpstan-ignore-line to @phpstan-ignore.
We can "map" some of PhpStan's identifiers to our error codes and respect them - so we would ignore the corresponding PhpTools warning.
We can add a code action to migrate
@phpstan-ignore-lineto@phpstan-ignore.
Is there a reliable way to tell what are identifiers of the errors that are ignored with @phpstan-ignore-line? I think you would need to remove @phpstan-ignore-line, run PHPStan to see what errors will that uncover in order to know their identifiers and only then you could perform automated fix. Also, after you migrated your projects, you would never use it again, so if it is as complex as it seems, I don't think it's worth it.
We can "map" some of PhpStan's identifiers to our error codes and respect them - so we would ignore the corresponding PhpTools warning.
That seems really nice :)
-
You're right, that couldn't be that sophisticated. Just a regular rename and the error identifier(s) would need to be typed by the user. Not worth it.
-
I agree :)