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

Check Hash Directive more strictly inside of lists or arrays #3080

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.4 - 2024-04-16

### Fixed
* Regression: An empty line or comment at the end of a list breaks Stroustrup formatting. [#3079](https://github.com/fsprojects/fantomas/issues/3079)

## 6.3.3 - 2024-04-12

### Fixed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,31 +95,6 @@ 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 ``hash directive before closing list bracket, nested let binding`` () =
formatSourceString
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -736,3 +736,99 @@ let b = // Build an inbound for the specified subnet.
Tags = Map.empty
}
"""

[<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 ``empty line before closing list bracket, 3079`` () =
formatSourceString
"""
let list = [
someItem

]
"""
config
|> prepend newline
|> should
equal
"""
let list = [
someItem

]
"""

[<Test>]
let ``comment before closing list bracket, 3079`` () =
formatSourceString
"""
let list = [
someItem
// comment
]
"""
config
|> prepend newline
|> should
equal
"""
let list = [
someItem
// comment
]
"""

[<Test>]
let ``comment before closing list bracket with hash directive`` () =
formatSourceString
"""
let list = [
someItem
#if something
item1
#else
item2
#endif
// comment
]
"""
config
|> prepend newline
|> should
equal
"""
let list =
[
someItem
#if something
item1
#else
item2
#endif
// comment
]
"""
7 changes: 6 additions & 1 deletion src/Fantomas.Core/Context.fs
Original file line number Diff line number Diff line change
Expand Up @@ -938,7 +938,12 @@ let indentSepNlnUnindentUnlessStroustrup f (e: Expr) (ctx: Context) =
let shouldUseStroustrup =
let isArrayOrListWithHashDirectiveBeforeClosingBracket () =
match e with
| Expr.ArrayOrList node -> Seq.isEmpty node.Closing.ContentBefore
| Expr.ArrayOrList node ->
node.Closing.ContentBefore
|> Seq.forall (fun x ->
match x.Content with
| TriviaContent.Directive _ -> false
| _ -> true)
| _ -> true

isStroustrupStyleExpr ctx.Config e
Expand Down