:wave: hey all.... I have two scenarios in mind wh...
# detekt
s
👋 hey all.... I have two scenarios in mind where I think detekt could be useful and wanted to get your opinion if detekt is the right tool or if something similar exists... Scenario 1: we are doing an incremental migration from one assertion library to another. Old code remain the same, but for new code we should use the new library. To help devs who sometimes forget, would be useful for a detekt rule that checks for imports/functions of the old library and fail the build Scenario 2: We use Jetpack Compose on Android. There is the generic function
collectAsState()
that's useful on other platforms, but probably wrong most of the time on Android. On Android we should be using
collectAsStateWithLifecycle()
. This is where a detekt rule might help. The way I see it, it can be one rule that covers both. And it has a deny list of functions/imports that the user can configure to fail the build. Are you aware if something like this exists? Would detekt be the right tool to implement this? Thanks
m
I think both are cases where detekt can be helpful. In fact the detekt code base also uses it. You could look at the `ForbiddenImport`and
ForbiddenMethodCall
rules.
Copy code
# example from the <https://github.com/detekt/detekt/blob/main/config/detekt/detekt.yml>
ForbiddenImport:
  active: true
  imports:
    - value: 'org.junit.jupiter.api.Assertions*'
      reason: 'Use AssertJ assertions instead.'
    - value: 'org.junit.jupiter.api.assertThrows'
      reason: 'Use AssertJ assertThatCode { }.isInstanceOf() or assertThatExceptionOfType().isThrownBy { } instead.'
    - value: 'java.util.stream.*'
      reason: "Use Kotlin's sequences instead."
  ForbiddenMethodCall:
    active: true
    methods:
      - 'kotlin.io.print'
      - 'kotlin.io.println'
      - 'java.net.URL.openStream'
      - 'java.lang.Class.getResourceAsStream'
      - 'java.lang.ClassLoader.getResourceAsStream'
      - 'org.jetbrains.kotlin.diagnostics.DiagnosticUtils.getLineAndColumnInPsiFile'
👍 3
s
Thanks
a
For this
that's useful on other platforms, but probably wrong most of the time on Android. On Android we should be
in detekt you have to set different config in each repo. I don’t know anyway where we can override one rule config differently in each repo