Fix Detekt Naming convention findings (28 issues)
Part of the post-#7020 Detekt static analysis cleanup.
Scope
Fix the following Detekt findings and remove their <ID> entries from app/detekt-baseline.xml:
VariableNaming(12 findings)MemberNameEqualsClassName(5 findings)FunctionNaming(4 findings)FunctionParameterNaming(4 findings)TopLevelPropertyNaming(2 findings)MatchingDeclarationName(1 finding)
Steps
- Delete the matching
<ID>...lines fromapp/detekt-baseline.xml. - Run
./gradlew :app:detektto see the exact file and line locations of each violation. - Fix the violations in code. Rename identifiers to follow Kotlin camelCase/PascalCase conventions (be careful not to rename fields serialized by Gson/Retrofit unless annotated with
@SerializedName). - Manually check that the changes are correct, sensible, and do not break the logic. Keeping some exceptions might make sense sometimes, in that case add a comment explaining why.
- Run
./gradlew :app:ktlintCheck :app:detekt testBetaDebugUnitTestand verify all checks pass. - Create a pull request with these changes.
@nicolas-raoul can i work on this ?
Hi @nicolas-raoul,
Detekt's FunctionNaming rule flags Compose functions like CategoryItem and CategoryItemPreview because they use UpperCamelCase , i.e. what the naming convention for composable functions is.
Would you prefer individual suppressions or configuring Detekt to ignore @Composable functions? I think the configuration approach would be more maintainable for future Compose functions.
What are your thoughts?
Good catch @devendrachoudharycodes!
Yes, configuring Detekt to ignore @Composable functions is definitely the better and more maintainable approach (as recommended by the Detekt Compose setup guide).
Please add a detekt.yml configuration file (e.g. app/detekt.yml or config/detekt/detekt.yml) wired up via config.setFrom(...) in app/build.gradle.kts (keeping buildUponDefaultConfig = true), with:
naming:
FunctionNaming:
ignoreAnnotated: ['Composable']
If you find other relevant rules in the article above, can you also add them too? Thanks!
Hi @nicolas-raoul,
Issue #7051 was automatically closed when PR #7173 merged. Could you please reopen #7051?
My PR #7173 description included "Fixes #7051", which auto-closed the issue, but there are still a few remaining findings from the issue scope that I am submitting in follow-up PRs:
- FunctionParameterNaming (4 findings) — PR submitted
- TopLevelPropertyNaming (2 findings in
Monuments.kt) — next PR - MatchingDeclarationName (1 finding for
Costants.kt) — next PR
Thanks!