Detekt Setup for Kotlin Code Style Checking

NOVASOLUTIONS.TECHNOLOGY is engaged in the development, support and maintenance of iOS, Android, PWA mobile applications. We have extensive experience and expertise in publishing mobile applications in popular markets like Google Play, App Store, Amazon, AppGallery and others.
Development and support of all types of mobile applications:
Information and entertainment mobile applications
News apps, games, reference guides, online catalogs, weather apps, fitness and health apps, travel apps, educational apps, social networks and messengers, quizzes, blogs and podcasts, forums, aggregators
E-commerce mobile applications
Online stores, B2B apps, marketplaces, online exchanges, cashback services, exchanges, dropshipping platforms, loyalty programs, food and goods delivery, payment systems.
Business process management mobile applications
CRM systems, ERP systems, project management, sales team tools, financial management, production management, logistics and delivery management, HR management, data monitoring systems
Electronic services mobile applications
Classified ads platforms, online schools, online cinemas, electronic service platforms, cashback platforms, video hosting, thematic portals, online booking and scheduling platforms, online trading platforms

These are just some of the types of mobile applications we work with, and each of them may have its own specific features and functionality, tailored to the specific needs and goals of the client.

Showing 1 of 1 servicesAll 1735 services
Detekt Setup for Kotlin Code Style Checking
Simple
~1 business day
FAQ
Our competencies:
Development stages
Latest works
  • image_mobile-applications_feedme_467_0.webp
    Development of a mobile application for FEEDME
    756
  • image_mobile-applications_xoomer_471_0.webp
    Development of a mobile application for XOOMER
    624
  • image_mobile-applications_rhl_428_0.webp
    Development of a mobile application for RHL
    1052
  • image_mobile-applications_zippy_411_0.webp
    Development of a mobile application for ZIPPY
    947
  • image_mobile-applications_affhome_429_0.webp
    Development of a mobile application for Affhome
    862
  • image_mobile-applications_flavors_409_0.webp
    Development of a mobile application for the FLAVORS company
    445

Setting Up Detekt for Kotlin Code Style Checking

Detekt is a static analyzer for Kotlin code. It finds code smells, checks function complexity, detects potentially unsafe code (unsafe !!, magic numbers, empty catch blocks). For Android projects, it works alongside Android Lint — they complement each other: Lint knows Android specifics (incorrect Context usage, memory leaks), Detekt — Kotlin idioms.

Connecting to Gradle

// build.gradle.kts (project level)
plugins {
    id("io.gitlab.arturbosch.detekt") version "1.23.7"
}

detekt {
    config.setFrom(files("$rootDir/detekt.yml"))
    buildUponDefaultConfig = true
    allRules = false
    baseline = file("$rootDir/detekt-baseline.xml")
}

dependencies {
    detektPlugins("io.gitlab.arturbosch.detekt:detekt-formatting:1.23.7")
    detektPlugins("com.twitter.compose.rules:detekt:0.0.26")  // Compose-specific rules
}

detektPlugins("io.gitlab.arturbosch.detekt:detekt-formatting") adds formatting via ktlint under the hood.

detekt.yml Configuration

build:
  maxIssues: 0
  excludeCorrectable: false

complexity:
  LongMethod:
    threshold: 50
  CyclomaticComplexMethod:
    threshold: 15
  LongParameterList:
    threshold: 6
    ignoreDefaultParameters: true
  TooManyFunctions:
    thresholdInFiles: 20
    thresholdInClasses: 15

style:
  MagicNumber:
    ignoreNumbers:
      - '-1'
      - '0'
      - '1'
      - '2'
    ignoreEnums: true
    ignoreConstantDeclaration: true
  UnusedPrivateMember:
    active: true

potential-bugs:
  UnsafeCallOnNullableType:
    active: true
  UnreachableCode:
    active: true

exceptions:
  SwallowedException:
    active: true
  TooGenericExceptionCaught:
    active: true
    exceptionNames:
      - Exception
      - Throwable

Baseline

On existing projects, Detekt finds hundreds of violations. Running with maxIssues: 0 from scratch is unrealistic. Baseline fixes current state:

./gradlew detektBaseline

Creates detekt-baseline.xml with all existing violations. Detekt will complain only about new violations in new code. Baseline is committed to repository, gradually cleaned up during refactoring.

Running in CI

- name: Run Detekt
  run: ./gradlew detekt

- name: Upload Detekt Report
  uses: github/codeql-action/upload-sarif@v3
  if: always()
  with:
    sarif_file: build/reports/detekt/detekt.sarif

SARIF format displays violations directly in GitHub Code Review as annotations. if: always() — upload report even if detekt fails, so we see violations in PR.

Compose-specific Rules

For Jetpack Compose projects add twitter-compose-rules:

detektPlugins("com.twitter.compose.rules:detekt:0.0.26")

Rules check: @Composable functions without @Preview, unstable parameters in @Composable, remember usage without keys where keys are needed. Real issues Android Lint doesn't cover.

Timeline: 1 day. Cost is calculated individually.