Skip to content

Commit 06d86ad

Browse files
johnW-retnojaf
andauthored
Fixed unnecessary parentheses in last tuple item (#3082) (#3119)
* Fixed unnecessary parentheses in last tuple item (#3082) * Slight refactor * Add changelog entry --------- Co-authored-by: nojaf <[email protected]>
1 parent be5d577 commit 06d86ad

File tree

4 files changed

+25
-3
lines changed

4 files changed

+25
-3
lines changed

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Changelog
22

3+
## 6.3.15 - 2024-09-14
4+
5+
### Fixed
6+
* Non needed parentheses are added around lambda call from tuple/members [#3082](https://github.com/fsprojects/fantomas/issues/3082)
7+
38
## 6.3.14 - 2024-09-14
49

510
### Fixed

src/Fantomas.Core.Tests/OperatorTests.fs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1354,7 +1354,7 @@ fun i -> sprintf "%i" i, fun () -> i
13541354
|> should
13551355
equal
13561356
"""
1357-
(fun i -> sprintf "%i" i, (fun () -> i)) |> List.init foo |> Map.ofList
1357+
(fun i -> sprintf "%i" i, fun () -> i) |> List.init foo |> Map.ofList
13581358
"""
13591359

13601360
[<Test>]

src/Fantomas.Core.Tests/TupleTests.fs

+14
Original file line numberDiff line numberDiff line change
@@ -551,3 +551,17 @@ let (clReducedValues, // some comment 1
551551
clSecondActualKeys): ClArray<'a> * ClArray<int> * ClArray<int> =
552552
reduce processor DeviceOnly resultLength clOffsets clFirstKeys clSecondKeys clValues
553553
"""
554+
555+
[<Test>]
556+
let ``unneeded parentheses on last tuple item, 3082`` () =
557+
formatSourceString
558+
"""
559+
func ("/health", fun a b -> "")
560+
"""
561+
config
562+
|> prepend newline
563+
|> should
564+
equal
565+
"""
566+
func ("/health", fun a b -> "")
567+
"""

src/Fantomas.Core/CodePrinter.fs

+5-2
Original file line numberDiff line numberDiff line change
@@ -1888,10 +1888,13 @@ let genTupleExpr (node: ExprTupleNode) =
18881888
| _ -> expr
18891889

18901890
let shortExpression =
1891-
col sepNone node.Items (function
1891+
let lastIndex = Array.length node.Children - 1
1892+
1893+
coli sepNone node.Items (fun i c ->
1894+
match c with
18921895
| Choice1Of2 e ->
18931896
match e with
1894-
| IsLambdaOrIfThenElse e -> sepOpenT +> genExpr e +> sepCloseT
1897+
| IsLambdaOrIfThenElse e when i <> lastIndex -> sepOpenT +> genExpr e +> sepCloseT
18951898
| e -> genExpr (wrapInfixAppRhsInParenIfNeeded e)
18961899
| Choice2Of2 comma -> genSingleTextNode comma +> addSpaceIfSpaceAfterComma)
18971900

0 commit comments

Comments
 (0)