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

Add space around dots when negative floats are inside Expr.TripleNumberIndexRange #3106

Merged
merged 1 commit into from
Aug 16, 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.11 - 2024-08-16

### Fixed
* F# Range Operator (\.\.) with negative numbers produces invalid F# code and idempotent. [#3105](https://github.com/fsprojects/fantomas/issues/3105)

## 6.3.10 - 2024-07-12

### Changed
Expand Down
14 changes: 14 additions & 0 deletions src/Fantomas.Core.Tests/ListTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2292,3 +2292,17 @@ let fns =
Functions[Checked false
OnChange(fun _ -> s |> updateSettings)]
"""

[<Test>]
let ``negative numbers in range operator, 3105`` () =
formatSourceString
"""
[|-24.0 .. -1.0 .. -30.0|]
"""
config
|> prepend newline
|> should
equal
"""
[| -24.0 .. -1.0 .. -30.0 |]
"""
13 changes: 11 additions & 2 deletions src/Fantomas.Core/CodePrinter.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1546,10 +1546,19 @@ let genExpr (e: Expr) =
|> genNode node
| Expr.IndexRangeWildcard node -> genSingleTextNode node
| Expr.TripleNumberIndexRange node ->
let isNegativeFloat (text: string) =
text.StartsWith("-", StringComparison.Ordinal) && text.Contains(".")

let genDots (before: SingleTextNode) (dots: SingleTextNode) (after: SingleTextNode) =
if not (isNegativeFloat before.Text) && not (isNegativeFloat after.Text) then
genSingleTextNode dots
else
sepSpace +> genSingleTextNode dots +> sepSpace

genSingleTextNode node.Start
+> genSingleTextNode node.StartDots
+> genDots node.Start node.StartDots node.Center
+> genSingleTextNode node.Center
+> genSingleTextNode node.EndDots
+> genDots node.Center node.EndDots node.EndDots
+> genSingleTextNode node.End
|> genNode node
| Expr.IndexRange node ->
Expand Down
Loading