Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consider honoring SuspiciousModifierThen #340

Open
Goooler opened this issue Sep 25, 2024 · 1 comment
Open

Consider honoring SuspiciousModifierThen #340

Goooler opened this issue Sep 25, 2024 · 1 comment

Comments

@Goooler
Copy link

Goooler commented Sep 25, 2024

"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

@mrmans0n
Copy link
Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants