Kotlin / Kotlin/ktfmt

Preserving user-authored line breaks produces non-deterministic output for equivalent syntax trees

Open
#638 1 comment 0 reactions 0 assignees View on GitHub
formatting-discussions
Dominant language
Kotlin
Stars
1.3k
Forks
116
Avg merge
4d 10h
Merged PRs (30d)
15

Description

While I do agree with the points raised in #547, I'm not a fan of the approach that was ultimately chosen. Preserving user-authored line breaks inside lambdas violates the deterministic premise this formatter was arguably built upon. The most appealing principle for me was that any equivalent input syntax tree would always result in the same formatted output (barring any additional newlines in function bodies). This is not the case anymore, as developers may influence the formatting result in lambdas, which aren't only used for DSLs.

Could this have been approached differently? How about wrapping the outer lambda body to a new line if it contains a nested lambda on the very same line? To be clear, I'm not suggesting that "preserve user-authored line breaks" should be completely removed or replaced - I just don't think it should have been made the default.

Contributor guide

Open the contributing guide

Research direction

Start by reviewing the current behavior discussed in issue #547 and how the formatter handles line breaks inside lambdas. Compare equivalent syntax trees containing nested lambdas, and consider the requested default behavior; done means the formatting result is deterministic while the existing option to preserve user-authored line breaks remains available.

Written by the indexing model from the issue text.

Assessment

Tech stack
kotlin
Domain
tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.