mrmans0n/compose-rules

Consider honoring `SuspiciousModifierThen`

Opened this issue · 1 comments

"SuspiciousModifierThen",
"Using Modifier.then with a Modifier factory function with an implicit receiver",
"Calling a Modifier factory function with an implicit receiver inside " +
    "Modifier.then will result in the receiver (`this`) being added twice to the " +
    "chain. For example, fun Modifier.myModifier() = this.then(otherModifier()) - " +
    "the implementation of factory functions such as Modifier.otherModifier() will " +
    "internally call this.then(...) to chain the provided modifier with their " +
    "implementation. When you expand this.then(otherModifier()), it becomes: " +
    "this.then(this.then(OtherModifierImplementation)) - so you can see that `this` " +
    "is included twice in the chain, which results in modifiers such as padding " +
    "being applied twice, for example. Instead, you should either remove the then() " +
    "and directly chain the factory function on the receiver, this.otherModifier(), " +
    "or add the empty Modifier as the receiver for the factory, such as " +
    "this.then(Modifier.otherModifier())",

https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:compose/ui/ui-lint/src/main/java/androidx/compose/ui/lint/SuspiciousModifierThenDetector.kt;l=109-132

Interesting rule! The wording is so trippy, had to re-read multiple times XD