Just Eat Costa Fotiadis Nov 4, 2024

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

Critical Insight

Custom Detekt rules automate code quality enforcement for team-specific patterns, removing the burden from human reviewers and preventing platform-specific bugs before merge.

The article includes the exact code for implementing custom rules and registering them with Detekt's ServiceLoader pattern.

About This Article

Problem

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.

Solution

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.

Impact

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.