Conversation
…stacked docblocks UnusedImportRemovingPostRector checks each docblock of a node on a clone with setDocComment(), but the clone keeps the PHP_DOC_INFO attribute already resolved for the original node (its last docblock), so the factory returns that PhpDocInfo instead of parsing the docblock: only the last docblock is scanned and the imports used by the earlier ones are removed. Clear the attribute on the clone.
Member
|
This would break a docblock standard that is generally recognized and would lead to unexpected consequences. Fix the docblock to one instead. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
With
->withImportNames(removeUnusedImports: true), a node carrying two docblocks loses the imports referenced only in the first one:use App\Attr\First;is removed, with no rule applied. The same two annotations in a single docblock are fine; with three stacked docblocks, the first two imports go.Cause:
UnusedImportRemovingPostRector::findNamesInDocBlocks()checks each docblock on aclone $nodewithsetDocComment($doc), but the clone keeps thePHP_DOC_INFOattribute already resolved for the original node — i.e. its last docblock — socreateFromNodeOrEmpty()returns that cachedPhpDocInfoinstead of parsing$doc. Only the last docblock is ever scanned. It shows as soon as anything resolved the node's docblock earlier in the run:DocblockNameImportingPostRectorwithimportDocBlockNames(the default), or any rule reading the docblock — which is why the existing fixtures, whose configs do neither, pass.Fix: clear the attribute on the clone. Fixture added to
tests/Issues/NamespacedUseAutoImport(its config already enables bothremoveUnusedImports()andimportNames()); it fails onmain(-use Carbon\CarbonInterface;) and passes with the change. Full suite: 5290 tests green; ecs and phpstan report nothing new on the changed file.