Skip to content

Commit

Permalink
Fix idempotency problem with parentheses
Browse files Browse the repository at this point in the history
  • Loading branch information
janus committed Apr 6, 2022
1 parent e784cd6 commit 4ac7755
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 1 deletion.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## [Unreleased]

### Fixed
* Multiline parentheses objectExpression in indexer expression. [#2176](https://github.com/fsprojects/fantomas/issues/2176)

## [4.7.6] - 2022-04-04

### Fixed
Expand Down
39 changes: 39 additions & 0 deletions src/Fantomas.Tests/DotIndexedGetTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,42 @@ a
)
.Meh().[0]
"""

[<Test>]
let ``multiline parentheses objectExpression in indexer expression, 2176`` () =
formatSourceString
false
"""
namespace FSX.Infrastructure
module Unix =
let GrabTheFirstStringBeforeTheFirstColon (lines: seq<string>) =
seq {
for line in lines do
yield
(line.Split(
[| ":" |],
StringSplitOptions.RemoveEmptyEntries
)).[0]
}
"""
{ config with MaxLineLength = 80 }
|> prepend newline
|> should
equal
"""
namespace FSX.Infrastructure
module Unix =
let GrabTheFirstStringBeforeTheFirstColon (lines: seq<string>) =
seq {
for line in lines do
yield
(line.Split(
[| ":" |],
StringSplitOptions.RemoveEmptyEntries
)).[0]
}
"""
7 changes: 6 additions & 1 deletion src/Fantomas/CodePrinter.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2453,7 +2453,12 @@ and genExpr astContext synExpr ctx =

expressionFitsOnRestOfLine (short +> idx) (long +> idx)
| DotIndexedGet (objectExpr, indexArgs) ->
addParenIfAutoNln objectExpr (genExpr astContext)
let isParen =
match objectExpr with
| Paren _ -> true
| _ -> false

ifElse isParen (genExpr astContext objectExpr) (addParenIfAutoNln objectExpr (genExpr astContext))
-- "."
+> sepOpenLFixed
+> genExpr astContext indexArgs
Expand Down

0 comments on commit 4ac7755

Please sign in to comment.