Skip to content

Commit

Permalink
Idempotency problem when using lower MaxLineLength than default and f…
Browse files Browse the repository at this point in the history
…antomas needs to split lines

 Fixes fsprojects#2176
  • Loading branch information
janus authored and nojaf committed Apr 6, 2022
1 parent e784cd6 commit 1c4b15c
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
### Fixed
* SRTP or condition disappear when non-generic type is used. [#2168](https://github.com/fsprojects/fantomas/issues/2168)
* Multiline AbstractSlot without constraints introduces newline [#2175](https://github.com/fsprojects/fantomas/issues/2175)
* Multiline parentheses objectExpression in indexer expression, 2176 [#2176](https://github.com/fsprojects/fantomas/issues/2176)

## [4.7.5] - 2022-03-27

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 1c4b15c

Please sign in to comment.