Skip to content

Commit 25a9002

Browse files
authored
Check if expression is isArrayOrListWithHashDirectiveBeforeClosingBracket in indentSepNlnUnindentUnlessStroustrup (#3071)
* Check if expression is isArrayOrListWithHashDirectiveBeforeClosingBracket in indentSepNlnUnindentUnlessStroustrup * Add additional test * 6.3.1
1 parent 74fb395 commit 25a9002

File tree

3 files changed

+72
-1
lines changed

3 files changed

+72
-1
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Changelog
22

3+
## 6.3.1 - 2024-03-30
4+
5+
### Fixed
6+
* HashDirective before closing `]`. [#3070](https://github.com/fsprojects/fantomas/issues/3070)
7+
38
## 6.3.0 - 2024-03-15
49

510
### Miscellaneous

src/Fantomas.Core.Tests/Stroustrup/SynBindingFunctionExpressionTests.fs

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,65 @@ let x y = [
9595
]
9696
"""
9797

98+
[<Test>]
99+
let ``hash directive before closing list bracket, 3070`` () =
100+
formatSourceString
101+
"""
102+
let private knownProviders = [
103+
#if !FABLE_COMPILER
104+
(SerilogProvider.isAvailable, SerilogProvider.create)
105+
(MicrosoftExtensionsLoggingProvider.isAvailable, MicrosoftExtensionsLoggingProvider.create)
106+
#endif
107+
]
108+
"""
109+
config
110+
|> prepend newline
111+
|> should
112+
equal
113+
"""
114+
let private knownProviders =
115+
[
116+
#if !FABLE_COMPILER
117+
(SerilogProvider.isAvailable, SerilogProvider.create)
118+
(MicrosoftExtensionsLoggingProvider.isAvailable, MicrosoftExtensionsLoggingProvider.create)
119+
#endif
120+
]
121+
"""
122+
123+
[<Test>]
124+
let ``hash directive before closing list bracket, nested let binding`` () =
125+
formatSourceString
126+
"""
127+
let foo bar =
128+
let tfms = [
129+
#if NET6_0_OR_GREATER
130+
"net6.0"
131+
#endif
132+
#if NET7_0_OR_GREATER
133+
"net7.0"
134+
#endif
135+
]
136+
()
137+
"""
138+
config
139+
|> prepend newline
140+
|> should
141+
equal
142+
"""
143+
let foo bar =
144+
let tfms =
145+
[
146+
#if NET6_0_OR_GREATER
147+
"net6.0"
148+
#endif
149+
#if NET7_0_OR_GREATER
150+
"net7.0"
151+
#endif
152+
]
153+
154+
()
155+
"""
156+
98157
[<Test>]
99158
let ``synbinding function with array`` () =
100159
formatSourceString

src/Fantomas.Core/Context.fs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -936,7 +936,14 @@ let addParenIfAutoNln expr f =
936936

937937
let indentSepNlnUnindentUnlessStroustrup f (e: Expr) (ctx: Context) =
938938
let shouldUseStroustrup =
939-
isStroustrupStyleExpr ctx.Config e && canSafelyUseStroustrup (Expr.Node e) ctx
939+
let isArrayOrListWithHashDirectiveBeforeClosingBracket () =
940+
match e with
941+
| Expr.ArrayOrList node -> Seq.isEmpty node.Closing.ContentBefore
942+
| _ -> true
943+
944+
isStroustrupStyleExpr ctx.Config e
945+
&& canSafelyUseStroustrup (Expr.Node e) ctx
946+
&& isArrayOrListWithHashDirectiveBeforeClosingBracket ()
940947

941948
if shouldUseStroustrup then
942949
f e ctx

0 commit comments

Comments
 (0)