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
val input ="abc"val example =try {
input.fakeFunction(a ="aaaaaaaaaaaaaaa", b ="bbbbbbbbbbb", c ="cccccccccccc").map { strng -> strng.replace("a", "b") }
} catch (error:Exception) {
println()
}
ktfmt will wrap it as follows:
val input ="abc"val example =try {
input.fakeFunction(a ="aaaaaaaaaaaaaaa", b ="bbbbbbbbbbb", c ="cccccccccccc").map { strng
->
strng.replace("a", "b")
}
} catch (error:Exception) {
println()
}
The fact that it doesn’t simply put the whole .map { ... } on a new line is odd to me. And the -> on its own line is also unusual. This issue can be reproduced in the online ktfmtplayground by setting style to kotlinlang and line length to 100.
The text was updated successfully, but these errors were encountered:
@nreid260 would it be possible to implement something similar to what rustfmt does? E.g. with the following Rust,
fnmain(){let vec = vec![1,2,3,4,5];let result = vec.iter().map(|x| x + 2 + 1 + 2).map(|x| x + 1 + 3 + 123 + 654654 + 1);let result:Vec<i32> = result.collect();println!("{:?}",result);}
It formats it to
fnmain(){let vec = vec![1,2,3,4,5];let result = vec
.iter().map(|x| x + 2 + 1 + 2).map(|x| x + 1 + 3 + 123 + 654654 + 1);let result:Vec<i32> = result.collect();println!("{:?}",result);}
What if ktfmt is updated to do the following: if there is a chain of function calls which goes over the max line length, then each function call should be put onto a new line. Only after each function call is put onto a new line does it attempt to do further wrapping if necessary.
Your description is what ktfmt does most of the time. The behaviour you're seeing was specially added to improve the "feel" of code like:
return foo.bar("something")?.block {
// Some long lambda
}
I recall there being some common example where preceding method calls were important, but perhaps the block-like behaviour could be limited to free calls and calls on simple names.
If I have the following code,
ktfmt
will wrap it as follows:The fact that it doesn’t simply put the whole
.map { ... }
on a new line is odd to me. And the->
on its own line is also unusual. This issue can be reproduced in the onlinektfmt
playground by setting style tokotlinlang
and line length to 100.The text was updated successfully, but these errors were encountered: