Skip to content

Commit

Permalink
Check if expression is isArrayOrListWithHashDirectiveBeforeClosingBra…
Browse files Browse the repository at this point in the history
…cket in indentSepNlnUnindentUnlessStroustrup
  • Loading branch information
nojaf committed Mar 30, 2024
1 parent 74fb395 commit 919491f
Show file tree
Hide file tree
Showing 3 changed files with 38 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
* HashDirective before closing `]`. [#3070](https://github.com/fsprojects/fantomas/issues/3070)

## 6.3.0 - 2024-03-15

### Miscellaneous
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,31 @@ let x y = [
]
"""

[<Test>]
let ``hash directive before closing list bracket, 3070`` () =
formatSourceString
"""
let private knownProviders = [
#if !FABLE_COMPILER
(SerilogProvider.isAvailable, SerilogProvider.create)
(MicrosoftExtensionsLoggingProvider.isAvailable, MicrosoftExtensionsLoggingProvider.create)
#endif
]
"""
config
|> prepend newline
|> should
equal
"""
let private knownProviders =
[
#if !FABLE_COMPILER
(SerilogProvider.isAvailable, SerilogProvider.create)
(MicrosoftExtensionsLoggingProvider.isAvailable, MicrosoftExtensionsLoggingProvider.create)
#endif
]
"""

[<Test>]
let ``synbinding function with array`` () =
formatSourceString
Expand Down
9 changes: 8 additions & 1 deletion src/Fantomas.Core/Context.fs
Original file line number Diff line number Diff line change
Expand Up @@ -936,7 +936,14 @@ let addParenIfAutoNln expr f =

let indentSepNlnUnindentUnlessStroustrup f (e: Expr) (ctx: Context) =
let shouldUseStroustrup =
isStroustrupStyleExpr ctx.Config e && canSafelyUseStroustrup (Expr.Node e) ctx
let isArrayOrListWithHashDirectiveBeforeClosingBracket () =
match e with
| Expr.ArrayOrList node -> Seq.isEmpty node.Closing.ContentBefore
| _ -> true

isStroustrupStyleExpr ctx.Config e
&& canSafelyUseStroustrup (Expr.Node e) ctx
&& isArrayOrListWithHashDirectiveBeforeClosingBracket ()

if shouldUseStroustrup then
f e ctx
Expand Down

0 comments on commit 919491f

Please sign in to comment.