phptools-docs icon indicating copy to clipboard operation
phptools-docs copied to clipboard

Autocompletion for `@phpstan-ignore`

Open jrmajor opened this issue 1 year ago • 5 comments

Since PHPStan 1.11.0, it supports ignoring errors using identifiers (https://phpstan.org/user-guide/ignoring-errors).

  1. When I type @phps, I would like to get autocomplete suggestion @phpstan-ignore ,
  2. When I type @phpstan-ignore ar, I would like to get autocomplete suggestions with all identifiers starting with ar. List of all identifiers is available here: human-readable, JSON,
  3. I would like to see a warning when I use @phpstan-ignore-line or @phpstan-ignore-next-line instead of @phpstan-ignore.

jrmajor avatar Jul 29 '24 11:07 jrmajor

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-line deprecated or not recommended in some way? Or is it a personal preference?

A side note - our linter may not respect the @phpstan-ignore directive.

jakubmisek avatar Jul 29 '24 11:07 jakubmisek

Is @phpstan-ignore-line line 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).

jrmajor avatar Jul 29 '24 11:07 jrmajor

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.

jakubmisek avatar Jul 29 '24 12:07 jakubmisek

We can add a code action to migrate @phpstan-ignore-line to @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 :)

jrmajor avatar Jul 29 '24 12:07 jrmajor

  • 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 :)

jakubmisek avatar Jul 29 '24 12:07 jakubmisek