fsprojects / fantomas

FSharp source code formatter
https://fsprojects.github.io/fantomas
Other
772 stars 194 forks source link

IndentSpaceNum is ignored if PreserveEndOfLine is enable #387

Closed SCullman closed 5 years ago

SCullman commented 5 years ago

Description

IndentSpaceNum is ignored if PreserveEndOfLine is enable

Repro code

http://ratatosk.dynu.net/fantomas/#?code=DYUwLgBAhgJj0QEYQLwQLACgEGolA&config=N4IgkgdgJgphAuBlADgQwMYwHIFcC2IAXACwA0IACqgOYwDqAllPABZEAcADORQE4wBnGLwBuMAKLQA8gDMAMgwgwi8XjhjlEMPA3QB7ADZ6IAQXiSoshUqIzUBoZrSYAQjBl7+J3tXxx4KmoaICgYMG4e-ADChsaB6k5hJjLwwjF4eKjxwaGYyam8Wjr6RhDZ5JCwCFIQACq8AJ6MrLb2jiAASjCesLxSyHAAIjDoBqi8qPAMcYR2DjnOMN56ONDDBgw6BeUhqrrwALJ6sK3zAL5AA

Input:

let add a b = 
 a + b

formats to

let add a b = 
 a + b

expected

let add a b = 
     a + b
nojaf commented 5 years ago

@jindraivanek this is another good example where preserveLineBreaks put in a newline and just guesses what the indentation should be. It does take the IndentSpaceNum setting into account.

nojaf commented 5 years ago

@jindraivanek do you agree with the changes in https://github.com/fsprojects/fantomas/pull/434/commits/676965e6ec196983ab5e5253c1fb94940e31af22? I think we will make a lot of people happy with preserving the newline after an equal sign.

jindraivanek commented 5 years ago

I don't agree with this, I think Fantomas should format into one style regardless newlines in original source code (with exception of keeping blank lines separators).

My general opinion on stuff like this is that Fantomas should do one-liner if possible, otherwise newline+indent if following block will be multiline.

nojaf commented 5 years ago

Ok, I've reverted the changes for now. https://github.com/fsprojects/fantomas/pull/434/commits/32653bc923ef30fd6dacc370ffcef15e0a1ce7a9 People can let us know what they think about this below.

nojaf commented 5 years ago

And if you really want to force the content after the = you can always add a comment after =. F.ex.

let foo = //
    a + b

Maybe that can be a good compromise.

nojaf commented 5 years ago

Discussing further in #449.