diffplug / diffplug/spotless

Using editorConfigOverride in kotlinGradle ktlint removes its default values, changing behavior

Open
#2,226 0 comments 0 reactions 0 assignees View on GitHub
bug-unconfirmed
Dominant language
Java
Stars
5.6k
Forks
559
Avg merge
1d 13h
Merged PRs (30d)
34

Description

When you use `editorConfigOverride` with map that has at least 1 entry, for example with arbitrary key that doesn't exist:
```gradle.kts
spotless {
kotlinGradle {
target("*.gradle.kts")
ktlint("1.3.1").editorConfigOverride(
mapOf(
"abc" to "abc",
),
)
}
}
```

the default behavior changes. For example, when I fail the `no-consecutive-comments` rule by having this in `build.gradle.kts`:
```gradle.kts
/** Deps */
// Dep1
```

after adding the map with 1 element, `./gradlew spotlessApply` will no longer display the error, and will successfully format the file.
```
> Task :spotlessApply

BUILD SUCCESSFUL in 220ms
6 actionable tasks: 3 executed, 3 up-to-date
15:25:53: Execution finished 'spotlessApply'.
```

With empty map, it finishes with error:
```
org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':spotlessKotlinGradle'.
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.lambda$executeIfValid$1(ExecuteActionsTaskExecuter.java:130)
...
Caused by: java.lang.AssertionError: Error on line: 20, column: 5
rule: standard:no-consecutive-comments
an EOL comment may not be preceded by a KDoc. Reversed order is allowed though when separated by a newline.
at com.diffplug.spotless.glue.ktlint.compat.KtLintCompatReporting.report(KtLintCompatReporting.java:23)
at com.diffplug.spotless.glue.ktlint.compat.KtLintCompat1Dot0Dot0Adapter$FormatterCallback.invoke(KtLintCompat1Dot0Dot0Adapter.java:77)
at com.diffplug.spotless.glue.ktlint.compat.KtLintCompat1Dot0Dot0Adapter$FormatterCallback.invoke(KtLintCompat1Dot0Dot0Adapter.java:72)
at com.pinterest.ktlint.rule.engine.internal.CodeFormatter.format(CodeFormatter.kt:31)
at com.pinterest.ktlint.rule.engine.api.KtLintRuleEngine.format(KtLintRuleEngine.kt:116)
...
```

Versions:
Gradle 8.9
id("com.diffplug.spotless") version "7.0.0.BETA1"
Windows 10

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.