You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The rule for whitespace before/after curly braces is most appropriate when curly braces are used for blocks. But this rule is also enforced in other situations, like passing inlined lambda parameters to functions (e.g. associateBy). That means it creates an implicit rule about spacing with function parameters where no rule exists currently.
So something like this would be considered acceptable to ktlint but has obviously inconsistent styling:
val foo = listOf("Foo")
val bar = foo.associateBy( { it.length } , { it } )
val baz = someFunc(1, 42)
(I personally think foo.associateBy( { it.length } , { it } ) is less readable than foo.associateBy({it.length} , {it}))
I propose that this whitespace rule be changed to only apply to block level.
The text was updated successfully, but these errors were encountered:
ktlint tries to adhere to the default IDEA's settings whenever possible (to stay compatible with the Ctrl+Alt+L) and so the expected code style in this case is:
val foo = listOf("Foo")
val bar = foo.associateBy({ it.length }, { it })
val baz = someFunc(1, 42)
foo.associateBy( { it.length } , { it } ) triggers lint errors after } and so it's not going to pass validation (verified locally using ktlint@0.9.2). I would expect a lint error between ( and { but it seems like this case isn't covered (I'll take care of it over the weekend).
I'll keep this ticket open until a new release (with a fix for ( {) is published but other than that it looks like everything is in order.
The rule for whitespace before/after curly braces is most appropriate when curly braces are used for blocks. But this rule is also enforced in other situations, like passing inlined lambda parameters to functions (e.g.
associateBy
). That means it creates an implicit rule about spacing with function parameters where no rule exists currently.So something like this would be considered acceptable to ktlint but has obviously inconsistent styling:
(I personally think
foo.associateBy( { it.length } , { it } )
is less readable thanfoo.associateBy({it.length} , {it})
)I propose that this whitespace rule be changed to only apply to block level.
The text was updated successfully, but these errors were encountered: