Hopefully this is the right place to ask this :sli...
# compiler
p
Hopefully this is the right place to ask this 🙂 We are using the strict API for our internal modules (not published anywhere) to avoiding leaving details across modules. However, one (understandable) side effect is that any component defined as public is never marked as unused by the IDE even if there is no uses. Is there any way to make sure that we are not leaving unused code in our project? Given that we are probably not using it correctly as is 😅
t
You can run “Unused symbol inspection” on IDEA project
t
@turansky Do you know if tests won't be considered entry points if they're excluded from inspection scope?
p
Ah, yeah that, along with interfaces are the ones that tend to make the unused marking problematic IMHO
p
https://kotlinlang.slack.com/archives/C7L3JB43G/p1617128739035100?thread_ts=1617122770.034800&cid=C7L3JB43G I’ve tried running inspect code on Android Studio (couldn’t find the mentioned option) and added an unused public interface and it didn’t show any results 😞
l
Did you report the issue?
p
I didn’t as it’s probably working as expected. Similarly to interfaces, there is no way the compiler can know if a given public API is going to be used outside a project. I’m unsure if there could be an IDE plugin or setting that could be made but it’s probably out of the scope of the explicit API lib.
l
I think it's more an issue of the unused code detector being confused by an unexpected
public
modifier/annotation, and it needs to be updated to support that. The normal behavior is to have unreferenced code shown as unused (which you can fix with automated tests or a sample module).
p
How does the compiler know if the module is consumed by a local app or by a third party after publishing it? If you have a public API unreferenced code doesn’t work, as it may be referenced by consumers of the API, external to the current project.
l
The compiler cannot know, I was talking about the IDE which can know for tests and other modules.
p
Same problem though, how does it know that the module is not also published as part of a public library? It would be interesting if there was a way to tweak this though. For instance, another similar issue is when you have code that is only referenced by tests it doesn’t mark it as unused but for production purposes they are unused
l
It cannot know, but if the code is tested, no problem.