Skip to content

[Renaming] Keep unused import unless configured $rectorConfig->removeUnusedImports() on RenameClassRector on no namespace#3460

Merged
samsonasik merged 8 commits intomainfrom
keep-unused-import-unless-configured
Mar 6, 2023
Merged

[Renaming] Keep unused import unless configured $rectorConfig->removeUnusedImports() on RenameClassRector on no namespace#3460
samsonasik merged 8 commits intomainfrom
keep-unused-import-unless-configured

Conversation

@samsonasik
Copy link
Copy Markdown
Member

@samsonasik samsonasik commented Mar 6, 2023

When $rectorConfig->removeUnusedImports() is not used, the unused import should be kept, this is only happen on no namespace, ref:

Without namespace (got removed) : https://getrector.com/demo/1fe1232a-4741-4564-b225-8f0822338071
With namespace (unused use is kept) : https://getrector.com/demo/b4de0818-8ca3-496b-92c7-6f54e9ffd4cd

Fixes rectorphp/rector#7549

…UnusedImports() on RenameClassRector on no namespace
@samsonasik samsonasik requested a review from TomasVotruba as a code owner March 6, 2023 08:17
@samsonasik
Copy link
Copy Markdown
Member Author

Fixed 🎉

@samsonasik
Copy link
Copy Markdown
Member Author

rector-symfony test need to updated to cover this:

There were 3 failures:

1) Rector\Symfony\Tests\Set\Symfony62\Symfony62Test::test with data set #0
Failed asserting that string matches format description.
--- Expected
+++ Actual
@@ @@
 <?php
 
+use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
 use Symfony\Component\HttpFoundation\Response;
 use Symfony\Component\Routing\Annotation\Route;

@samsonasik
Copy link
Copy Markdown
Member Author

I created PR to rector-symfony for it rectorphp/rector-symfony#375

@samsonasik
Copy link
Copy Markdown
Member Author

Re-start build

@samsonasik
Copy link
Copy Markdown
Member Author

All checks have passed 🎉 @TomasVotruba I think it is ready.

@samsonasik
Copy link
Copy Markdown
Member Author

@TomasVotruba I am merging it ;)

@samsonasik samsonasik merged commit b3da981 into main Mar 6, 2023
@samsonasik samsonasik deleted the keep-unused-import-unless-configured branch March 6, 2023 11:57
samsonasik added a commit that referenced this pull request May 8, 2023
…UnusedImports() on RenameClassRector on no namespace (#3460)

* [Renaming] Keep unused import unless configured $rectorConfig->removeUnusedImports() on RenameClassRector on no namespace

* clean up fixture

* Fixed 🎉

* fix

* clean up

* clean up

* final touch: eol

* Fix
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

RenameClassRector ignored use.

1 participant