Search code examples
gradlegradle-kotlin-dsleditorconfig

Disable ktlint rules with ktlint-gradle version 12.0.2


I upgraded the ktlint-gradle plugin to version 12.0.2 and now it does not respect the settings in my modules' build.gradle where I previously disabled some rules like that:

ktlint {
    ktlint.setDisabledRules(["package-name, max_line_length"])
}

I also tried using a .editorconfig file but this on does not allow all the options I need. Disabling max_line_lenth did work there but I dont have the option for package-name.

Screenshot of IDE warning when trying to disable ktlint rule.

In the projects build.gradle I have the ktlint-gradle dependency in the buildscript and for allprojects I apply the ktlint-gradle plugin.

buildscript {
    ...
    dependencies {
        classpath 'com.android.tools.build:gradle:8.1.4'
        classpath "org.jlleitschuh.gradle:ktlint-gradle:12.0.2" // https://github.com/JLLeitschuh/ktlint-gradle/releases  
        ...
  }
}

allprojects {
    ...
    apply plugin: "org.jlleitschuh.gradle.ktlint"
}

Solution

  • Ok I got it, I used the wrong rule naming in the .editorconfig file, need to use the ktlint_standard_rule-name format.

    https://pinterest.github.io/ktlint/latest/rules/standard/

    for example: ktlint_standard_discouraged-comment-location = disabled

    The IDE (Android Studio) still does not recognize these properties then but while running ktlintcheck it evaluates the editorconfig file correctly.

    thanks to wakingrufus on github for answering this question.