twitter / compose-rules

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

Property 'TwitterCompose' is misspelled or does not exist. #100

Closed ege-ah closed 2 years ago

ege-ah commented 2 years ago

When the detektPlugin applied and rules added to the config file, CI build fails with error

Run failed with 1 invalid config property. - Property 'TwitterCompose' is misspelled or does not exist.

To Reproduce Steps to reproduce the behavior:

  1. Apply plugin
dependencies {
            detektPlugins("io.gitlab.arturbosch.detekt:detekt-formatting:$detektVersion")
            detektPlugins("com.twitter.compose.rules:detekt:$twitterComposeVersion")
        }
  1. Add compose rules to bottom of the existing detekt-config.xml
TwitterCompose:
  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
  ModifierComposable:
    active: true
  ModifierMissing:
    active: true
  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
  ComposableParamOrder:
    active: true
  PreviewNaming:
    active: true
  PreviewPublic:
    active: false
  RememberMissing:
    active: true
  UnstableCollections:
    active: true
  ViewModelForwarding:
    active: true
  ViewModelInjection:
    active: true
  1. Run ./gradlew sonarqube

Expected behavior Project compiles and CI build success

Instead it is failing on CI and locally, note that current detekt setup is working properly after deleting the TwitterCompose rule set.

Environment Version 1.21

* What went wrong:
Execution failed for task ':sonarqube'.
> Run failed with 1 invalid config property.
    - Property 'TwitterCompose' is misspelled or does not exist.
mrmans0n commented 2 years ago

This means your rule is not properly brought on the module detekt wants to be running on. Make sure your gradle setup is correct and the rule is being applied in the right place.

Namely, this means that your step 1 is not correctly done (e.g. not done in the right place, at all necessary times).

For example, this happened to me when I was applying the detekt gradle plugin to modules but the detektPlugins was not applied to exactly the same modules the gradle plugin was being applied to.

ege-ah commented 2 years ago

How come detekt is working properly and CI doesnt fail without this plugin?

mrmans0n commented 2 years ago

This is a custom plugin that has configuration to be added in detekt.yml. If the detekt gradle plugin is running through a module and finds this in detekt.yml, without seeing a plugin that can handle it, that's when you see this error. It's a mechanism Detekt has to detect misconfigurations in the build when using custom plugins.

It means that there is at least 1 place (maybe more, but at least 1) where detekt sees your config but doesn't have detektPlugins("com.twitter.compose.rules:detekt:$twitterComposeVersion") and it needs it.

From what you pasted here I cannot tell you exactly where it's wrong, but the error you are seeing is because of what I mentioned 😅

ege-ah commented 2 years ago

thanks for the response but still cannot understand why detektPlugins("io.gitlab.arturbosch.detekt:detekt-formatting:$detektVersion")

works but not twittterCompose plugin, they are both in detekt.gradle which is applied in build.gradle (app)

mrmans0n commented 2 years ago

As it's a rule they themselves maintain, the tooling provided out of the box contains generating the formatting defaults, so the proper config should already be there everywhere it's necessary (at least it used to anyway). They also include a default value in their resources/ (which I guess it's something we could do as well if it's open for everyone! will make a note to look into that if it helps)

I'm not super keen on providing a default for everything though because it kind of hides everything you can configure. The content emitters and the composition local allowlists are things I'd love people to set up in almost every situation, so adding a default fallback might lead to unintended situations like some modules not properly configured missing that part of the custom config and not failing to run with that error you saw 😬

So we'll have to think about it and see the pros/cons before moving forward with that 😅

alvindizon commented 1 year ago

I encountered this same error. Can this be used together with io.gitlab.arturbosch.detekt:detekt-formatting?

mrmans0n commented 1 year ago

Use the fork at https://github.com/mrmans0n/compose-rules instead. It shouldn't be a problem there, plus all active development of this project moved there.