I'm trying to convert my rule to using type resolu...
# detekt
d
I'm trying to convert my rule to using type resolution: • Added
@RequiresTypeResolution
to the rule class • In my test (using
KoTest
) I have called
createEnvironment()
• Then I switched to
MyRule().compileAndLintWithContext(env, code)
All existing tests keep passing (so no errors in test/env setup). But the following code:
Copy code
fun visitNamedFunction(function: KtNamedFunction) {
  println(bindingContext.getType(function))
}
prints "*null*". I have also checked that
bindingContext == BindingContext.EMPTY
returns false. Did I miss someting?
oooh, I have found that
Copy code
bindingContext.diagnostics.forEach {
      println(it.factoryName)
    }
prints:
Copy code
UNRESOLVED_REFERENCE
UNRESOLVED_REFERENCE
UNRESOLVED_REFERENCE
UNRESOLVED_REFERENCE
UNRESOLVED_REFERENCE
UNRESOLVED_REFERENCE
UNRESOLVED_REFERENCE
UNRESOLVED_REFERENCE
UNUSED_PARAMETER
Looks like my sample test code is not set up for compiling 🙂
And it looks like I have to provide a path to compose sources somehow. Because my rule uses
@Composable
and
Modifier
and all that. There's
additionalRootPaths
parameters, but not sure what to feed there for
Compose
. Investigating.
b
What is the output for
./gradlew test -Pcompile-test-snippets=true
? I'm guessing here but probably you need to add compose as a
testImplementation
dependency the gradle module.
d
Thank you! I will try both!