Skip to content

Commit

Permalink
Consider tuple as short branch in KeepIndentInBranch setting. (#1810)
Browse files Browse the repository at this point in the history
  • Loading branch information
nojaf committed Jul 3, 2021
1 parent a388f39 commit 7f3731b
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 1 deletion.
90 changes: 90 additions & 0 deletions src/Fantomas.Tests/KeepIndentInBranchTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1830,3 +1830,93 @@ let private parseModel (modelSrc: string) : Result<MyReturnType, string list> =
else
Error validationErrors
"""

[<Test>]
let ``tuple is consider as short branch, 1800`` () =
formatSourceString
false
"""
let nextModel, objectsRemoved =
List.fold
(fun acc item ->
match entityInCurrentModel with
| None ->
// look it's a tuple
nextModel, objectsRemoved
| Some subjectToRemove ->
let a = 5
let b = 6
someFunctionApp a b |> ignore
acc)
state
[]
"""
{ config with
MultiLineLambdaClosingNewline = true
KeepIndentInBranch = true }
|> prepend newline
|> should
equal
"""
let nextModel, objectsRemoved =
List.fold
(fun acc item ->
match entityInCurrentModel with
| None ->
// look it's a tuple
nextModel, objectsRemoved
| Some subjectToRemove ->
let a = 5
let b = 6
someFunctionApp a b |> ignore
acc
)
state
[]
"""

[<Test>]
let ``parenthesis tuple is consider as short branch`` () =
formatSourceString
false
"""
let nextModel, objectsRemoved =
List.fold
(fun acc item ->
match entityInCurrentModel with
| None ->
// look it's a tuple but wrapped in parenthesis
(nextModel, objectsRemoved)
| Some subjectToRemove ->
let a = 5
let b = 6
someFunctionApp a b |> ignore
acc)
state
[]
"""
{ config with
MultiLineLambdaClosingNewline = true
KeepIndentInBranch = true }
|> prepend newline
|> should
equal
"""
let nextModel, objectsRemoved =
List.fold
(fun acc item ->
match entityInCurrentModel with
| None ->
// look it's a tuple but wrapped in parenthesis
(nextModel, objectsRemoved)
| Some subjectToRemove ->
let a = 5
let b = 6
someFunctionApp a b |> ignore
acc
)
state
[]
"""
4 changes: 3 additions & 1 deletion src/Fantomas/SourceParser.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1730,7 +1730,9 @@ let private shouldNotIndentBranch e es =
match e with
| SimpleExpr _
| Sequential (_, _, true)
| App _ -> true
| App _
| Tuple _
| Paren (_, Tuple _, _, _) -> true
| _ -> false

let isLongElseBranch e =
Expand Down

0 comments on commit 7f3731b

Please sign in to comment.