Skip to content

This repository contains Detekt custom rules and configuration that are based on Deloitte Digital's Kotlin Style Guide.

License

Notifications You must be signed in to change notification settings

DeloitteAU/dd-detekt-rules

Repository files navigation

Detekt custom rules

This repository contains Detekt custom rules and configuration that are based on Deloitte Digital's Kotlin Style Guide.

Adding To Your Project

Make sure to add detekt to your project by applying the following configuration to your app-level build.gradle file:

   plugins {
      id("io.gitlab.arturbosch.detekt").version("1.19.0")
   }

Custom Rules

  1. Copy the jar file (build/libs/dd-detekt-custom-rules-1.0.jar) from this repo.

  2. Go to the project folder of the project where you want to use these custom rules.

  3. In your project folder, create a detekt folder and paste the jar file here.

  4. Navigate to the app-level build.gradle file and add the jar file as dependency:

      dependencies {
          detektPlugins files("$rootDir/detekt/dd-detekt-custom-rules-1.0.jar")
      }
    

Custom Configurations

  1. Copy detekt.yml file from the this repo.

  2. Go to the project folder of the project where you want to use the custom configuration and paste detekt.yml file inside the detekt folder.

  3. Navigate to the app-level build.gradle file and apply the following configuration:

    detekt {
        config = files("$rootDir/detekt/detekt.yml")
    }
    

Detekt Plugin

  1. If you're using the Detekt Plugin on your IDE, go to Preferences > Tools > Detekt.
  2. Set Plugin Jars to the path of your jar file and Configuration Files to the path of your configuration file.

Development Workflow

  1. Create a branch from master and follow this naming convention for your branch: rule/your-custom-rule (E.g. rule/collapsible-if-statements).

  2. From the project folder, create your custom rules inside src/main/kotlin/com/dd/detektcustomrules/rules.

  3. Create a test for your custom rule.

  4. Add the new rule to DDRuleSetProvider.

  5. Open detekt.yml and under custom, add your custom rule and set active to true

    custom:
      MyRule:
        active: true
  6. Commit and push your changes.

  7. Create a Pull Request.

  8. Once your Request is merged, run .gradlew build in your terminal. This should create a jar file.

Best Practices

  • Use the visit method that gets you the closest to the PSI node that you want to check for violation. E.g. If your custom rule checks function names, use visitNamedFunction instead of visitDeclaration.
  • Although we can't avoid traversing through a PSI node, it's always best to keep the number of loops/iteration over a collection as minimal as possible to prevent performance overhead.
  • When calling the report method to report a violation, make sure to use a message that best describes the violation and add some information that will help the developers solve it.
  • When writing tests, make sure all possible scenarios are covered.

Documentation

About

This repository contains Detekt custom rules and configuration that are based on Deloitte Digital's Kotlin Style Guide.

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages