Skip to content

Commit

Permalink
Fixed unnecessary parentheses in last tuple item (#3082) (#3119)
Browse files Browse the repository at this point in the history
* Fixed unnecessary parentheses in last tuple item (#3082)

* Slight refactor

* Add changelog entry

---------

Co-authored-by: nojaf <[email protected]>
  • Loading branch information
johnW-ret and nojaf authored Sep 14, 2024
1 parent be5d577 commit 06d86ad
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 3 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## 6.3.15 - 2024-09-14

### Fixed
* Non needed parentheses are added around lambda call from tuple/members [#3082](https://github.com/fsprojects/fantomas/issues/3082)

## 6.3.14 - 2024-09-14

### Fixed
Expand Down
2 changes: 1 addition & 1 deletion src/Fantomas.Core.Tests/OperatorTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1354,7 +1354,7 @@ fun i -> sprintf "%i" i, fun () -> i
|> should
equal
"""
(fun i -> sprintf "%i" i, (fun () -> i)) |> List.init foo |> Map.ofList
(fun i -> sprintf "%i" i, fun () -> i) |> List.init foo |> Map.ofList
"""

[<Test>]
Expand Down
14 changes: 14 additions & 0 deletions src/Fantomas.Core.Tests/TupleTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -551,3 +551,17 @@ let (clReducedValues, // some comment 1
clSecondActualKeys): ClArray<'a> * ClArray<int> * ClArray<int> =
reduce processor DeviceOnly resultLength clOffsets clFirstKeys clSecondKeys clValues
"""

[<Test>]
let ``unneeded parentheses on last tuple item, 3082`` () =
formatSourceString
"""
func ("/health", fun a b -> "")
"""
config
|> prepend newline
|> should
equal
"""
func ("/health", fun a b -> "")
"""
7 changes: 5 additions & 2 deletions src/Fantomas.Core/CodePrinter.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1888,10 +1888,13 @@ let genTupleExpr (node: ExprTupleNode) =
| _ -> expr

let shortExpression =
col sepNone node.Items (function
let lastIndex = Array.length node.Children - 1

coli sepNone node.Items (fun i c ->
match c with
| Choice1Of2 e ->
match e with
| IsLambdaOrIfThenElse e -> sepOpenT +> genExpr e +> sepCloseT
| IsLambdaOrIfThenElse e when i <> lastIndex -> sepOpenT +> genExpr e +> sepCloseT
| e -> genExpr (wrapInfixAppRhsInParenIfNeeded e)
| Choice2Of2 comma -> genSingleTextNode comma +> addSpaceIfSpaceAfterComma)

Expand Down

0 comments on commit 06d86ad

Please sign in to comment.