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

Unexpected newline before "{" for lambda expression assignments #409

Closed
schmist opened this issue May 1, 2019 · 7 comments
Closed

Unexpected newline before "{" for lambda expression assignments #409

schmist opened this issue May 1, 2019 · 7 comments

Comments

@schmist
Copy link

schmist commented May 1, 2019

Since version 0.32.0 lambda expression assignments like:

private fun foo(): () -> Int =
    { 42 }

trigger a Unexpected newline before "{".

For the shown example, there is no need to have a line break after =, but if the first line is getting too long, a line break makes sense.

Is this intended behavior?

@shashachu
Copy link
Contributor

shashachu commented May 6, 2019

Both the Google and Jetbrains styleguides say no linebreaks before opening curly braces so this is by-design.

https://developer.android.com/kotlin/style-guide#braces
https://kotlinlang.org/docs/reference/coding-conventions.html#formatting

@igorwojda
Copy link

igorwojda commented May 15, 2019

I think this should be reopened

If line is to long Android Studio will format below code and move { ... to new line

fun validDateRule(): ValidationRule<LocalDate?> =
        { date: LocalDate?, _: EventType -> ValidationResult(date != null) }

and ktlint complains Unexpected newline before "{"

@shashachu
Copy link
Contributor

In my opinion, for these one-off exceptions, it's better to use a ktlint-disable comment to suppress it rather than complicate the rule. But open to feedback from others.

@shashachu shashachu reopened this May 15, 2019
@igorwojda
Copy link

igorwojda commented May 29, 2019

In my project, this violation happens 6 times already.
I think indent before { should be allowed if the previous line ends with = character

image
(no ktlint violation)

Format code (using Android Studio default settings)

image
(ktlint violation)

@igorwojda
Copy link

We should really prioritize this as this rule contradicts default AS formatting

@pgreze
Copy link

pgreze commented Nov 12, 2019

+1 I believe @igorwojda example with validDateRule is a good example 👍

@Tapchicoma
Copy link
Collaborator

Related - #637

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

No branches or pull requests

5 participants