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

Fix 2151, index syntax without dot on array of arrays #2163

Merged
merged 2 commits into from
Mar 24, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

### Fixed
* DotGet in quotation should be further indented. [#2154](https://github.com/fsprojects/fantomas/issues/2154)
* Reformatting multiple array index operators (v6 style) adds spaces that are invalid [#2151](https://github.com/fsprojects/fantomas/issues/2151)

## [4.7.3] - 2022-03-12

Expand Down
21 changes: 21 additions & 0 deletions src/Fantomas.Tests/IndexSyntaxTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,27 @@ arr[0, 2, 3, 4] <- 2
arr[0, 2, 3, 4]
"""

[<Test>]
let ``index syntax without dot on array of arrays, 2151`` () =
formatSourceString
false
"""
let a = Array.create 10 -1
let b = Array.create 10 a

printfn "%d -> %d" a[0] (b[0][0])
"""
config
|> prepend newline
|> should
equal
"""
let a = Array.create 10 -1
let b = Array.create 10 a

printfn "%d -> %d" a[0] (b[0][0])
"""

[<Test>]
let ``only add spaces when expressions are atomic`` () =
formatSourceString
Expand Down
5 changes: 3 additions & 2 deletions src/Fantomas/SourceParser.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1761,8 +1761,9 @@ let (|ElmishReactWithChildren|_|) (e: SynExpr) =
| SynExpr.App (_,
false,
SynExpr.App (_, false, OptVar ident, (ArrayOrList _ as attributes), _),
ArrayOrList (sr, isArray, children, er, _),
_) -> Some(ident, attributes, (isArray, sr, children, er))
ArrayOrList (sr, isArray, children, er, r),
_) when (not (RangeHelpers.isAdjacentTo attributes.Range r)) ->
nojaf marked this conversation as resolved.
Show resolved Hide resolved
Some(ident, attributes, (isArray, sr, children, er))
| _ -> None

let isIfThenElseWithYieldReturn e =
Expand Down