DEVSENSE / phptools-docs

PHP Tools public content
Apache License 2.0
77 stars 10 forks source link

Autocompletion for `@phpstan-ignore` #610

Open jrmajor opened 1 month ago

jrmajor commented 1 month ago

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.
jakubmisek commented 1 month ago

Thank you for the suggestion!

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

jrmajor commented 1 month ago

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).

jakubmisek commented 1 month ago

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.

jrmajor commented 1 month ago

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

jakubmisek commented 1 month ago