Skip to content
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

Merged
merged 2 commits into from
Sep 29, 2020

Conversation

t-kameyama
Copy link
Contributor

Fixes #864
Fixes #854

@t-kameyama t-kameyama force-pushed the issue_864 branch 2 times, most recently from 1213350 to c62023d Compare September 28, 2020 03:45

private fun ASTNode.isOnSameLineAsIfKeyword(): Boolean {
val containerNode = psi.getStrictParentOfType<KtContainerNode>() ?: return false
val ifExpression = containerNode.parent as? KtIfExpression ?: return false
Copy link
Collaborator

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 74656c3


private fun ASTNode.isOnSameLineAsIfKeyword(): Boolean {
val containerNode = psi.getStrictParentOfType<KtContainerNode>() ?: return false
return when (val parent = containerNode.parent) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But what about KtWhenExpression?

Copy link
Contributor Author

@t-kameyama t-kameyama Sep 28, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator

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?

Copy link
Contributor Author

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

Copy link
Collaborator

@romtsn romtsn Sep 29, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gotcha, thanks for clarification

@romtsn romtsn merged commit 5671af8 into pinterest:master Sep 29, 2020
@t-kameyama t-kameyama deleted the issue_864 branch September 29, 2020 07:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants