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

pattern matched unions are formatted badly #283

Closed
7sharp9 opened this issue Jul 20, 2018 · 4 comments
Closed

pattern matched unions are formatted badly #283

7sharp9 opened this issue Jul 20, 2018 · 4 comments

Comments

@7sharp9
Copy link
Member

7sharp9 commented Jul 20, 2018

Using sourceTransformer.fs from this repo

let rec multiline synExpr = 
    match synExpr with
    | ConstExpr _
    | NullExpr
    | OptVar _
    | SequentialSimple _ ->
        false

    | ObjExpr _
    | While _
    | For _
    | ForEach _
    | TryWith _
    | TryFinally _
    | Sequentials _
    | IfThenElse _ ->
        true

    | Paren e
    | SingleExpr(_, e)
    | TypedExpr(_, e, _)
    | CompExpr(_, e)
    | ArrayOrListOfSeqExpr(_, e)
    | DesugaredLambda(_, e)
    | Lambda(e, _)
    | TypeApp(e, _)
    | LongIdentSet(_, e)
    | DotGet(e, _)
    | TraitCall(_, _, e) ->
        multiline e
...

is formatted into this:

let rec multiline synExpr =
    match synExpr with
    | ConstExpr _ | NullExpr | OptVar _ | SequentialSimple _ -> false
    | ObjExpr _ | While _ | For _ | ForEach _ | TryWith _ | TryFinally _ | Sequentials _ | IfThenElse _ -> true
    | Paren e | SingleExpr(_, e) | TypedExpr(_, e, _) | CompExpr(_, e) | ArrayOrListOfSeqExpr(_, e) | DesugaredLambda(_, 
                                                                                                                      e) | Lambda(e, 
                                                                                                                                  _) | TypeApp(e, 
                                                                                                                                               _) | LongIdentSet(_, 
                                                                                                                                                                 e) | DotGet(e, 
                                                                                                                                                                             _) | TraitCall(_, 
                                                                                                                                                                                            _, 
                                                                                                                                                                                            e) -> 
        multiline e

Another piece of code in this file:

let (|OneLinerBinding|MultilineBinding|) b =
    match b with
    | LetBinding([], PreXmlDoc [||], _, _, _, _, OneLinerExpr _)
    | DoBinding([], PreXmlDoc [||], OneLinerExpr _)
    | MemberBinding([], PreXmlDoc [||], _, _, _, _, OneLinerExpr _)
    | PropertyBinding([], PreXmlDoc [||], _, _, _, _, OneLinerExpr _) 
    | ExplicitCtor([], PreXmlDoc [||], _, _, OneLinerExpr _, _) -> 
        OneLinerBinding b

    | _ -> MultilineBinding b

Is formatted to this:

let (|OneLinerMemberDefn|MultilineMemberDefn|) md =
    match md with
    | MDOpen _ | MDInherit _ | MDValField _ | MDImplicitCtor _ | MDInterface(_, None) | MDAbstractSlot([], 
                                                                                                       PreXmlDoc [||], _, 
                                                                                                       _, _, _, _, _) | MDImplicitInherit(_, 
                                                                                                                                          OneLinerExpr _, 
                                                                                                                                          _) | MDMember(OneLinerBinding _) | MDAutoProperty([], 
                                                                                                                                                                                            PreXmlDoc [||], 
                                                                                                                                                                                            _, 
                                                                                                                                                                                            _, 
                                                                                                                                                                                            OneLinerExpr _, 
                                                                                                                                                                                            _, 
                                                                                                                                                                                            _, 
                                                                                                                                                                                            _, 
                                                                                                                                                                                            _) | MDLetBindings(_, 
                                                                                                                                                                                                               _, 
                                                                                                                                                                                                               [ OneLinerBinding _ ]) -> 
        OneLinerMemberDefn md
    | _ -> MultilineMemberDefn md

There are multiple issues with indentation and union filed components being moved down a line.

@vasily-kirichenko
Copy link
Contributor

@7sharp9 What about using FormatConfig.PreserveEndOfLine = true? I've tested your first sample and it's not changed at all after formatting.

@7sharp9
Copy link
Member Author

7sharp9 commented Jul 23, 2018

I suppose but thats just disabling the issue

@nojaf
Copy link
Contributor

nojaf commented Nov 20, 2018

Would it be ok to state that every case inside a pattern match should be on a newline?
Style guide says If the expression is short, you can consider using a single line if each subexpression is also simple..

However to me it doesn't seem like the end of the world if we go with an opinionated approach and go with a line anyway. Or does anyone have a good heuristic in mind?

nojaf added a commit to nojaf/fantomas that referenced this issue Jan 16, 2019
nojaf added a commit that referenced this issue Jan 17, 2019
@jindraivanek
Copy link
Contributor

Fixed by #391.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants