this post was submitted on 08 Jan 2026
10 points (91.7% liked)

Programming

24365 readers
639 users here now

Welcome to the main community in programming.dev! Feel free to post anything relating to programming here!

Cross posting is strongly encouraged in the instance. If you feel your post or another person's post makes sense in another community cross post into it.

Hope you enjoy the instance!

Rules

Rules

  • Follow the programming.dev instance rules
  • Keep content related to programming in some way
  • If you're posting long videos try to add in some form of tldr for those who don't want to watch videos

Wormhole

Follow the wormhole through a path of communities !webdev@programming.dev



founded 2 years ago
MODERATORS
 

Is it even possible? It seems every third-party tool that did it is abandoning the feature and I can't get the deprecated but still present feature to work in Detekt or ktlint. I didn't realise the biggest challenge with Kotlin would be detecting unused import statements so I can easily remove them.

Edit: Thanks for the help everyone, but I could not get anything working so I eventually just did it manually with a little help from the android linter.

top 7 comments
sorted by: hot top controversial new old
[–] jere@feddit.org 3 points 3 days ago* (last edited 2 days ago) (1 children)

I use ktlint with spotless. If you want to remove unused imports and wildcard imports, you need to activate those rules in your .editorconfig file in your project dir.

Please add following lines to your .editorconfig for correct behavior with IntelliJ:

https://pinterest.github.io/ktlint/latest/rules/configuration-intellij-idea/

No unused imports and no wildcard imports are standard rules:

https://pinterest.github.io/ktlint/latest/rules/standard/

Add ktlint rules in the same file:

ktlint_standard_no-wildcard-imports = enabled
ktlint_standard_no-unused-imports = enabled
[–] dr_robotBones@reddthat.com 1 points 3 days ago (1 children)

I tried ktlint, it was having trouble handling libraries and kept giving me no reference errors for library imports.

[–] jere@feddit.org 3 points 3 days ago

Well, I recommend you trying to use the spotless plugin for Maven/Gradle and configuring ktlint or ktfmt. Maybe try ktlint first with my configuration tips. If it doesn't work, you could show us your repository or a snippet of it.

[–] HelloRoot@lemy.lol 1 points 4 days ago* (last edited 3 days ago) (2 children)
kotlinc -Xanalysis-mode=unused-imports -Xreport-perf -Xuse-k2 $(find "$SRC_DIR" -name '*.kt')

maybe you need to play around with the flags, I'm away from pc and can't test, but from the top of my head and a quick search it should be something like that

on arch linux it comes from this package: https://archlinux.org/packages/extra/any/kotlin/ not sure about other distros

no clue about windows

[–] dr_robotBones@reddthat.com 2 points 3 days ago (1 children)

I got the Kotlin compiler using sdkman, the closest thing to that command I found was: kotlinc -Xreturn-value-checker=full $(find . -name '*.kt')

It doesn't really work, it just gives errors for every single import that comes from a library (libKTX in my case)

[–] HelloRoot@lemy.lol 2 points 3 days ago* (last edited 3 days ago)

My bad, I think the option I mentioned might have existed at some point but doesn't now.

Sadly it's probably a moating strategy for jetbrains to have that as an IDE exclusive feature.

The best you can probably do is trying to dig out that functionality from the android studio source ... https://android.googlesource.com/platform/tools/base/+/studio-master-dev/studio.md

[–] dr_robotBones@reddthat.com 1 points 3 days ago

The debian/ubuntu package for the Kotlin compiler is super outdated, so I'll have to find a way to get it