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

Elements accept and respect a Modifier parameter in Jetpack Compose #5276

Closed
chao2zhang opened this issue Sep 5, 2022 · 5 comments
Closed
Labels

Comments

@chao2zhang
Copy link
Member

Relevant convention:
https://github.com/androidx/androidx/blob/androidx-main/compose/docs/compose-api-guidelines.md#elements-accept-and-respect-a-modifier-parameter

Rule constraints that is reasonable to implemented in Detekt:

  • Element functions MUST accept a parameter of type Modifier.
  • This parameter MUST be named "modifier" and MUST appear as the first optional parameter in the element function's parameter list.
  • Element functions MUST NOT accept multiple Modifier parameters
  • Element functions MUST provide their modifier parameter to the Compose UI node they emit by passing it to the root element function they call. If the element function directly emits a Compose UI layout node, the modifier MUST be provided to the node.
  • Element functions MUST NOT concatenate additional modifiers to the beginning of the received modifier parameter before passing the concatenated modifier chain to the Compose UI node they emit.
@BraisGabin
Copy link
Member

Detekt should be framework independent so I don't think we should implement this. But there is already a rule set that implements nearly all of those: https://github.com/appKODE/detekt-rules-compose

I use it on my project and it works great. I think that this issue should be open there with the missing parts that are not yet implemented.

@cortinico
Copy link
Member

Agree on @BraisGabin message.
If we really wish, we can create a detekt/detekt-compose repo using the rules template and keep those rules there if we want to make them a 1st party rule. Also as we don't have Compose code in the codebase, we won't be using those rules (which is another point for having them in a separate repo).

@chachako
Copy link

chachako commented Sep 7, 2022

Another rules library that may be helpful: https://github.com/twitter/compose-rules

@3flex
Copy link
Member

3flex commented Sep 11, 2022

Agree with the comments above - and the Twitter rule set would be a great one to showcase in the marketplace once #5191 is done.

@chao2zhang
Copy link
Member Author

Thanks for the replies! twitter/compose-rules seem to be a good third-party repository for people to look into. Hoepfully we will enrich our rules marketplace in #5191

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

No branches or pull requests

5 participants