Closed LemonNekoGH closed 3 weeks ago
I cannot reproduce the problem with given code sample and .editorconfig
. I am familiar with this specific exception and have made some adjustments in the upcoming release. Did you actually try to reproduce with this code sample, or is it an abstraction of the real code in which you found the problem?
Oh, sorry, I will check my reproduce code again, and I found that other authors of issue used ktlint's API to verify the issue, I will learn to use it.
By the way, my .editorconfig
file contains trim_trailing_whitespace = true
, and VSCode will trim trailing whitespace on file save when this line exists.
Oh, sorry again, I found a mistake in my description, the command ktlint
with option -F
won't produce the exception, but produced by command ktlint
without any options.
I will still learn to how to verify this issue in testing code.
And expected behavior when run ktlint
without any options:
Code.kt:2:15: Trailing space(s) (standard:no-trailing-spaces)
Code.kt:2:16: Unnecessary long whitespace (standard:no-multi-spaces)
I have tried to add these tests to ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/rules/ArgumentListWrappingRuleTest.kt
:
// This test failed with com.pinterest.ktlint.rule.engine.api.KtLintRuleException
@Test
fun `It will throws an exception`() {
val code = """
fun a() {
var a = 10
println(a)
}
""".trimIndent()
argumentListWrappingRuleAssertThat(code)
.hasNoLintViolations()
}
// This test passed.
@Test
fun `It won't throw an exception`() {
val code = """
fun a() {
var a = 10
a = 20
}
""".trimIndent()
argumentListWrappingRuleAssertThat(code)
.hasNoLintViolations()
}
To avoid that trailing spaces are removed, you should use $SPACE
variable to retain them. For example:
@Test
fun `It will throws an exception`() {
val code =
"""
fun a() {
var a = 10$SPACE$SPACE$SPACE$SPACE
println(a)
}
""".trimIndent()
argumentListWrappingRuleAssertThat(code)
.hasNoLintViolations()
}
This test however still succeeds. So, I don't get how you get an exception.
Thank you for your notice, I have replaced space to variable, but exception still appeared.
I have done these steps to add and run test code:
1.2.1
./gradlew
to configure the project../gradlew :ktlint-ruleset-standard:test
I don't know which step is wrong...Or, maybe I lost some steps?
I will try to reproduce on other machine later.
Check out tag 1.2.1
Why checkout the 1.2.1
tag? Just create a new branch from master
as otherwise you will miss all changes that have been added since the 1.2.1
release.
Other things that you can do:
draft
) so that I can have a look at your changes.I use cli version 1.2.1
so I checkout tag 1.2.1
to keep environment identical.
I know my mistake now, if the bug fixed in new commit, this bug report will be meaningless.
Thank you, I will try to reproduce in latest commit.
I didn't reproduce this problem in the latest commit. Thank you for your help. I'm sorry for wasting your time.
I didn't reproduce this problem in the latest commit. Thank you for your help. I'm sorry for wasting your time.
No problem. We both learned something ;-)
Expected Behavior
I use
·
stands for space. Before I usektlint -F
:After:
Observed Behavior
I got an Exception:
If next line does not contains a function call, the exception gone, examples:
Your Environment
.editorconfig
settings[*.{kt,kts}] trim_trailing_whitespace = true ktlint_code_style = android_studio