android / compose-samples

Official Jetpack Compose samples.
https://developer.android.com/jetpack/compose
Apache License 2.0
19.84k stars 4.71k forks source link

Upgrade to new spotless version for all samples #1443

Closed riggaroo closed 1 month ago

riggaroo commented 1 month ago

Upgrade to version 1.3.1 of Ktlint, migrating to the standard rules where applicable. This change is the result of running the new rules - its large since it hasn't been run in a long time unfortunately.

Two rules disabled as per Compose conventions: Composable function names, allow them to start with lowercase Allowing PascalCase naming on constants

dturner commented 1 month ago

Following discussion, I thought it'd be helpful to describe the process for identifying and disabling a ktlint rule which is run through spotless.

To disable a ktlint rule, you need to know 2 things:

The problem is that running gradlew spotlessCheck doesn't provide the names of the rules which are being violated (reported here, here and here). To find that out, you need to run ktlint directly (brew install ktlint).

I ran it on the JetLagged source using ktlint "app/src/**/*.kt" after rolling back some of the formatting changes in this PR. This gives you the names of any rule violations. In my case, one of the rules being violated was standard:multiline-expression-wrapping meaning it's in the standard ruleset and is named multiline-expression-wrapping.

To disable it, add an entry to .editorconfig using the following format ktlint_<ruleset>_<rulename> = disabled so in this case it's ktlint_standard_multiline-expression-wrapping = disabled.

BUT WAIT. Spotless is problematic because it doesn't work with configuration caching so you may find that it doesn't pick up the changes in .editorconfig (as reported here). To solve this use --no-configuration-cache and --no-daemon flags, so: ./gradlew spotlessCheck --no-daemon --no-configuration-cache.