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

Indentation on lambda's closing brace #479

Closed
bethcutler opened this issue Jun 10, 2019 · 2 comments · Fixed by #508
Closed

Indentation on lambda's closing brace #479

bethcutler opened this issue Jun 10, 2019 · 2 comments · Fixed by #508
Labels

Comments

@bethcutler
Copy link
Contributor

What's the correct way to format this?

foo.func {
  param1, param2 ->
    doSomething()
    doSomething2()
}

Intellij formats it as this:

foo.func {
  param1, param2 ->
  doSomething()
  doSomething2()
}

But ktlint expects this:

foo.func {
  param1, param2 ->
    doSomething()
    doSomething2()
  }

The solution is a bit more obvious when the params can fit on the same line as the opening brace:

foo.func { param1, param2 ->
  doSomething()
  doSomething2()
}
@shashachu
Copy link
Contributor

Hmm... I don't really know. The IntelliJ and the ktlint format both seem a little bit wrong.

@shashachu
Copy link
Contributor

shashachu commented Jul 3, 2019

@bethcutler I think IntelliJ is right:

For curly braces, put the opening brace in the end of the line where the construct begins, and the closing brace on a separate line aligned horizontally with the opening construct.

It looks like the bug is that ktlint is increasing the indent due to the arrow in the lambda. From what I can see, IntelliJ never does. It does increase the indent for arrows inside when statements, though.

@shashachu shashachu added the bug label Jul 3, 2019
shashachu added a commit to shashachu/ktlint that referenced this issue Jul 3, 2019
shashachu added a commit that referenced this issue Jul 5, 2019
* Fixing bug with extra indentation after lambda arrow

Fixes #479

* Adding tests
sowmyav24 pushed a commit to sowmyav24/ktlint that referenced this issue Jul 18, 2019
* Fixing bug with extra indentation after lambda arrow

Fixes pinterest#479

* Adding tests
orchestr7 pushed a commit to saveourtool/diktat that referenced this issue Jun 29, 2020
* Fixing bug with extra indentation after lambda arrow

Fixes pinterest/ktlint#479

* Adding tests
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants