mrmans0n/compose-rules

New useful rule: ConditionCouldBeLifted

Closed this issue · 3 comments

amal commented

In the other set of Compose rules I've seen a useful one: ConditionCouldBeLifted.

This is the source:
https://github.com/appKODE/detekt-rules-compose/blob/a481fb7/src/main/kotlin/ru/kode/detekt/rule/compose/ConditionCouldBeLifted.kt

I'd like to use it, but this ruleset conflicts with yours and I don't want to switch from yours :)
Can you please add it here?

It reports cases where a Compose layout contains a single conditional expression which could be lifted.

Non-compliant:

Column {
  if(condition) {
    Row()
    Row()
  }
}

Compliant:

if(condition) {
  Column {
    Row()
    Row()
  }
}

ignoreCallsWithArgumentNames config option allows to specify argument names which (when present) will make this rule ignore and skip those calls:

ConditionCouldBeLifted:
  active: true
  ignoreCallsWithArgumentNames: [ 'modifier', 'contentAlignment' ]

Doesn't it work if you have both at the same time?
Iirc their ruleset is "compose" and this one is "Compose", can't detekt differentiate them? (Asking from ignorance lol)

amal commented

I've tried to use both before and it had some problems, but atm I don't remember what exactly )

Gonna close this one, because:

  • It's possible to run both rulesets at the same time, this one is "Compose" and the other one is "compose" so they shouldn't clash.
  • Even if we wanted to implement something similar to this, it's just not possible as we don't use type resolution rules (this might change in the future though, but not in the near future), as they are detekt only.