Skip to content

Always insert newline after 'do'#5

Closed
georgefst wants to merge 1 commit intofourmolu:masterfrom
georgefst:master
Closed

Always insert newline after 'do'#5
georgefst wants to merge 1 commit intofourmolu:masterfrom
georgefst:master

Conversation

@georgefst
Copy link
Collaborator

Ugh, this is potentially a one-line fix, except that a handful of tests now fail with idempotence issues...

I guess we've gotta ask how much we care about holding ourselves to the same standards as the main ormolu branch in that respect. The upshot of not caring here would be that users may sometimes have to format twice if they write some really odd code using unusually compact do-notation.

Idempotence is obviously a valuable property, but if we start allowing some configuration, it's going to be increasingly difficult to guarantee in all cases anyway.

Fixes #1 (for good this time)

This fixes a bug where formatting could change the AST, due to four space indentation taking an infix operator past the end column of 'do'.
@georgefst
Copy link
Collaborator Author

Fixes #1 (for good this time)

Well, only if we disable the idempotence tests, obviously.

@parsonsmatt
Copy link
Collaborator

What's the idempotency tests that are failing?

I'm in favor of this. I have occasionally used a form with blockarguments like

map
  do \x -> ...
  do filter p xs

but I would not be upset if a newline happened.

@georgefst
Copy link
Collaborator Author

georgefst commented Jun 14, 2020

Actually, they mostly come down to the fact that ormolu allows braces in single-line dos, but expands them in multi-line. Seeing as this patch makes all dos multi-line, we should be able to just make sure this transformation is always applied on the first pass. I'm currently unsure where the relevant code lives, however.

The one other case then is the bracket-declaration test, where we have:

$( do [d| baz = baz |] )

formatted to:

$(do
      [d|baz = baz|])

then:

$( do
       [d|baz = baz|]
 )

@georgefst
Copy link
Collaborator Author

Closing in favour of #6.

@georgefst georgefst closed this Jun 22, 2020
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.

Fix the test suite

2 participants