Extending Detekt for Android Code Quality
Article Summary
Costa Fotiadis from Just Eat Takeaway shows how custom Detekt rules caught edge-to-edge violations before they hit production. No more relying on reviewers to remember Android 15's breaking changes.
Just Eat Takeaway's Android team extended Detekt (Kotlin's static analysis tool) with custom rules tailored to their codebase. They built a separate module that enforces team-specific patterns and catches issues that generic linters miss, all integrated into their CI pipeline with automated PR comments.
Key Takeaways
- Custom rule enforces enableEdgeToEdge() calls for Android 15 compatibility
- Prevents banned APIs like GlobalScope and android.util.Log automatically
- Uses danger-kotlin to post violation comments directly on pull requests
- Unit tests allow quick iteration on arcane Detekt APIs
Custom Detekt rules automate code quality enforcement for team-specific patterns, removing the burden from human reviewers and preventing platform-specific bugs before merge.
About This Article
Just Eat Takeaway's Android team needed to enforce coding patterns that went beyond what generic linting could catch. They wanted to prevent android.util.Log usage, block GlobalScope, and enforce custom Dagger2 annotations across their codebase.
Costa Fotiadis's team built a detekt-custom-rules library module using RuleSetProvider and the ServiceLoader pattern. They registered the custom rules through a detekt.yml configuration file and applied them via the detektPlugins syntax in their build system.
The custom rules run in CI with danger-kotlin to post automated violation comments on pull requests. This removed the need for manual review to catch predictable code quality issues before code gets merged.