Follow-up from #2587807: Drupal.Classes.UnusedUseStatement needs to scan comments.
Can Coder Sniffer scan for alias usages in e.g. @var
statements and correct them to the FQN as well as removing the extraneous use statement?
PhpStorm auto-aliases this stuff, and unless we turn off automatic importing, we can't escape it (yet). I use that IDE mostly, and I have no good way to disable the UnusedUseStatement sniff when running phpcbf
(except turning ON every other sniff, which is cumbersome).
So:
use \Drupal\Core\Url;
// ...
/** @var Url $link **/
becomes
// ...
/** @var \Drupal\Core\Url $link **/
(use statement removed, documentation reference changed to FQN)
Also, the remove-use statement fix would not run unless it was sure it had fixed all aliases in known documentation tokens like @see
, @var
, etc. (since loose references are probably impossible to parse).
Comments
Comment #3
klausiImplemented - please test!
Comment #4
klausiKind of a follow-up: #2841777: Throw error if data type in docs is not fully namespaced