Skip to content

Using with Detekt

When using the Detekt Gradle Plugin, you can specify the dependency on this set of rules by using detektPlugins.

dependencies {
    detektPlugins "io.nlopez.compose.rules:detekt:<VERSION>"
}

Using with detekt CLI

The releases page contains an uber jar for each version release that can be used to run with the CLI version of detekt.

detekt -p detekt-compose-<VERSION>-all.jar -c your/config/detekt.yml

Enabling rules

For the rules to be picked up, you will need to enable them in your detekt.yml configuration file.

Compose:
  ComposableAnnotationNaming:
    active: true
  CompositionLocalAllowlist:
    active: true
    # You can optionally define a list of CompositionLocals that are allowed here
    # allowedCompositionLocals: LocalSomething,LocalSomethingElse
  CompositionLocalNaming:
    active: true
  ContentEmitterReturningValues:
    active: true
    # You can optionally add your own composables here
    # contentEmitters: MyComposable,MyOtherComposable
  DefaultsVisibility:
    active: true
  ModifierClickableOrder:
    active: true
  ModifierComposable:
    active: true
  ModifierMissing:
    active: true
    # You can optionally control the visibility of which composables to check for here
    # Possible values are: `only_public`, `public_and_internal` and `all` (default is `only_public`)
    # checkModifiersForVisibility: only_public
  ModifierNaming:
    active: true
  ModifierNotUsedAtRoot:
    active: true
    # You can optionally add your own composables here
    # contentEmitters: MyComposable,MyOtherComposable
  ModifierReused:
    active: true
  ModifierWithoutDefault:
    active: true
  MultipleEmitters:
    active: true
    # You can optionally add your own composables here
    # contentEmitters: MyComposable,MyOtherComposable
  MutableParams:
    active: true
  ComposableNaming:
    active: true
    # You can optionally disable the checks in this rule for regex matches against the composable name (e.g. molecule presenters)
    # allowedComposableFunctionNames: .*Presenter,.*MoleculePresenter
  ComposableParamOrder:
    active: true
  PreviewAnnotationNaming:
    active: true
  PreviewPublic:
    active: true
  RememberMissing:
    active: true
  RememberContentMissing:
    active: true
  UnstableCollections:
    active: true
  ViewModelForwarding:
    active: true
      # You can optionally use this rule on things other than types ending in "ViewModel" or "Presenter" (which are the defaults). You can add your own via a regex here:
      # allowedStateHolderNames: .*ViewModel,.*Presenter
  ViewModelInjection:
    active: true
    # You can optionally add your own ViewModel factories here
    # viewModelFactories: hiltViewModel,potatoViewModel

Disabling a specific rule

To disable a rule you have to follow the instructions from the Detekt documentation, and use the id of the rule you want to disable.

For example, to disable ComposableNaming:

@Suppress("ComposableNaming")
@Composable
fun myNameIsWrong() { }