RemoveUnusedimports removes used imports
See original GitHub issueI ran this recipe on a few private repositories, and I had some compilation failures because of imports that where removed, but were in fact used. I fail to fin a pattern to explain the error, and thus create a unit test: sometimes the class was used in javadoc (@throws
or @link
), sometimes in annotations, …
So I played a bit with Moderne to reproduce on some public repositories. Here’s one: https://github.com/code4craft/webmagic/pull/1037/files
[INFO] --- maven-compiler-plugin:3.8.1:testCompile (default-testCompile) @ webmagic-extension ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 24 source files to /tmp/webmagic/webmagic-extension/target/test-classes
[INFO] /tmp/webmagic/webmagic-extension/src/test/java/us/codecraft/webmagic/MockPageModelPipeline.java: Some input files use or override a deprecated API.
[INFO] /tmp/webmagic/webmagic-extension/src/test/java/us/codecraft/webmagic/MockPageModelPipeline.java: Recompile with -Xlint:deprecation for details.
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] /tmp/webmagic/webmagic-extension/src/test/java/us/codecraft/webmagic/downloader/MockGithubDownloader.java:[932,26] cannot find symbol
symbol: class Request
location: class us.codecraft.webmagic.downloader.MockGithubDownloader
[ERROR] /tmp/webmagic/webmagic-extension/src/test/java/us/codecraft/webmagic/downloader/MockGithubDownloader.java:[932,43] cannot find symbol
symbol: class Task
location: class us.codecraft.webmagic.downloader.MockGithubDownloader
[ERROR] /tmp/webmagic/webmagic-extension/src/test/java/us/codecraft/webmagic/downloader/MockGithubDownloader.java:[932,12] cannot find symbol
symbol: class Page
location: class us.codecraft.webmagic.downloader.MockGithubDownloader
[ERROR] /tmp/webmagic/webmagic-extension/src/test/java/us/codecraft/webmagic/downloader/MockGithubDownloader.java:[933,9] cannot find symbol
symbol: class Page
location: class us.codecraft.webmagic.downloader.MockGithubDownloader
[ERROR] /tmp/webmagic/webmagic-extension/src/test/java/us/codecraft/webmagic/downloader/MockGithubDownloader.java:[933,25] cannot find symbol
symbol: class Page
location: class us.codecraft.webmagic.downloader.MockGithubDownloader
[ERROR] /tmp/webmagic/webmagic-extension/src/test/java/us/codecraft/webmagic/downloader/MockGithubDownloader.java:[936,29] cannot find symbol
symbol: class Request
location: class us.codecraft.webmagic.downloader.MockGithubDownloader
[ERROR] /tmp/webmagic/webmagic-extension/src/test/java/us/codecraft/webmagic/downloader/MockGithubDownloader.java:[937,25] cannot find symbol
symbol: class PlainText
location: class us.codecraft.webmagic.downloader.MockGithubDownloader
[INFO] 7 errors
Issue Analytics
- State:
- Created 2 years ago
- Comments:9 (8 by maintainers)
Top Results From Across the Web
Removed Used import · Issue #1085 · diffplug/spotless - GitHub
Hi Team, When trying to execute ./gradlew clean spotlessApply, it's removing one of the used imports. The project is on Java 8, ...
Read more >RemoveUnused · Scalafix - Scala Center
Removes unused imports and terms that reported by the compiler under -Ywarn-unused. ... Remove unused imports: // before import scala.
Read more >How to remove unused imports in Intellij IDEA on commit?
Choose the project/module you want to remove unused import from in Project view. Then from Code menu choose Optimize imports and confirm with...
Read more >RemoveUnusedImports - Error Prone
The check has no known bugs. If it reports an unused import that looks like it was actually used, try removing it and...
Read more >How to enable "remove unused imports"
Preferences->Editor->Auto Import->Optimize Imports on the Fly will automatically remove unuxed imports. 5. Avatar. Stephen Boesch · Created ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@murdos quick update - this should be fixed on main through
NoMissingTypes
.We’re working on a solution so that shared namespaces like
us.codecraft.webmagic.SpiderTest
will contain type info. ButNoMissingTypes
will prevent used imports from being removed unexpectedly.@murdos the new type cache accounts for the same FQN in multiple packages, but we’re still working on a release.