-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
NoUnusedImportsFixer - Ignore references in comments #2814
Description
no_unused_imports fixer searches for references to the imported elements almost everywhere in the code, including comments. This sometimes leads to not removing use statements that are unused because the same word was found in a comment, despite the comment being unrelated. See symfony/symfony#22962 (comment) for an example.
This check is done using a regular expression on the PHP code, which is the reason why the fixer can find false positives quite easily. IMO this is a bug and we should improve the regular expression.
But if we consider this a behavior change, then it would be nice to introduce a strict mode via a configuration option. When enabled, the fixer would only check usage of the imported elements in actual code and ignore comments completely (or look for PHPDocs/custom annotations only, e.g. @param Foo or @Annotation()).