-
Notifications
You must be signed in to change notification settings - Fork 506
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ArgumentListWrappingRule: fix wrong indentation in if
condition
#929
Conversation
1213350
to
c62023d
Compare
|
||
private fun ASTNode.isOnSameLineAsIfKeyword(): Boolean { | ||
val containerNode = psi.getStrictParentOfType<KtContainerNode>() ?: return false | ||
val ifExpression = containerNode.parent as? KtIfExpression ?: return false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have a feeling that KtIfExpression
is not enough here, we should probably also consider when
and while
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in 74656c3
c62023d
to
74656c3
Compare
|
||
private fun ASTNode.isOnSameLineAsIfKeyword(): Boolean { | ||
val containerNode = psi.getStrictParentOfType<KtContainerNode>() ?: return false | ||
return when (val parent = containerNode.parent) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But what about KtWhenExpression
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a test for when
.
https://github.com/t-kameyama/ktlint/blob/74656c35796b2541335419ba55cc9d5ba2ec54fd/ktlint-ruleset-experimental/src/test/kotlin/com/pinterest/ktlint/ruleset/experimental/ArgumentListWrappingRuleTest.kt#L366-L384
In when
condition, indent size is 4.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But shouldn't it be
when(foo(
i
)
) { ... }
or am I missing something?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IntelliJ formats it as follows:
fun foo(i: Int) = true
fun test(i: Int) {
when (foo(
i
)) {
true -> println(1)
false -> println(2)
}
}
to
fun foo(i: Int) = true
fun test(i: Int) {
when (foo(
i
)) {
true -> println(1)
false -> println(2)
}
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
gotcha, thanks for clarification
Fixes #864
Fixes #854