Skip to content

Setup detekt static analysis plugin#1123

Merged
LikeTheSalad merged 2 commits into
open-telemetry:mainfrom
embrace-io:fractalwrench/use-detekt
Aug 4, 2025
Merged

Setup detekt static analysis plugin#1123
LikeTheSalad merged 2 commits into
open-telemetry:mainfrom
embrace-io:fractalwrench/use-detekt

Conversation

@fractalwrench
Copy link
Copy Markdown
Member

Goal

Detekt is a static analysis program for Kotlin that is pretty commonly used on Android. I've set it up on any module that is using the Android library conventions gradle script as I think it'd be beneficial for catching potential problems and maintaining consistent formatting style in Kotlin code.

Analysis can be triggered via ./gradlew detekt or ./gradlew check. I've suppressed all existing warnings in the project by using a baseline file, and any subsequent warnings would fail the build. The baseline can be added to by ./gradlew detektBaseline which will regenerate the file.

If any of the default rules in the baseline seem annoying or too much of a false positive I'm pretty happy to update the PR, as specific rules can be configured or even disabled. I went with as close to the default as possible, but FWIW here are the modifications we found useful at Embrace: https://github.com/embrace-io/embrace-android-sdk/blob/main/config/detekt/detekt.yml

@fractalwrench fractalwrench requested a review from a team as a code owner August 1, 2025 13:23
@fractalwrench fractalwrench force-pushed the fractalwrench/use-detekt branch from bfb2e93 to 2acf446 Compare August 1, 2025 13:50
Copy link
Copy Markdown
Contributor

@LikeTheSalad LikeTheSalad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left a couple of comments, though I like the overall idea as it can provide similar benefits we get with errorprone, but for Kotlin. I'm not yet aware if this config is "too strict" or not, as I haven't worked with it yet, although I guess we can make adjustments later if needed. Thank you!

Comment thread buildSrc/src/main/kotlin/otel.android-library-conventions.gradle.kts Outdated
Comment thread buildSrc/src/main/kotlin/otel.android-library-conventions.gradle.kts Outdated
@LikeTheSalad LikeTheSalad merged commit c75dc3d into open-telemetry:main Aug 4, 2025
6 checks passed
Copy link
Copy Markdown
Contributor

@breedx-splk breedx-splk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the addition. One small downside I notice is the sudden appearance of a lot of xml in this project. :)

@bidetofevil
Copy link
Copy Markdown
Contributor

The idea is that we should fix or configure the ruleset so there are no XML files, but I'd take those rather than have the issues that those bring up.

Disabling rules that we don't care about enough to fix is always a good option

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants