Skip to content

Commit 67f6c28

Browse files
committed
Update style for function call with parenthesis around function name. (#2544)
1 parent c99f7b6 commit 67f6c28

File tree

4 files changed

+42
-57
lines changed

4 files changed

+42
-57
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Changelog
22

3+
## Unreleased
4+
5+
### Changed
6+
* Function call with parenthesis around function name. [#2382](https://github.com/fsprojects/fantomas/issues/2382)
7+
38
## [5.1.0-alpha-002] - 2022-09-29
49

510
### Changed

src/Fantomas.Core.Tests/AppTests.fs

Lines changed: 36 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -479,11 +479,10 @@ let ``parenthesis around composed function expression, 1341`` () =
479479
|> should
480480
equal
481481
"""
482-
(f >> g)
483-
(
484-
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb,
485-
c
486-
)
482+
(f >> g) (
483+
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb,
484+
c
485+
)
487486
"""
488487

489488
[<Test>]
@@ -528,11 +527,10 @@ let ``parenthesis around simple function expression`` () =
528527
|> should
529528
equal
530529
"""
531-
(ignore)
532-
(
533-
"Tuuuuuuuuuuuuurn Tuuuuuuuuuuuuurn Tuuuuuuuuuuuuurn Tuuuuuuuuuuuuurn tooooooooooooooooooooooo stooooooooooooooooooooooooone",
534-
42
535-
)
530+
(ignore) (
531+
"Tuuuuuuuuuuuuurn Tuuuuuuuuuuuuurn Tuuuuuuuuuuuuurn Tuuuuuuuuuuuuurn tooooooooooooooooooooooo stooooooooooooooooooooooooone",
532+
42
533+
)
536534
"""
537535

538536
[<Test>]
@@ -547,8 +545,9 @@ let ``parenthesis around simple function expression with single parenthesis argu
547545
|> should
548546
equal
549547
"""
550-
(ignore)
551-
("Tuuuuuuuuuuuuurn tooooooooooooooooooooooo stooooooooooooooooooooooooone")
548+
(ignore) (
549+
"Tuuuuuuuuuuuuurn tooooooooooooooooooooooo stooooooooooooooooooooooooone"
550+
)
552551
"""
553552

554553
[<Test>]
@@ -565,12 +564,11 @@ stooooooooooooooooooooooooone\"\"\")
565564
|> should
566565
equal
567566
"
568-
(ignore)
569-
(
570-
\"\"\"Tuuuuuuuuuuuuurn
567+
(ignore) (
568+
\"\"\"Tuuuuuuuuuuuuurn
571569
tooooooooooooooooooooooo
572570
stooooooooooooooooooooooooone\"\"\"
573-
)
571+
)
574572
"
575573

576574
[<Test>]
@@ -1064,3 +1062,25 @@ printf "%-40s %s" "" (*<--flags*) word
10641062
"""
10651063
printf "%-40s %s" "" (*<--flags*) word
10661064
"""
1065+
1066+
[<Test>]
1067+
let ``function invocation wrapped in parentheses, 2382`` () =
1068+
formatSourceString
1069+
false
1070+
"""
1071+
(ignore)
1072+
(
1073+
"Tuuuuuuuuuuuuurn Tuuuuuuuuuuuuurn Tuuuuuuuuuuuuurn Tuuuuuuuuuuuuurn tooooooooooooooooooooooo stooooooooooooooooooooooooone",
1074+
42
1075+
)
1076+
"""
1077+
config
1078+
|> prepend newline
1079+
|> should
1080+
equal
1081+
"""
1082+
(ignore) (
1083+
"Tuuuuuuuuuuuuurn Tuuuuuuuuuuuuurn Tuuuuuuuuuuuuurn Tuuuuuuuuuuuuurn tooooooooooooooooooooooo stooooooooooooooooooooooooone",
1084+
42
1085+
)
1086+
"""

src/Fantomas.Core/CodePrinter.fs

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1575,16 +1575,6 @@ and genExpr astContext synExpr ctx =
15751575

15761576
fun ctx -> isShortExpression ctx.Config.MaxDotGetExpressionWidth short long ctx
15771577

1578-
// (*) (60. * 1.1515 * 1.609344)
1579-
// function is wrapped in parenthesis
1580-
| AppParenArg (Choice1Of2 (Paren _, _, _, _, _, _) as app)
1581-
| AppParenArg (Choice2Of2 (Paren _, _, _, _, _) as app) ->
1582-
let short = genAppWithParenthesis app astContext
1583-
1584-
let long = genAlternativeAppWithParenthesis app astContext
1585-
1586-
expressionFitsOnRestOfLine short long
1587-
15881578
// path.Replace("../../../", "....")
15891579
| AppSingleParenArg (LongIdentExpr lids as functionOrMethod, px) ->
15901580
let addSpace =
@@ -3109,16 +3099,6 @@ and genMatchBangWith astContext (matchKeyword: range) (matchExpr: SynExpr) (with
31093099
withKeyword
31103100
"with"
31113101

3112-
and genAlternativeAppWithParenthesis app astContext =
3113-
match app with
3114-
| Choice1Of2 t -> genAlternativeAppWithTupledArgument t astContext
3115-
| Choice2Of2 s -> genAlternativeAppWithSingleParenthesisArgument s astContext
3116-
3117-
and genAppWithParenthesis app astContext =
3118-
match app with
3119-
| Choice1Of2 t -> genAppWithTupledArgument t astContext
3120-
| Choice2Of2 s -> genAppWithSingleParenthesisArgument s astContext
3121-
31223102
and collectMultilineItemForSynExpr (astContext: ASTContext) (e: SynExpr) : ColMultilineItem list =
31233103
match e with
31243104
| LetOrUses (bs, e) -> collectMultilineItemForLetOrUses astContext bs (collectMultilineItemForSynExpr astContext e)
@@ -4078,11 +4058,7 @@ and genClause
40784058
+> leadingExpressionIsMultiline
40794059
(optPre (!- " when") sepNone eo (fun e ->
40804060
let short = sepSpace +> genExpr astContext e
4081-
4082-
let long =
4083-
match e with
4084-
| AppParenArg app -> indentSepNlnUnindent (genAlternativeAppWithParenthesis app astContext)
4085-
| e -> indentSepNlnUnindent (genExpr astContext e)
4061+
let long = indentSepNlnUnindent (genExpr astContext e)
40864062

40874063
expressionFitsOnRestOfLine short long))
40884064
(fun isMultiline ctx ->

src/Fantomas.Core/SourceParser.fs

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1725,22 +1725,6 @@ let isSynExprLambdaOrIfThenElse =
17251725
| SynExpr.IfThenElse _ -> true
17261726
| _ -> false
17271727

1728-
let (|AppParenTupleArg|_|) e =
1729-
match e with
1730-
| AppSingleParenArg (a, Paren (lpr, Tuple (ts, tr), rpr, pr)) -> Some(a, lpr, ts, tr, rpr, pr)
1731-
| _ -> None
1732-
1733-
let (|AppParenSingleArg|_|) e =
1734-
match e with
1735-
| AppSingleParenArg (a, Paren (lpr, p, rpr, pr)) -> Some(a, lpr, p, rpr, pr)
1736-
| _ -> None
1737-
1738-
let (|AppParenArg|_|) e =
1739-
match e with
1740-
| AppParenTupleArg t -> Choice1Of2 t |> Some
1741-
| AppParenSingleArg s -> Choice2Of2 s |> Some
1742-
| _ -> None
1743-
17441728
let (|StroustrupStyleExpr|_|) (isStroustrupStyleEnabled: bool) (e: SynExpr) =
17451729
if not isStroustrupStyleEnabled then
17461730
None

0 commit comments

Comments
 (0)