why does ktlint wrap this line? ``` fun <T&g...
# ktlint
c
why does ktlint wrap this line?
Copy code
fun <T> autoClose(wrapped: T, closeFunction: suspend (T) -> Unit): T
I get these 3 errors:
Copy code
> Task :failgood:lintKotlinMain FAILED
/Users/christoph/Projects/failgood/failgood/jvm/src/failgood/dsl/ResourcesDSL.kt:25:23: Lint error > [standard:function-signature] Newline expected after opening parenthesis
/Users/christoph/Projects/failgood/failgood/jvm/src/failgood/dsl/ResourcesDSL.kt:25:35: Lint error > [standard:function-signature] Parameter should start on a newline
/Users/christoph/Projects/failgood/failgood/jvm/src/failgood/dsl/ResourcesDSL.kt:25:69: Lint error > [standard:function-signature] Newline expected before closing parenthesis
the whole line is only 73 chars long.
p
In
ktlint-official
code style, the
function-signature
rules starts wrapping function signatures when the function contains 2 or more parameters regardless of line length. See documentation for configuration
c
ok. one possible improvement would be that the error message could mention that it splits because of the number of parameters.
does the idea formatter also do that or is it recommended in a style guide?
p
No and no.
ktlint_official
goes beyond the style guides and puts more emphasis on consistency of code. By formatting all function signatures in a consistent way, maintenance becomes easier in my opinion. IntelliJ IDEA allows all following in same class/file:
Copy code
fun foo1(a: String, b: String) = "foo"
fun foo2(
    a: String, b: String
) = "foo"
fun foo3(
    a: String,
    b: String
) = "foo"
When working with multiple developers on the same project, or when maintain a long lived project, more and more variations of function signatures are introduced. This rules, restricts the number of variations by imposing stricter rules.
c
i really want uniform formatting for calls but i only want it to wrap when the max line count is reached. how can i do that?
p
112 Views