-
Notifications
You must be signed in to change notification settings - Fork 507
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
allow for named blocks #62
Conversation
Hi @aem. Did you mean |
whoops. yes. this is what i get for using vim 😞 |
@aem no worries! :) Thank you for the PR! 🙇♂️ |
@shyiko always, never a fan of people opening issues on my projects without trying to do something about it, figured i'd be a good OSS citizen myself :) |
@aem we might have a problem here. I was about to release a new version of ktlint but decided to check what Intellij formatter does when asked to reformat a block of code containing lambda expression with a label and, alas, a space is inserted between @ and {. fun foo() {
ints.forEach lit@{
if (it == 0) return@lit
print(it)
}
} becomes fun foo() {
ints.forEach lit@ {
if (it == 0) return@lit
print(it)
}
} (example taken from https://kotlinlang.org/docs/reference/returns.html) |
interesting. looks like you're correct and we've been doing this differently in our codebase. i'm happy to update our styleguide to add the space before the brace if you want to back this change out |
@aem 🤝 yeah, I think it's better this way (staying as much IDEA-code-style-compatible as possible). Sorry about all the confusion. |
no worries, should've checked docs/intellij's formatting first |
Kotlin supports named blocks in cases where you want to return early or return from an inner block without returning a function, the syntax is as so:
obviously that's contrived because
return@map
would suffice as well, but our code sometimes requires operations like.map { .map { } }
which meansreturn@method
doesn't work, named blocks are required.