I'm a ktfmt noob. Is this really the way fluent ch...
# ktfmt
u
I'm a ktfmt noob. Is this really the way fluent chains are supposed to look like? Even if the chain is longer than the max width?
g
I wouldn't think so... Did you run ktfmt from the IDEA plugin or from gradle or from the CLI?
u
gradle plugin
g
Did you set the
maxWidth
in the
ktfmt
block to a value or is it still at the default? In my experience, respecting the width never has been an issue, but fluent chains that fit on one line will remain there iirc. If you want to have breaks inserted, you could always use the empty comment trick (add linebreaks manually, insert an empty comment after the first part of the call chain). Quite ugly, but better than nothing
u
yes i overrode it to.120
g
Well, then the output is what I'd expect (your line has a width of 118)
👍 1
It's been a while since I set ktfmt up for my current project, but I think code like this was a reason for me to limit the width to 100 (or basically leave it at the default)
u
you sure? the vertical line is intellij highlighting the 120 mark. atleast thats what i think (im a 120 user always)
g
Pretty sure:
💯 1
My guideline is at 100 btw, so you might wanna check your settings on IntelliJ 😉
u
you're right, damn
btw about compose, isn't there maybe a update coming? I'm not sure I like the singlelining in UI, where the nesting implies .. nesting I assume singlelining of lambdas is not configurable, right?
g
I'm not working with Compose (or even Android) atm. As suggested, you can always force a linebreak if you want by adding an empty comment before the linebreak you want to have preserved. A point regarding configurability: In general, I regard lack of configurability as a feature. It saves you from discussion about mostly meaningless details. If your defaults are reasonable, you'll get used to a code style. Unfortunately, Kotlin does not really have an official formatter like e.g. Dart has (with
dartfmt
).
ktfmt
is closest to
dartfmt
for me (deterministic results based on input tokens), that's why I chose it. Not having to think about formatting anymore can be quite liberating
u
I do agree about the single config, but I don't think this is a good rule for UI where nesting is semantics, not just a stylistic choice
App { SelectableCard { Button { Text }}}}
is obviously less clear; so not sure if this holds up in 2025 where UIs are in kotlin
n
I must say I'm on the same page here @ursus, the problem is finding time to work on this. It would also be beneficial for
.kts
files as well where we have plenty of lambdas where we don't want this kind of inlining most of the time.
Thanks for creating the issue to track that BTW 🙂
👍 1
u
yea +1 for DSLs; thats probably the underlying issue, not just UIs
👍 1