Search code examples
kotlineditorconfigktlint

Ktlint ignores .editorconfig


I wanted to try out Kotlin and ktlint and I was happy to see that it supports tab indentation via the editorconfig file (since this PR). Sadly it doesn't seem to work for me. I haven't used editorconfig before, I might have made some simple mistake.

My .editorconfig in the root folder:

indent_style = tab

My gradle file:

import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

val koinVersion: String by project
val junitVersion: String by project

plugins {
    application
    kotlin("jvm") version "1.4.30"
    id("org.jlleitschuh.gradle.ktlint") version "10.0.0"
}

group = "me.me"
version = "1.0-SNAPSHOT"

application {
    mainClassName = "de.me.bot.translate.MainKt"
}

repositories {
    mavenCentral()
    jcenter()
}

dependencies {
    implementation("com.sksamuel.hoplite:hoplite-core:+")
    implementation("org.koin:koin-core:$koinVersion")

    testImplementation("org.koin:koin-test:$koinVersion")
    testImplementation(kotlin("test-junit5"))
    testImplementation("org.junit.jupiter:junit-jupiter-api:$junitVersion")

    testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:$junitVersion")
}

tasks.test {
    useJUnitPlatform()
}

tasks.withType<KotlinCompile>() {
    kotlinOptions.jvmTarget = "13"
}

However running gradle ktlintCheck still throws exceptions because of unexpected tab characters. I don't understand why. I ran it with --debug, but it didn't give me any useful information.

Here is my project: github.com


Solution

  • EditorConfig specification states:

    With the exception of the root key, all pairs MUST be located under a section to take effect.

    So your .editorconfig file should be:

    root = true
    
    [*.{kt,kts}]
    indent_style = tab