Skip to content

Commit

Permalink
Avoid vanity alignment in base ctor call (#1890)
Browse files Browse the repository at this point in the history
* Avoid vanity alignment in base ctor call

fixes #1442

* Update unit test to conform with the others.

Co-authored-by: nojaf <florian.verdonck@outlook.com>
  • Loading branch information
su8898 and nojaf committed Sep 14, 2021
1 parent 95fbd82 commit 2f574b6
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 1 deletion.
31 changes: 31 additions & 0 deletions src/Fantomas.Tests/ClassTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -896,3 +896,34 @@ type MaybeBuilder() =
) : 'U option =
Option.bind binder value
"""

[<Test>]
let ``avoid vanity alignment when calling base constructor, 1442`` () =
formatSourceString
false
"""
type public DerivedExceptionWithLongNaaaaaaaaameException (message: string,
code: int,
originalRequest: string,
originalResponse: string) =
inherit BaseExceptionWithLongNaaaameException(message, code, originalRequest, originalResponse)"""
{ config with MaxLineLength = 80 }
|> prepend newline
|> should
equal
"""
type public DerivedExceptionWithLongNaaaaaaaaameException
(
message: string,
code: int,
originalRequest: string,
originalResponse: string
) =
inherit BaseExceptionWithLongNaaaameException
(
message,
code,
originalRequest,
originalResponse
)
"""
26 changes: 25 additions & 1 deletion src/Fantomas/CodePrinter.fs
Original file line number Diff line number Diff line change
Expand Up @@ -4552,10 +4552,34 @@ and genMemberDefn astContext node =
| MDOpen s -> !-(sprintf "open %s" s)
// What is the role of so
| MDImplicitInherit (t, e, _) ->
let genBasecall =
let shortExpr = genExpr astContext e

let longExpr =
match e with
| Paren (lpr, (Tuple (es, tr)), rpr, pr) ->
indent
+> sepNln
+> indent
+> sepOpenTFor lpr
+> sepNln
+> (col (sepComma +> sepNln) es (genExpr astContext)
|> genTriviaFor SynExpr_Tuple pr)
+> unindent
+> sepNln
+> unindent
+> sepCloseTFor rpr pr
+> unindent
|> genTriviaFor SynExpr_Paren pr
| _ -> genExpr astContext e

expressionFitsOnRestOfLine shortExpr longExpr

!- "inherit "
+> genType astContext false t
+> addSpaceBeforeClassConstructor e
+> genExpr astContext e
+> genBasecall

| MDInherit (t, _) -> !- "inherit " +> genType astContext false t
| MDValField f -> genField astContext "val " f
| MDImplicitCtor (ats, ao, ps, so) ->
Expand Down

0 comments on commit 2f574b6

Please sign in to comment.