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

Fixed unnecessary parentheses in last tuple item (fsprojects#3082) #3119

Merged
merged 4 commits into from
Sep 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading