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 #2176
  • Loading branch information
janus committed Apr 5, 2022
1 parent 541085a commit 3f2134e
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
39 changes: 39 additions & 0 deletions src/Fantomas.Tests/ComputationExpressionTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2436,3 +2436,42 @@ async {
return model.Prop
}
"""

[<Test>]
let ``Idempotency problem when using lower MaxLineLength than default, 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 _ -> false
| _ -> true

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

0 comments on commit 3f2134e

Please sign in to comment.