【问题标题】:Ktlint ignores .editorconfigKtlint 忽略 .editorconfig
【发布时间】:2021-05-30 13:38:02
【问题描述】:

我想试用 Kotlin 和 ktlint,我很高兴看到它通过 editorconfig 文件支持制表符缩进(自 this PR 起)。可悲的是,它似乎对我不起作用。我之前没用过editorconfig,可能是我犯了一些简单的错误。

我在根文件夹中的.editorconfig

indent_style = tab

我的 gradle 文件:

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"
}

但是,由于意外的制表符,运行 gradle ktlintCheck 仍然会引发异常。我不明白为什么。我用 --debug 运行它,但它没有给我任何有用的信息。

Here is my project: github.com

【问题讨论】:

  • 我认为你的项目被隐藏了
  • @YuriSchimke 我真笨,谢谢。现在可见

标签: kotlin editorconfig ktlint


【解决方案1】:

EditorConfig 规范states:

除根密钥外,所有对都必须位于一个部分下才能生效。

所以你的 .editorconfig 文件应该是:

root = true

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

【讨论】:

  • 好的,谢谢。我以前从未使用过 editorconfig,而 Intellij 似乎只是接受它。我一直在寻找 ktlint 中的错误。
猜你喜欢
  • 2020-04-03
  • 2020-07-10
  • 2015-07-30
  • 2022-06-15
  • 2020-06-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多