Skip to content

Commit

Permalink
Improve code position (#234)
Browse files Browse the repository at this point in the history
  • Loading branch information
BraisGabin authored Aug 4, 2024
1 parent 20f574d commit bafc442
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ internal class UnusedInjectKsp : LightsaberKspRule {
val injectName = inject.parent as KSClassDeclaration
Finding(
"The @Inject in `${injectName.qualifiedName!!.asString()}` constructor is unused because there is a @Provides defined in `${parent.qualifiedName!!.asString()}.${provide.simpleName.getShortName()}`.",
inject.location.toCodePosition(),
inject.annotations
.single { it.annotationType.resolve().declaration.qualifiedName!!.asString() == Inject::class.qualifiedName!! }
.location
.toCodePosition(),
inject::hasSuppress,
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@ internal fun checkUnusedScopes(
.map { (component, scope) ->
Finding(
"The scope `$scope` on component `$component` is not used.",
component.getScopeCodePosition(daggerProcessingEnv, scope.scopeAnnotation()!!.annotationTypeElement()!!.toString()),
component.getScopeCodePosition(
daggerProcessingEnv,
scope.scopeAnnotation()!!.annotationTypeElement()!!.toString(),
),
component.componentPath().currentComponent()::hasSuppress,
)
}
Expand Down Expand Up @@ -87,7 +90,10 @@ internal class UnusedScopesKsp : LightsaberKspRule {
val annotationName = scopes.find { classDeclaration.hasAnnotation(it) }
Finding(
"The `@$annotationName` scope is unused because `${classDeclaration.qualifiedName!!.asString()}` doesn't contain any constructor annotated with `@Inject`.",
classDeclaration.location.toCodePosition(),
classDeclaration.annotations
.single { it.annotationType.resolve().declaration.qualifiedName!!.asString() == annotationName }
.location
.toCodePosition(),
classDeclaration::hasSuppress,
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import schwarz.it.lightsaber.utils.extension
internal class UnusedInjectKtTest {

@ParameterizedTest
@CsvSource("kapt,4,14", "ksp,5,")
@CsvSource("kapt,4,14", "ksp,6,")
fun injectNotUsed(
@ConvertWith(CompilerArgumentConverter::class) compiler: KotlinCompiler,
line: Int,
Expand Down Expand Up @@ -43,7 +43,9 @@ internal class UnusedInjectKtTest {
import javax.inject.Inject
class Foo @Inject constructor()
class Foo
@Inject
constructor()
""".trimIndent(),
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ internal class UnusedScopesKtTest {
}

@ParameterizedTest
@CsvSource("kapt,5,14", "ksp,6,")
@CsvSource("kapt,5,14", "ksp,5,")
fun singletonNoInject_Errors(
@ConvertWith(CompilerArgumentConverter::class) compiler: KotlinCompiler,
line: Int,
Expand Down Expand Up @@ -121,7 +121,7 @@ internal class UnusedScopesKtTest {
}

@ParameterizedTest
@CsvSource("kapt,5,14", "ksp,6,")
@CsvSource("kapt,5,14", "ksp,5,")
fun customScopeNoInject_Error(
@ConvertWith(CompilerArgumentConverter::class) compiler: KotlinCompiler,
line: Int,
Expand Down

0 comments on commit bafc442

Please sign in to comment.