Skip to content

Commit

Permalink
EndsWithSingleListApp & EndsWithDualListApp are enable by IsStroustru…
Browse files Browse the repository at this point in the history
…pStyle as well. (#2795)

* EndsWithSingleListApp & EndsWithDualListApp are enbled by both ExperimentalElmish or IsStroustrupStyle.

* Renamed test file.
  • Loading branch information
nojaf committed Mar 17, 2023
1 parent 5a020e3 commit 76be1b9
Show file tree
Hide file tree
Showing 9 changed files with 86 additions and 18 deletions.
7 changes: 4 additions & 3 deletions docs/docs/end-users/Configuration.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -869,9 +869,10 @@ formatCode
(*** include-output ***)

(**
<fantomas-setting name="fsharp_stroustrup_final_list_arguments" orange></fantomas-setting>
<fantomas-setting name="fsharp_experimental_elmish" orange></fantomas-setting>
Applies the Stroustrup style to the final (two) array or list argument(s) in a function application.
Applies the Stroustrup style to the final (two) array or list argument(s) in a function application.
Note that this behaviour is also active when `fsharp_multiline_bracket_style = stroustrup`.
Default = false
*)
Expand Down Expand Up @@ -904,7 +905,7 @@ let singleList =
]
"""
{ FormatConfig.Default with
StroustrupFinalListArguments = true }
ExperimentalElmish = true }
(*** include-output ***)

(**
Expand Down
2 changes: 1 addition & 1 deletion src/Fantomas.Core.Tests/Fantomas.Core.Tests.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@
<Compile Include="Stroustrup\FunctionApplicationSingleListTests.fs" />
<Compile Include="Stroustrup\FunctionApplicationDualListTests.fs" />
<Compile Include="Stroustrup\SynExprAnonRecdStructTests.fs" />
<Compile Include="Stroustrup\FinalListArgumentsTests.fs" />
<Compile Include="Stroustrup\ExperimentalElmishTests.fs" />
<Compile Include="IdentTests.fs" />
<Compile Include="RecordDeclarationsWithXMLDocTests.fs" />
<Compile Include="MaxIfThenShortWidthTests.fs" />
Expand Down
8 changes: 4 additions & 4 deletions src/Fantomas.Core.Tests/NumberOfItemsListOrArrayTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ h [ longValueThatIsALotOfCharactersSoooooLong; longValueThatIsALotOfCharactersSo
"""
{ config with
ArrayOrListMultilineFormatter = NumberOfItems
StroustrupFinalListArguments = true }
ExperimentalElmish = true }
|> prepend newline
|> should
equal
Expand Down Expand Up @@ -206,7 +206,7 @@ h [ longValueThatIsALotOfCharactersSoooooLong; longValueThatIsALotOfCharactersSo
"""
{ config with
ArrayOrListMultilineFormatter = NumberOfItems
StroustrupFinalListArguments = true }
ExperimentalElmish = true }
|> prepend newline
|> should
equal
Expand Down Expand Up @@ -240,7 +240,7 @@ h [ longValueThatIsALotOfCharactersSoooooLong; longValueThatIsALotOfCharactersSo
"""
{ config with
ArrayOrListMultilineFormatter = NumberOfItems
StroustrupFinalListArguments = true }
ExperimentalElmish = true }
|> prepend newline
|> should
equal
Expand Down Expand Up @@ -272,7 +272,7 @@ h [ longValueThatIsALotOfCharactersSoooooLong; longValueThatIsALotOfCharactersSo
"""
{ config with
ArrayOrListMultilineFormatter = NumberOfItems
StroustrupFinalListArguments = true }
ExperimentalElmish = true }
|> prepend newline
|> should
equal
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module Fantomas.Core.Tests.Stroustrup.FinalListArgumentsTests
module Fantomas.Core.Tests.Stroustrup.ExperimentalElmishTests

open NUnit.Framework
open FsUnit
Expand All @@ -7,7 +7,7 @@ open Fantomas.Core

let config =
{ config with
StroustrupFinalListArguments = true }
ExperimentalElmish = true }

[<Test>]
let ``input without attributes`` () =
Expand Down Expand Up @@ -1448,3 +1448,70 @@ let stillCramped =
y
z ]
"""

[<Test>]
let ``fsharp_multiline_bracket_style = stroustrup also applies for applications that ends with list arguments`` () =
formatSourceString
false
"""
type Point =
{
/// Great comment
X: int
Y: int
}
type Model = {
Points: Point list
}
let view dispatch model =
div
[]
[
h1 [] [ str "Some title" ]
ul
[]
[
for p in model.Points do
li [] [ str $"%i{p.X}, %i{p.Y}" ]
]
hr []
]
let alsoStroup = [
// yow
x ; y ; z
]
"""
{ FormatConfig.Default with
MultilineBracketStyle = Stroustrup }
|> prepend newline
|> should
equal
"""
type Point = {
/// Great comment
X: int
Y: int
}
type Model = { Points: Point list }
let view dispatch model =
div [] [
h1 [] [ str "Some title" ]
ul [] [
for p in model.Points do
li [] [ str $"%i{p.X}, %i{p.Y}" ]
]
hr []
]
let alsoStroup = [
// yow
x
y
z
]
"""
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ open Fantomas.Core

let config =
{ config with
StroustrupFinalListArguments = true }
ExperimentalElmish = true }

