mrmans0n / compose-rules

Lint rules for ktlint/detekt aimed to contribute to a healthier usage of Compose. Actively maintained and evolved fork of the Twitter Compose rules.
https://mrmans0n.github.io/compose-rules
Other
525 stars 19 forks source link

New useful rule: ConditionCouldBeLifted #280

Open amal opened 1 month ago

amal commented 1 month ago

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' ]
mrmans0n commented 1 month ago

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 1 month ago

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