Skip to content

Conversation

@bioball
Copy link
Member

@bioball bioball commented Oct 29, 2025

If an operator chain or method call is multiline, keep those newlines in the formatted output.

Help preserve code like:

foo
  |> (it) -> it + 2
  |> (it) -> it / 2

@bioball bioball marked this pull request as ready for review October 29, 2025 21:32
@bioball bioball force-pushed the respect-line-breaks branch 2 times, most recently from afbf15c to 3cef59b Compare October 30, 2025 06:07
val children = node.children
val sep: (Node, Node) -> FormatNode = { prev, next ->
if (prev.isTerminal(",") && prev.linesBetween(next) > 0) forceSpaceyLine() else spaceOrLine()
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This logic is arbitrary and error prone.
It doesn't work for many different cases or works by chance:

// doesn't multiline
p1 = foo(1
        ,2
        ,3)

// here it does
p2 = foo(1,
        2
        ,3)

// doesn't multiline
p3 = foo(1, 2, 3, it
        .asd)

// works by chance, because we respect newlines after comments
p4 = foo(1, 2, 3, /*foo*/
        it)

I think we should go back to the drawing board with this logic.
Maybe remove this part and merge the rest. This could be a subsequent PR.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's intentional that p3 doesn't multiline; per our formatting rules, it\n.bar should be single-lined, and this formatting rule shouldn't interfere with that. I also think it's fine that p4 works.

It's definitely a problem that p1 doesn't multiline; just pushed up a commit to fix that. Also, this also fixes an issue where this doesn't multiline:

1 +
  2

@bioball bioball force-pushed the respect-line-breaks branch from 51d6fe4 to c706685 Compare October 31, 2025 17:54
If an operator chain or method call is multiline, keep those newlines
in the formatted output.

Help preserve code like:

```
foo
  |> (it) -> it + 2
  |> (it) -> it / 2
```
@bioball bioball force-pushed the respect-line-breaks branch from c706685 to 298126e Compare October 31, 2025 20:20
@bioball bioball merged commit d8adb28 into apple:main Nov 3, 2025
4 checks passed
@bioball bioball deleted the respect-line-breaks branch November 3, 2025 05:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants