Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Newline after "bang" keywords in computation expressions. #615

Closed
fahrenq opened this issue Dec 31, 2019 · 3 comments · Fixed by #722
Closed

Newline after "bang" keywords in computation expressions. #615

fahrenq opened this issue Dec 31, 2019 · 3 comments · Fixed by #722

Comments

@fahrenq
Copy link

fahrenq commented Dec 31, 2019

Dear maintainers,

Recently updated my Rider which apparently included the new version of Fantomas.

I found this behavior to be very strange:

let f =
  async {
    // Without binding newline after assignment sign preserved, which is expected behavior
    let r =
      match 0 with
      | _ -> ()

    return r
  }

let f2 =
  async {
    // When binding, newline force-removed, which makes the whole expression
    // on the right side to be indented.
    let! r = match 0 with
             | _ -> () |> async.Return

    return r
  }

And it also true for all other "bang" methods in computation expressions (return!, do!, etc.)
Please note it's not exclusive to pattern matching on the right side. I just chose it as an example from my production code, but in fact, any code block gets indented.

You can see more examples here.

While it doesn't look all that scary with examples above, production code has really weird looking indentation that's hard to work with.

I'm ready to contribute and adjust things above by myself, I just want some insights on why was this rule added in the first place? Should we make this behavior optional?

Thanks!

@nojaf
Copy link
Contributor

nojaf commented Dec 31, 2019

Hello @fahrenq, the new version of Fantomas has nothing to do with the way bangs are formatted.
It has been like this since I've picked the project up and as far as I can tell it has no real deliberate reason.

The first thing that comes to mind is that the AST will be different with and without ! and so things might have diverged in the CodePrinter file.

I'm ok with changing the current behaviour as it would be better if it is matching the style without !.
Please add new unit tests in https://github.com/fsprojects/fantomas/blob/master/src/Fantomas.Tests/ComputationExpressionTests.fs to cover all scenarios and check out our contribution guide.

Let me know if you need any further help, I'm also around on the F# Foundation slack if that helps.

@fahrenq
Copy link
Author

fahrenq commented Dec 31, 2019

Thank you very much, I will check it out and will try to resolve it.
Happy New Year :)

@drhumlen
Copy link

drhumlen commented Mar 9, 2020

We have a lot of computation expressions in our codebase, so I see this formatting inconsistency all the time too. +1'ed

I much prefer the formatting of the ordinary lets btw if there's any doubt. The formatting for let! leads to a ton of empty space with some very narrow formatting around column ~100 which is really hard to read and looks weird.

Hoping for a fix for this soon 😄

nojaf added a commit to nojaf/fantomas that referenced this issue Mar 13, 2020
nojaf added a commit that referenced this issue Mar 17, 2020
* Use autoIndentNlnByFuture for let bang. Fixes #615

* Apply the same behavior when formatting !and
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 a pull request may close this issue.

3 participants