Closed mateuszkwiecinski closed 5 days ago
Tnx for reporting.
This problem is present since Ktlint version 1.0.x
:
$ ktlint-1.0.1 --stdin -F
07:59:48.997 [main] INFO com.pinterest.ktlint.cli.internal.KtlintCommandLine - Enable default patterns [**/*.kt, **/*.kts]
class KotlinClass{
private fun hi(){
println("OK")
}
}
class KotlinClass {
private fun hi() {
println("OK")
}
}
It works fine in version 0.50.0
$ ktlint-0.50.0 --stdin -F
08:00:03.120 [main] INFO com.pinterest.ktlint.cli.internal.KtlintCommandLine - Enable default patterns [**/*.kt, **/*.kts]
class KotlinClass{
private fun hi(){
println("OK")
}
}
08:00:20.335 [main] WARN com.pinterest.ktlint.rule.engine.api.KtLintRuleEngine - Format was not able to resolve all violations which (theoretically) can be autocorrected in file <stdin> in 3 consecutive runs of format.
class KotlinClass {
private fun hi() {
println("OK")
}
}
This problem is present since Ktlint version 1.0.x:
Huh, interesting 😅 I started observing this only when upgrading to 1.3.0
, I had an old smoke test which started failing just now - which suggests something recent made the issue more apparent/more easily reproducible? 👀
Maybe it is caused by promoting sone experimental rules to standard. If your smoke test runs with non-experimental only this could explain the issue.
Maybe it is caused by promoting sone experimental rules to standard. If your smoke test runs with non-experimental only this could explain the issue.
After some more investigation, it turns out that the problem is caused by moving the standard:curly-spacing
rule.
Disabling that rule, results in the expected code:
root = true
[*.{kt,kts}]
ktlint_standard = enabled
ktlint_standard_curly-spacing = disabled
results in the expected code:
class KotlinClass {
private fun hi() {
println("OK")
}
}
It is not clear to me why you smoketest did not fail with previous 1.0.x
to 1.2.x
versions. The class-signature
was a experimental rule which is now promoted to non-experimental. The curly-spacing
rule was already non-experimental since first release of ktlint.
Anyways, it is still a bug to be resolved.
Expected Behavior
Running
format
with autoCorrect produces valid codestyleObserved Behavior
Running
check
after successfulformat
failsSteps to Reproduce
Given the following snippet:
runing
ktlint -F
produces:(notice the double spaces before
{
)which then fails on regular ktlint run with
Your Environment
.editorconfig
settings[*] insert_final_newline = true
[*.{kt,kts}] max_line_length = 140 indent_size = 4 ij_kotlin_allow_trailing_comma = true ij_kotlin_allow_trailing_comma_on_call_site = true ktlint_code_style = intellij_idea