[<Test>]
let ``two short lists`` () =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ open Fantomas.Core

let config =
{ config with
StroustrupFinalListArguments = true }
ExperimentalElmish = true }

[<Test>]
let ``short function application`` () =
Expand Down
4 changes: 2 additions & 2 deletions src/Fantomas.Core/CodePrinter.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2155,7 +2155,7 @@ let genFunctionNameWithMultilineLids (trailing: Context -> Context) (longIdent:
|> genNode parentNode

let (|EndsWithDualListApp|_|) (config: FormatConfig) (appNode: ExprAppNode) =
if not config.StroustrupFinalListArguments then
if not (config.ExperimentalElmish || config.IsStroustrupStyle) then
None
else
let mutable otherArgs = ListCollector<Expr>()
Expand All @@ -2171,7 +2171,7 @@ let (|EndsWithDualListApp|_|) (config: FormatConfig) (appNode: ExprAppNode) =
visit appNode.Arguments

let (|EndsWithSingleListApp|_|) (config: FormatConfig) (appNode: ExprAppNode) =
if not config.StroustrupFinalListArguments then
if not (config.ExperimentalElmish || config.IsStroustrupStyle) then
None
else
let mutable otherArgs = ListCollector<Expr>()
Expand Down
4 changes: 2 additions & 2 deletions src/Fantomas.Core/FormatConfig.fs
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ type FormatConfig =

[<Category("Convention")>]
[<DisplayName("Applies the Stroustrup style to the final (two) array or list argument(s) in a function application")>]
StroustrupFinalListArguments: bool
ExperimentalElmish: bool

[<Category("Convention")>]
[<DisplayName("Strict mode")>]
Expand Down Expand Up @@ -273,5 +273,5 @@ type FormatConfig =
MultilineBracketStyle = Cramped
KeepMaxNumberOfBlankLines = 100
NewlineBeforeMultilineComputationExpression = true
StroustrupFinalListArguments = false
ExperimentalElmish = false
StrictMode = false }
4 changes: 2 additions & 2 deletions src/Fantomas.Tests/EditorConfigurationTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ let fsharp_stroustrup_final_list_arguments () =
let editorConfig =
"""
[*.fs]
fsharp_stroustrup_final_list_arguments = true
fsharp_experimental_elmish = true
"""

use configFixture =
Expand All @@ -540,4 +540,4 @@ fsharp_stroustrup_final_list_arguments = true

let config = EditorConfig.readConfiguration fsharpFile.FSharpFile

Assert.IsTrue config.StroustrupFinalListArguments
Assert.IsTrue config.ExperimentalElmish

0 comments on commit 76be1b9

Please sign in to comment.