twitter / compose-rules

Static checks to aid with a healthy adoption of Compose
https://twitter.github.io/compose-rules
Other
1.35k stars 92 forks source link

Feature Request: Allow specifying an optional pattern for `ComposableNaming` #104

Closed ZacSweers closed 1 year ago

ZacSweers commented 1 year ago

Is your feature request related to a problem? Please describe. In our architecture we can define presenter functions that return State objects. These tend to be define similarly to how Molecule does it, where the function acts as business logic. This fails the naming check however.

@Composable
fun ProfilePresenter(
  userFlow: Flow<User>,
  balanceFlow: Flow<Long>,
): ProfileModel {
  val user by userFlow.collectAsState(null)
  val balance by balanceFlow.collectAsState(0L)

  return if (user == null) {
    Loading
  } else {
    Data(user.name, balance)
  }
}

Describe the solution you'd like It would be convenient if we could have a matcher config to ignore these types.

TwitterCompose:
  ComposableNaming:
    active: false
    functionNameExcludes: ['**Presenter']

Describe alternatives you've considered The only option right now is to suppress or disable the rule entirely.

Additional context Happy to send a PR if you're open to it 👍

mrmans0n commented 1 year ago

Yup, sounds like a great idea 😄
You'll need to modify ComposableNaming.kt and make sure that detekt/ComposableNamingCheck.kt and ktlint/ComposableNamingCheck.kt support the change (via tests).

ZacSweers commented 1 year ago

Hmm, I'm trying this now in the latest release but it doesn't appear to be working. Am I missing something about its configuration?

https://github.com/slackhq/circuit/pull/225