Lightsaber is a Dagger 2 plugin that detects unused code in your Module
s, Component
s and Subcomponent
s
/path/module/com/example/MyComponent.java:6:8: e: The @BindsInstance `myInt` declared in `test.MyComponent` is not used. [UnusedBindsInstances]
This plugin contains several rules:
- Empty
@Component
and@Subcomponent
- Unused
@BindsInstance
- Unused
@Provides
or@Binds
inside@Module
s - Unused
@Component(dependencies)
- Unused
@Inject
- Unused member injection methods (
Component.inject(Foo)
) - Unused
@Module
s - Unused Scopes (for example:
@Singleton
)
Add the plugin to your project:
// build.gradle.kts
plugins {
id("io.github.schwarzit.lightsaber") version "0.0.18"
}
And run ./gradlew lightsaberCheck
. Lightsaber will check your code and fail if there is any issue.
You can change that default for each rule from error to warnings or even ignore it completely like this:
import schwarz.it.lightsaber.gradle.Severity
lightsaber {
emptyComponents = Severity.Error
unusedBindsInstances = Severity.Error
unusedBindsAndProvides = Severity.Error
unusedDependencies = Severity.Error
unusedInjects = Severity.Error
unusedMembersInjection = Severity.Error
unusedModules = Severity.Error
unusedScopes = Severity.Error
}
Lightsaber supports the @Suppress
annotation. If you want to suppress an issue, you only have to add the @Suppress
annotation above the reported element with the rule name.
Example:
@Module
class MyModule {
@Suppress("UnusedBindsAndProvides")
@Provides
fun providesPotatoes() = "potatoes"
}
Clone the repo and execute:
./gradlew build