diff --git a/CHANGELOG.md b/CHANGELOG.md index c1a1417a99..92263ae2c9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## [8.0.0-alpha-002] - 2025-12-15 + +### Changed + +- Breaking: change default of MultilineBracketStyle from Cramped to Aligned. [#3200](https://github.com/fsprojects/fantomas/issues/3200) + ## [8.0.0-alpha-001] - 2025-12-12 ### Changed diff --git a/docs/docs/end-users/Configuration.fsx b/docs/docs/end-users/Configuration.fsx index ce889bc147..ff163ce25c 100644 --- a/docs/docs/end-users/Configuration.fsx +++ b/docs/docs/end-users/Configuration.fsx @@ -734,8 +734,8 @@ fsharp_max_function_binding_width = 10 ### fsharp_multiline_bracket_style -`Cramped` The default way in F# to format brackets. -`Aligned` Alternative way of formatting records, arrays and lists. This will align the braces at the same column level. +`Cramped` Alternative way in F# to format brackets. +`Aligned` The default way of formatting records, arrays and lists. This will align the braces at the same column level. `Stroustrup` Allow for easier reordering of members and keeping the code succinct. *) diff --git a/docs/docs/end-users/UpgradeGuide.md b/docs/docs/end-users/UpgradeGuide.md index c0767fff20..c5d8b9718f 100644 --- a/docs/docs/end-users/UpgradeGuide.md +++ b/docs/docs/end-users/UpgradeGuide.md @@ -82,7 +82,7 @@ fsharp_experimental_stroustrup_style = true ### Miscellaneous - The namespace in [Fantomas.FCS](https://www.nuget.org/packages/Fantomas.FCS) changed from `FSharp.Compiler` to `Fantomas.FCS`. -## v7 alpha +## v7 ### console application - Target framework is now `net8.0`. @@ -90,4 +90,9 @@ fsharp_experimental_stroustrup_style = true ### .editorconfig - `fsharp_max_dot_get_expression_width` was removed. +## v8 alpha + +### .editorconfig +- The default setting for `fsharp_multiline_bracket_style` is now `aligned`, to restore the previous behaviour use `fsharp_multiline_bracket_style = cramped`. + diff --git a/src/Fantomas.Core.Tests/AppTests.fs b/src/Fantomas.Core.Tests/AppTests.fs index 48889da97b..0000e16549 100644 --- a/src/Fantomas.Core.Tests/AppTests.fs +++ b/src/Fantomas.Core.Tests/AppTests.fs @@ -3,6 +3,7 @@ module Fantomas.Core.Tests.AppTests open NUnit.Framework open FsUnit open Fantomas.Core.Tests.TestHelpers +open Fantomas.Core // the current behavior results in a compile error since the |> is merged to the last line [] @@ -648,7 +649,9 @@ let ``string interpolation should not affect multiline function applications, 17 mkMember $"this.Try{memberName}" None [ mkSynAttribute "CustomOperation" (mkSynExprConstString $"try{memberName}") ] [ parameters ] (objectStateExpr body) """ - { config with IndentSize = 2 } + { config with + IndentSize = 2 + MultilineBracketStyle = Cramped } |> prepend newline |> should equal @@ -1130,7 +1133,9 @@ let ``multiline application wrapped in parentheses that equal the indent_size, 2 """ ((Combo { e1 = "Making this long so it goes on a new line new line new line new line making it long so it goes on a new line new line" })) """ - { config with IndentSize = 2 } + { config with + IndentSize = 2 + MultilineBracketStyle = Cramped } |> prepend newline |> should equal diff --git a/src/Fantomas.Core.Tests/AttributeTests.fs b/src/Fantomas.Core.Tests/AttributeTests.fs index 309a9d42af..bc13ad5e82 100644 --- a/src/Fantomas.Core.Tests/AttributeTests.fs +++ b/src/Fantomas.Core.Tests/AttributeTests.fs @@ -4,6 +4,7 @@ open NUnit.Framework open FsUnit open Fantomas.Core.Tests.TestHelpers +open Fantomas.Core [] let ``should keep the attribute on top of the function`` () = @@ -120,7 +121,8 @@ let ``type params`` () = """ let genericSumUnits ( x : float<'u>) (y: float<'u>) = x + y type vector3D<[] 'u> = { x : float<'u>; y : float<'u>; z : float<'u>}""" - config + { config with + MultilineBracketStyle = Cramped } |> prepend newline |> should equal @@ -179,7 +181,8 @@ type Foo = { [] Bar:string } """ - config + { config with + MultilineBracketStyle = Cramped } |> prepend newline |> should equal @@ -250,7 +253,8 @@ let ``comments before attributes should be added correctly, issue 422`` () = Phone : string Verified : bool } """ - config + { config with + MultilineBracketStyle = Cramped } |> prepend newline |> should equal @@ -542,7 +546,8 @@ type Commenter = DisplayName: string } """ - config + { config with + MultilineBracketStyle = Cramped } |> prepend newline |> should equal @@ -658,7 +663,8 @@ type RoleAdminImportController(akkaService: AkkaService) = """ { config with MaxInfixOperatorExpression = 40 - MaxArrayOrListWidth = 40 } + MaxArrayOrListWidth = 40 + MultilineBracketStyle = Cramped } |> prepend newline |> should equal @@ -885,7 +891,8 @@ module Foo = () """ { config with - NewlineBetweenTypeDefinitionAndMembers = false } + NewlineBetweenTypeDefinitionAndMembers = false + MultilineBracketStyle = Cramped } |> prepend newline |> should equal diff --git a/src/Fantomas.Core.Tests/BlankLinesAroundNestedMultilineExpressions.fs b/src/Fantomas.Core.Tests/BlankLinesAroundNestedMultilineExpressions.fs index 37a0227312..f925c02800 100644 --- a/src/Fantomas.Core.Tests/BlankLinesAroundNestedMultilineExpressions.fs +++ b/src/Fantomas.Core.Tests/BlankLinesAroundNestedMultilineExpressions.fs @@ -3,6 +3,7 @@ module Fantomas.Core.Tests.BlankLinesAroundNestedMultilineExpressions open NUnit.Framework open FsUnit open Fantomas.Core.Tests.TestHelpers +open Fantomas.Core let config = { config with @@ -147,7 +148,9 @@ type MNIST(path:string, ?urls:seq, ?train:bool, ?transform:Tensor->Tenso if File.Exists(filesProcessed.[3]) then target <- dsharp.load(filesProcessed.[3]) else target <- MNIST.LoadMNISTLabels(files.[3]); dsharp.save(target, filesProcessed.[3]) data, target """ - { config with MaxLineLength = 100 } + { config with + MaxLineLength = 100 + MultilineBracketStyle = Cramped } |> prepend newline |> should equal diff --git a/src/Fantomas.Core.Tests/CastTests.fs b/src/Fantomas.Core.Tests/CastTests.fs index 0a85d9aad1..c5fc9f7d4e 100644 --- a/src/Fantomas.Core.Tests/CastTests.fs +++ b/src/Fantomas.Core.Tests/CastTests.fs @@ -3,6 +3,7 @@ module Fantomas.Core.Tests.CastTests open NUnit.Framework open FsUnit open Fantomas.Core.Tests.TestHelpers +open Fantomas.Core [] let ``multiline downcast expression, `` () = @@ -145,7 +146,8 @@ module Foo = """ { config with SpaceBeforeColon = true - SpaceBeforeSemicolon = true } + SpaceBeforeSemicolon = true + MultilineBracketStyle = Cramped } |> prepend newline |> should equal @@ -180,7 +182,8 @@ module Foo = """ { config with SpaceBeforeColon = true - SpaceBeforeSemicolon = true } + SpaceBeforeSemicolon = true + MultilineBracketStyle = Cramped } |> prepend newline |> should equal diff --git a/src/Fantomas.Core.Tests/ClassTests.fs b/src/Fantomas.Core.Tests/ClassTests.fs index 7a9f9a39f9..71c395eba9 100644 --- a/src/Fantomas.Core.Tests/ClassTests.fs +++ b/src/Fantomas.Core.Tests/ClassTests.fs @@ -4,6 +4,7 @@ open NUnit.Framework open FsUnit open Fantomas.Core.Tests.TestHelpers +open Fantomas.Core [] let ``class signatures`` () = @@ -511,7 +512,8 @@ module Logging = let SetQuartzLogger l = LogProvider.SetCurrentLogProvider(l) """ { config with - MaxFunctionBindingWidth = 80 } + MaxFunctionBindingWidth = 80 + MultilineBracketStyle = Cramped } |> prepend newline |> should equal @@ -1141,7 +1143,8 @@ let ``trivia before and keyword in SynMemberDefn.GetSet, 2372`` () = override this.``type``: string = "fakerun" } """ - config + { config with + MultilineBracketStyle = Cramped } |> prepend newline |> should equal @@ -1170,7 +1173,8 @@ type [] Terminal = abstract onKey: IEvent<{| key: string; domEvent: KeyboardEvent |}> with get, set abstract onLineFeed: IEvent with get, set """ - config + { config with + MultilineBracketStyle = Cramped } |> prepend newline |> should equal diff --git a/src/Fantomas.Core.Tests/ColMultilineItemTests.fs b/src/Fantomas.Core.Tests/ColMultilineItemTests.fs index bb0d8bb72f..94775f459a 100644 --- a/src/Fantomas.Core.Tests/ColMultilineItemTests.fs +++ b/src/Fantomas.Core.Tests/ColMultilineItemTests.fs @@ -215,7 +215,8 @@ asyncResult { return Ok job } """ - config + { config with + MultilineBracketStyle = Cramped } |> prepend newline |> should equal diff --git a/src/Fantomas.Core.Tests/CommentTests.fs b/src/Fantomas.Core.Tests/CommentTests.fs index 55e064344f..b8a4f07823 100644 --- a/src/Fantomas.Core.Tests/CommentTests.fs +++ b/src/Fantomas.Core.Tests/CommentTests.fs @@ -116,7 +116,8 @@ type Model = Name: string // bar Street: string } """ - config + { config with + MultilineBracketStyle = Cramped } |> prepend newline |> should equal @@ -312,7 +313,8 @@ let a = // bar B = 7 } """ - config + { config with + MultilineBracketStyle = Cramped } |> prepend newline |> should equal @@ -333,7 +335,8 @@ let a = // bar B = 7 } """ - config + { config with + MultilineBracketStyle = Cramped } |> prepend newline |> should equal @@ -356,7 +359,8 @@ let a = B = 7 } """ { config with - SpaceAroundDelimiter = false } + SpaceAroundDelimiter = false + MultilineBracketStyle = Cramped } |> prepend newline |> should equal @@ -586,7 +590,8 @@ module TriviaModule = (* ending with block comment *) """ - config + { config with + MultilineBracketStyle = Cramped } |> prepend newline |> should equal @@ -826,7 +831,8 @@ type substring = #endif """ { config with - MaxInfixOperatorExpression = 60 } + MaxInfixOperatorExpression = 60 + MultilineBracketStyle = Cramped } |> should equal """(* @@ -1274,7 +1280,8 @@ type T = ; // Delay in ms since it entered the queue delay : float } """ - config + { config with + MultilineBracketStyle = Cramped } |> prepend newline |> should equal @@ -1631,7 +1638,8 @@ type TorDirectory = } } """ - config + { config with + MultilineBracketStyle = Cramped } |> prepend newline |> should equal @@ -2330,7 +2338,8 @@ type ExprFolder<'State> = targetIntercept: ('State -> Expr -> 'State) -> 'State -> DecisionTreeTarget -> 'State option tmethodIntercept: ('State -> Expr -> 'State) -> 'State -> ObjExprMethod -> 'State option } """ - config + { config with + MultilineBracketStyle = Cramped } |> prepend newline |> should equal @@ -2447,7 +2456,8 @@ let Anonymous = {| FontFamily = 700 // font-weight FontSize = 48. |} // font-weight """ - config + { config with + MultilineBracketStyle = Cramped } |> prepend newline |> should equal diff --git a/src/Fantomas.Core.Tests/CompilerDirectivesTests.fs b/src/Fantomas.Core.Tests/CompilerDirectivesTests.fs index 7d646d7176..34aa3ebb28 100644 --- a/src/Fantomas.Core.Tests/CompilerDirectivesTests.fs +++ b/src/Fantomas.Core.Tests/CompilerDirectivesTests.fs @@ -3,6 +3,7 @@ module Fantomas.Core.Tests.CompilerDirectiveTests open NUnit.Framework open FsUnit open Fantomas.Core.Tests.TestHelpers +open Fantomas.Core [] let ``should keep compiler directives`` () = @@ -1828,7 +1829,8 @@ let config = { #endif } """ - config + { config with + MultilineBracketStyle = Cramped } |> prepend newline |> should equal @@ -1862,7 +1864,8 @@ let config = { #endif } """ - config + { config with + MultilineBracketStyle = Cramped } |> prepend newline |> should equal @@ -1895,7 +1898,8 @@ let config = { #endif } """ - config + { config with + MultilineBracketStyle = Cramped } |> prepend newline |> should equal @@ -2148,7 +2152,8 @@ let getDefaultProxyFor = | None -> getDefault()) """ { config with - MaxIfThenElseShortWidth = 50 } + MaxIfThenElseShortWidth = 50 + MultilineBracketStyle = Cramped } |> prepend newline |> should equal @@ -2488,7 +2493,8 @@ let inputFileFlagsFsiBase (_tcConfigB: TcConfigBuilder) = List.empty #endif """ - config + { config with + MultilineBracketStyle = Cramped } |> prepend newline |> should equal @@ -2530,7 +2536,8 @@ let ``define before opening bracket of array, 1597`` () = System.Environment.SetEnvironmentVariable(varName, value) } """ - config + { config with + MultilineBracketStyle = Cramped } |> prepend newline |> should equal diff --git a/src/Fantomas.Core.Tests/ComputationExpressionTests.fs b/src/Fantomas.Core.Tests/ComputationExpressionTests.fs index 44e744d353..6689203fc8 100644 --- a/src/Fantomas.Core.Tests/ComputationExpressionTests.fs +++ b/src/Fantomas.Core.Tests/ComputationExpressionTests.fs @@ -1335,7 +1335,8 @@ let loginHandler = return! text "Successfully logged in" next ctx } """ - config + { config with + MultilineBracketStyle = Cramped } |> prepend newline |> should equal @@ -2042,7 +2043,8 @@ let password = (fun s -> s.Length >= 6) } """ - config + { config with + MultilineBracketStyle = Cramped } |> prepend newline |> should equal @@ -2234,7 +2236,8 @@ let ``keep new line before match bang, 1313`` () = |> AsyncResult.foldResult id (fun _ -> [])) "Incomplete pattern matches on this expression. For example" """ - config + { config with + MultilineBracketStyle = Cramped } |> prepend newline |> should equal @@ -2297,7 +2300,8 @@ aggregateResult { } """ { config with - MaxInfixOperatorExpression = 40 } + MaxInfixOperatorExpression = 40 + MultilineBracketStyle = Cramped } |> prepend newline |> should equal @@ -2420,7 +2424,8 @@ let ``trivia after computation expression, 2466`` () = EndLine = e.EndLine } } (*[/omit]*) """ - config + { config with + MultilineBracketStyle = Cramped } |> prepend newline |> should equal diff --git a/src/Fantomas.Core.Tests/ConstructorTests.fs b/src/Fantomas.Core.Tests/ConstructorTests.fs index 7473c3bf84..530c61bddf 100644 --- a/src/Fantomas.Core.Tests/ConstructorTests.fs +++ b/src/Fantomas.Core.Tests/ConstructorTests.fs @@ -3,6 +3,7 @@ module Fantomas.Core.Tests.ConstructorTests open NUnit.Framework open FsUnit open Fantomas.Core.Tests.TestHelpers +open Fantomas.Core [] let ``multiple base constructors in record, 2111`` () = @@ -20,7 +21,9 @@ type UnhandledWebException = new(info: SerializationInfo, context: StreamingContext) = { inherit Exception(info, context) } """ - { config with MaxLineLength = 100 } + { config with + MaxLineLength = 100 + MultilineBracketStyle = Cramped } |> prepend newline |> should equal @@ -183,7 +186,8 @@ type CreateBuildingViewModel = then vm.program <- p """ - config + { config with + MultilineBracketStyle = Cramped } |> prepend newline |> should equal diff --git a/src/Fantomas.Core.Tests/CrampedMultilineBracketStyleTests.fs b/src/Fantomas.Core.Tests/CrampedMultilineBracketStyleTests.fs index 443ba0b1c5..33bd62c056 100644 --- a/src/Fantomas.Core.Tests/CrampedMultilineBracketStyleTests.fs +++ b/src/Fantomas.Core.Tests/CrampedMultilineBracketStyleTests.fs @@ -5,6 +5,10 @@ open FsUnit open Fantomas.Core.Tests.TestHelpers open Fantomas.Core +let config = + { config with + MultilineBracketStyle = Cramped } + [] let ``record declaration`` () = formatSourceString "type AParameters = { a : int }" config diff --git a/src/Fantomas.Core.Tests/DallasTests.fs b/src/Fantomas.Core.Tests/DallasTests.fs index cabce2838e..793e6d22b8 100644 --- a/src/Fantomas.Core.Tests/DallasTests.fs +++ b/src/Fantomas.Core.Tests/DallasTests.fs @@ -794,7 +794,8 @@ let ``anon record expr`` () = b |} """ - config + { config with + MultilineBracketStyle = Cramped } |> prepend newline |> should equal @@ -812,7 +813,8 @@ let ``obj expr`` () = interface Meh with member x.Blur = () } """ - config + { config with + MultilineBracketStyle = Cramped } |> prepend newline |> should equal @@ -1490,7 +1492,8 @@ let ``multiple always break infix operators`` () = [ IdentifierOrDot.KnownDot(stn "." dot) IdentifierOrDot.Ident(mkSynIdent ident) ]) """ - config + { config with + MultilineBracketStyle = Cramped } |> prepend newline |> should equal diff --git a/src/Fantomas.Core.Tests/DotGetTests.fs b/src/Fantomas.Core.Tests/DotGetTests.fs index 91e606a955..8177939e72 100644 --- a/src/Fantomas.Core.Tests/DotGetTests.fs +++ b/src/Fantomas.Core.Tests/DotGetTests.fs @@ -776,7 +776,8 @@ let blah = """ { config with SpaceBeforeUppercaseInvocation = true - SpaceBeforeMember = true } + SpaceBeforeMember = true + MultilineBracketStyle = Cramped } |> prepend newline |> should equal diff --git a/src/Fantomas.Core.Tests/DotSetTests.fs b/src/Fantomas.Core.Tests/DotSetTests.fs index 7c562b3b0a..a91aae13d0 100644 --- a/src/Fantomas.Core.Tests/DotSetTests.fs +++ b/src/Fantomas.Core.Tests/DotSetTests.fs @@ -3,6 +3,7 @@ module Fantomas.Core.Tests.DotSetTests open NUnit.Framework open FsUnit open Fantomas.Core.Tests.TestHelpers +open Fantomas.Core [] let ``function application with parentheses should not respect SpaceBeforeUppercaseInvocation`` () = @@ -82,12 +83,8 @@ app().foo <- {| |} """ { config with - SpaceBeforeLowercaseInvocation = true } - |> fun formatted -> - formatSourceString - formatted - { config with - SpaceBeforeLowercaseInvocation = true } + SpaceBeforeLowercaseInvocation = true + MultilineBracketStyle = Cramped } |> prepend newline |> should equal diff --git a/src/Fantomas.Core.Tests/FormatAstTests.fs b/src/Fantomas.Core.Tests/FormatAstTests.fs index ff4c859e2b..452a5bf8c6 100644 --- a/src/Fantomas.Core.Tests/FormatAstTests.fs +++ b/src/Fantomas.Core.Tests/FormatAstTests.fs @@ -12,8 +12,12 @@ let parseAndFormat sourceCode = |> Seq.head |> fst + let config = + { config with + MultilineBracketStyle = Cramped } + let formattedCode = - CodeFormatter.FormatASTAsync(ast, source = sourceCode) + CodeFormatter.FormatASTAsync(ast, source = sourceCode, config = config) |> Async.RunSynchronously |> String.normalizeNewLine |> fun s -> s.TrimEnd('\n') diff --git a/src/Fantomas.Core.Tests/HashDirectiveTests.fs b/src/Fantomas.Core.Tests/HashDirectiveTests.fs index 8e0074e2b3..78f0c686f3 100644 --- a/src/Fantomas.Core.Tests/HashDirectiveTests.fs +++ b/src/Fantomas.Core.Tests/HashDirectiveTests.fs @@ -3,6 +3,7 @@ module Fantomas.Core.Tests.HashDirectiveTests open NUnit.Framework open FsUnit open Fantomas.Core.Tests.TestHelpers +open Fantomas.Core [] let ``should use verbatim strings on some hash directives`` () = @@ -176,7 +177,8 @@ type FSharpTokenizerColorState = | TripleQuoteStringInComment = 14 | InitialState = 0 """ - config + { config with + MultilineBracketStyle = Cramped } |> prepend newline |> should equal diff --git a/src/Fantomas.Core.Tests/IfThenElseTests.fs b/src/Fantomas.Core.Tests/IfThenElseTests.fs index 927db2262b..0a00c9faf6 100644 --- a/src/Fantomas.Core.Tests/IfThenElseTests.fs +++ b/src/Fantomas.Core.Tests/IfThenElseTests.fs @@ -1968,7 +1968,8 @@ let lessonsForm (f:ValidatedForm) dispatch = ] ] """ - config + { config with + MultilineBracketStyle = Cramped } |> prepend newline |> should equal diff --git a/src/Fantomas.Core.Tests/InterfaceTests.fs b/src/Fantomas.Core.Tests/InterfaceTests.fs index 5f651bd6ef..5c7efcca19 100644 --- a/src/Fantomas.Core.Tests/InterfaceTests.fs +++ b/src/Fantomas.Core.Tests/InterfaceTests.fs @@ -3,6 +3,7 @@ module Fantomas.Core.Tests.InterfaceTests open NUnit.Framework open FsUnit open Fantomas.Core.Tests.TestHelpers +open Fantomas.Core [] let ``interfaces and inheritance`` () = @@ -61,7 +62,10 @@ let ``should not add with to interface definitions with no members`` () = [] let ``object expressions`` () = - formatSourceString """let obj1 = { new System.Object() with member x.ToString() = "F#" }""" config + formatSourceString + """let obj1 = { new System.Object() with member x.ToString() = "F#" }""" + { config with + MultilineBracketStyle = Cramped } |> prepend newline |> should equal @@ -82,7 +86,8 @@ let ``object expressions and interfaces`` () = interface IFirst with member this.F() = () member this.G() = () }""" - config + { config with + MultilineBracketStyle = Cramped } |> prepend newline |> should equal @@ -107,7 +112,8 @@ let f () = interface IEnumerable<_> with member x.GetEnumerator() = null }""" { config with - MaxValueBindingWidth = 120 } + MaxValueBindingWidth = 120 + MultilineBracketStyle = Cramped } |> prepend newline |> should equal @@ -473,7 +479,8 @@ let test () = { new IDisposable with override this.Dispose() = dispose somethingElse } """ - config + { config with + MultilineBracketStyle = Cramped } |> prepend newline |> should equal @@ -616,7 +623,8 @@ let ``interface in obj expression, 2604`` () = interface Meh with member x.Blur = () } """ - config + { config with + MultilineBracketStyle = Cramped } |> prepend newline |> should equal @@ -640,7 +648,8 @@ let create () = interface Interface2 with member _.Foo2 s = s } """ - config + { config with + MultilineBracketStyle = Cramped } |> prepend newline |> should equal diff --git a/src/Fantomas.Core.Tests/KeepIndentInBranchTests.fs b/src/Fantomas.Core.Tests/KeepIndentInBranchTests.fs index 9ef21239c1..04fa9821b5 100644 --- a/src/Fantomas.Core.Tests/KeepIndentInBranchTests.fs +++ b/src/Fantomas.Core.Tests/KeepIndentInBranchTests.fs @@ -268,7 +268,8 @@ module Foo = Some 3 } """ - config + { config with + MultilineBracketStyle = Cramped } |> prepend newline |> should equal @@ -323,7 +324,8 @@ module Foo = Some 3 } """ - config + { config with + MultilineBracketStyle = Cramped } |> prepend newline |> should equal @@ -1416,7 +1418,9 @@ let x y = let ipv4 = string result.["ipv4"] None """ - { config with MaxArrayOrListWidth = 40 } + { config with + MaxArrayOrListWidth = 40 + MultilineBracketStyle = Cramped } |> prepend newline |> should equal @@ -1462,7 +1466,9 @@ let x = let ipv4 = string result.["ipv4"] None """ - { config with MaxArrayOrListWidth = 40 } + { config with + MaxArrayOrListWidth = 40 + MultilineBracketStyle = Cramped } |> prepend newline |> should equal diff --git a/src/Fantomas.Core.Tests/LambdaTests.fs b/src/Fantomas.Core.Tests/LambdaTests.fs index f49ff8a9eb..d3ec7b7e1e 100644 --- a/src/Fantomas.Core.Tests/LambdaTests.fs +++ b/src/Fantomas.Core.Tests/LambdaTests.fs @@ -63,7 +63,9 @@ let private badgeSample = exportDefault badgeSample """ - { config with MaxArrayOrListWidth = 40 } + { config with + MaxArrayOrListWidth = 40 + MultilineBracketStyle = Cramped } |> prepend newline |> should equal @@ -127,7 +129,8 @@ Target.create "Clean" (fun _ -> |> List.iter Shell.cleanDir ) """ - config + { config with + MultilineBracketStyle = Cramped } |> prepend newline |> should equal @@ -672,7 +675,8 @@ Decode.map3 (fun aggregateId event commitPayload -> Payload = payload } | None -> None) (Decode.field "aggregate_id" Decode.string) (Decode.field "event" Decode.string) decodePayload """ - config + { config with + MultilineBracketStyle = Cramped } |> prepend newline |> should equal @@ -915,7 +919,8 @@ module Foo = } """ { config with - MaxInfixOperatorExpression = 50 } + MaxInfixOperatorExpression = 50 + MultilineBracketStyle = Cramped } |> prepend newline |> should equal @@ -1067,7 +1072,8 @@ let g = revisionNumber = r processName = pn } -> p, r, pn) """ - config + { config with + MultilineBracketStyle = Cramped } |> prepend newline |> should equal diff --git a/src/Fantomas.Core.Tests/LetBindingTests.fs b/src/Fantomas.Core.Tests/LetBindingTests.fs index 4a4a4e86fc..70bb61dcba 100644 --- a/src/Fantomas.Core.Tests/LetBindingTests.fs +++ b/src/Fantomas.Core.Tests/LetBindingTests.fs @@ -772,7 +772,8 @@ let useEntries month year = (income, expenses) """ - config + { config with + MultilineBracketStyle = Cramped } |> prepend newline |> should equal @@ -929,7 +930,8 @@ let useOverviewPerMonth () = months """ - config + { config with + MultilineBracketStyle = Cramped } |> prepend newline |> should equal @@ -980,7 +982,9 @@ let ``don't add newline before array, 1033`` () = "--noframework" yield! refs |] """ - { config with MaxArrayOrListWidth = 40 } + { config with + MaxArrayOrListWidth = 40 + MultilineBracketStyle = Cramped } |> prepend newline |> should equal @@ -1378,7 +1382,8 @@ printfn "%s" (lookupMonth 12) printfn "%s" (lookupMonth 1) printfn "%s" (lookupMonth 13) // Throws an exception! """ - config + { config with + MultilineBracketStyle = Cramped } |> prepend newline |> should equal @@ -1717,7 +1722,8 @@ type Viewport = longitude: float zoom: int } """ - config + { config with + MultilineBracketStyle = Cramped } |> prepend newline |> should equal diff --git a/src/Fantomas.Core.Tests/ListTests.fs b/src/Fantomas.Core.Tests/ListTests.fs index 9c9704fdeb..5d57c05325 100644 --- a/src/Fantomas.Core.Tests/ListTests.fs +++ b/src/Fantomas.Core.Tests/ListTests.fs @@ -48,7 +48,8 @@ let ``array values`` () = let arr = [|(1, 1, 1); (1, 2, 2); (1, 3, 3); (2, 1, 2); (2, 2, 4); (2, 3, 6); (3, 1, 3); (3, 2, 6); (3, 3, 9)|] """ - config + { config with + MultilineBracketStyle = Cramped } |> prepend newline |> should equal @@ -133,7 +134,8 @@ let ``should keep -> notation`` () = let e1 = e :?> Collections.DictionaryEntry e1.Key, e1.Value] """ - config + { config with + MultilineBracketStyle = Cramped } |> prepend newline |> should equal @@ -166,7 +168,9 @@ let ``array comprehensions`` () = let a1 = [| for i in 1 .. 10 -> i * i |] let a2 = [| 0 .. 99 |] let a3 = [| for n in 1 .. 100 do if isPrime n then yield n |]""" - { config with MaxIfThenShortWidth = 25 } + { config with + MaxIfThenShortWidth = 25 + MultilineBracketStyle = Cramped } |> prepend newline |> should equal @@ -276,7 +280,8 @@ let ``comment after string in list`` () = "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz" // "ffffffffffffffffffffffffffffffffffffffff"] """ - config + { config with + MultilineBracketStyle = Cramped } |> should equal """let xxxxxxxxxxxx = @@ -292,7 +297,8 @@ let ``multiline list should print each item on newline`` () = "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz"; "ffffffffffffffffffffffffffffffffffffffff"] """ - config + { config with + MultilineBracketStyle = Cramped } |> should equal """let xxxxxxxxxxxx = @@ -309,7 +315,9 @@ let ``multiline list of string should not add ;`` () = [ "_Binaries/AltCover/Debug+AnyCPU/AltCover.exe" "_Binaries/AltCover.Shadow/Debug+AnyCPU/AltCover.Shadow.dll" ] """ - { config with MaxLineLength = 80 } + { config with + MaxLineLength = 80 + MultilineBracketStyle = Cramped } |> should equal """[ "_Binaries/AltCover/Debug+AnyCPU/AltCover.exe" @@ -328,7 +336,8 @@ let prismCli commando = ] () """ - config + { config with + MultilineBracketStyle = Cramped } |> prepend newline |> should equal @@ -356,7 +365,8 @@ let prismCli commando = () """ { config with - SpaceAroundDelimiter = false } + SpaceAroundDelimiter = false + MultilineBracketStyle = Cramped } |> prepend newline |> should equal @@ -379,7 +389,8 @@ let ``line comment inside list`` () = ] """ { config with - SpaceAroundDelimiter = false } + SpaceAroundDelimiter = false + MultilineBracketStyle = Cramped } |> prepend newline |> should equal @@ -396,7 +407,8 @@ let ``line comment inside array`` () = // foo |] """ - config + { config with + MultilineBracketStyle = Cramped } |> prepend newline |> should equal @@ -416,7 +428,8 @@ let input = let sample = [|0;3;0;1;-3|] """ - config + { config with + MultilineBracketStyle = Cramped } |> prepend newline |> should equal @@ -1519,7 +1532,8 @@ let f' includeWeekend = "Sunday" ] """ - config + { config with + MultilineBracketStyle = Cramped } |> prepend newline |> should equal @@ -1576,7 +1590,9 @@ let nestedList: obj list = [ ] ] """ - { config with MaxLineLength = 80 } + { config with + MaxLineLength = 80 + MultilineBracketStyle = Cramped } |> prepend newline |> should equal @@ -1606,7 +1622,9 @@ let nestedList: obj list = [| |] |] """ - { config with MaxLineLength = 80 } + { config with + MaxLineLength = 80 + MultilineBracketStyle = Cramped } |> prepend newline |> should equal @@ -1636,7 +1654,9 @@ let nestedList: obj list = [| |] |] """ - { config with MaxLineLength = 80 } + { config with + MaxLineLength = 80 + MultilineBracketStyle = Cramped } |> prepend newline |> should equal @@ -1667,7 +1687,9 @@ let nestedList: obj list = [ ] ] """ - { config with MaxLineLength = 80 } + { config with + MaxLineLength = 80 + MultilineBracketStyle = Cramped } |> prepend newline |> should equal @@ -1699,7 +1721,9 @@ let nestedList: obj list = [| |] |] """ - { config with MaxLineLength = 80 } + { config with + MaxLineLength = 80 + MultilineBracketStyle = Cramped } |> prepend newline |> should equal @@ -1887,7 +1911,8 @@ let original_input = [ { config with MaxIfThenElseShortWidth = 120 MaxArrayOrListWidth = 120 - MaxIfThenShortWidth = 120 } + MaxIfThenShortWidth = 120 + MultilineBracketStyle = Cramped } |> prepend newline |> should equal @@ -1931,7 +1956,9 @@ let wrong = [ if true then 2 ] """ - { config with MaxIfThenShortWidth = 20 } + { config with + MaxIfThenShortWidth = 20 + MultilineBracketStyle = Cramped } |> prepend newline |> should equal @@ -1953,7 +1980,8 @@ let choices : Foo list = Foo 2 ] """ - config + { config with + MultilineBracketStyle = Cramped } |> prepend newline |> should equal @@ -1976,7 +2004,8 @@ let choices : Foo list = [ Foo 2 ] ] """ - config + { config with + MultilineBracketStyle = Cramped } |> prepend newline |> should equal @@ -1998,7 +2027,8 @@ let x = [ 2 ] """ - config + { config with + MultilineBracketStyle = Cramped } |> prepend newline |> should equal @@ -2019,7 +2049,8 @@ let ``comment after closing list bracket, 1073`` () = SynExpr.ForEach(DebugPointAtFor.No, SeqExprOnly b1, b2, pat, expr1, expr2, zero)) Arb.generate<_> Arb.generate<_> genSubDeclExpr genSubDeclExpr genSubSynPat ] // """ - config + { config with + MultilineBracketStyle = Cramped } |> prepend newline |> should equal @@ -2041,7 +2072,8 @@ let ``comment after closing array bracket`` () = SynExpr.ForEach(DebugPointAtFor.No, SeqExprOnly b1, b2, pat, expr1, expr2, zero)) Arb.generate<_> Arb.generate<_> genSubDeclExpr genSubDeclExpr genSubSynPat |] // """ - config + { config with + MultilineBracketStyle = Cramped } |> prepend newline |> should equal @@ -2070,7 +2102,9 @@ type FSharpCompilerServiceChecker(backgroundServiceEnabled) = |> Seq.filter (fun o -> o.ReferencedProjects |> Array.map (fun (_,v) -> Path.GetFullPath v.ProjectFileName) |> Array.contains option.ProjectFileName ) ]) """ - { config with IndentSize = 2 } + { config with + IndentSize = 2 + MultilineBracketStyle = Cramped } |> prepend newline |> should equal @@ -2108,7 +2142,8 @@ let private fn (xs: int[]) = let s = fn2() s.DoSomething() ] """ - config + { config with + MultilineBracketStyle = Cramped } |> prepend newline |> should equal @@ -2136,7 +2171,8 @@ let ``multiline function application inside array, 1382`` () = uioooooooooooooooooooooooo ) |] """ - config + { config with + MultilineBracketStyle = Cramped } |> prepend newline |> should equal @@ -2163,7 +2199,8 @@ let ``multiline function application inside list`` () = ] """ { config with - SpaceBeforeLowercaseInvocation = true } + SpaceBeforeLowercaseInvocation = true + MultilineBracketStyle = Cramped } |> prepend newline |> should equal @@ -2187,7 +2224,8 @@ let foo = fun () -> 2 ] """ - config + { config with + MultilineBracketStyle = Cramped } |> prepend newline |> should equal @@ -2207,7 +2245,8 @@ let foo = fun () -> 2 |] """ - config + { config with + MultilineBracketStyle = Cramped } |> prepend newline |> should equal @@ -2229,7 +2268,8 @@ let fns = // I think the space at the start of the lines above matter ] """ - config + { config with + MultilineBracketStyle = Cramped } |> prepend newline |> should equal diff --git a/src/Fantomas.Core.Tests/ModuleTests.fs b/src/Fantomas.Core.Tests/ModuleTests.fs index 3e486d9c7e..a5744166da 100644 --- a/src/Fantomas.Core.Tests/ModuleTests.fs +++ b/src/Fantomas.Core.Tests/ModuleTests.fs @@ -433,7 +433,8 @@ type UrlModel = KeepNewlineAfter: bool Defines: string } """ - config + { config with + MultilineBracketStyle = Cramped } |> prepend newline |> should equal @@ -484,7 +485,8 @@ type UrlModel = KeepNewlineAfter: bool Defines: string } """ - config + { config with + MultilineBracketStyle = Cramped } |> prepend newline |> should equal diff --git a/src/Fantomas.Core.Tests/NewlineBetweenTypeDefinitionAndMembersTests.fs b/src/Fantomas.Core.Tests/NewlineBetweenTypeDefinitionAndMembersTests.fs index 1db3c91ccb..d6afa2fa6f 100644 --- a/src/Fantomas.Core.Tests/NewlineBetweenTypeDefinitionAndMembersTests.fs +++ b/src/Fantomas.Core.Tests/NewlineBetweenTypeDefinitionAndMembersTests.fs @@ -3,6 +3,7 @@ module Fantomas.Core.Tests.NewlineBetweenTypeDefinitionAndMembersTests open NUnit.Framework open FsUnit open Fantomas.Core.Tests.TestHelpers +open Fantomas.Core [] let ``newline between record type and members`` () = @@ -14,7 +15,8 @@ let ``newline between record type and members`` () = member this.Length = this.To - this.From """ { config with - MaxValueBindingWidth = 120 } + MaxValueBindingWidth = 120 + MultilineBracketStyle = Cramped } |> prepend newline |> should equal @@ -38,7 +40,8 @@ let ``existing newline between record type and members should not be duplicate`` member this.Length = this.To - this.From """ { config with - MaxValueBindingWidth = 120 } + MaxValueBindingWidth = 120 + MultilineBracketStyle = Cramped } |> prepend newline |> should equal @@ -59,7 +62,9 @@ let ``no extra newline after record type with no members`` () = To : float Name: string } """ - { config with MaxRecordWidth = 39 } + { config with + MaxRecordWidth = 39 + MultilineBracketStyle = Cramped } |> prepend newline |> should equal @@ -141,7 +146,8 @@ type Range = Name: string } member Length : unit -> int """ - config + { config with + MultilineBracketStyle = Cramped } |> prepend newline |> should equal @@ -255,7 +261,8 @@ type Color = member ToInt: unit -> int """ - config + { config with + MultilineBracketStyle = Cramped } |> prepend newline |> should equal diff --git a/src/Fantomas.Core.Tests/NoTrailingSpacesTests.fs b/src/Fantomas.Core.Tests/NoTrailingSpacesTests.fs index 84c512e1ae..bcd4c63a87 100644 --- a/src/Fantomas.Core.Tests/NoTrailingSpacesTests.fs +++ b/src/Fantomas.Core.Tests/NoTrailingSpacesTests.fs @@ -4,6 +4,7 @@ open NUnit.Framework open FsUnit open Fantomas.Core.Tests.TestHelpers +open Fantomas.Core [] let ``should not confuse me with an extra space at end of line v2`` () = @@ -17,7 +18,8 @@ let ``should not confuse me with an extra space at end of line v2`` () = codeSnippet { config with MaxInfixOperatorExpression = 90 - MaxArrayOrListWidth = 40 } + MaxArrayOrListWidth = 40 + MultilineBracketStyle = Cramped } |> should equal """let ``should not extrude without positive distance`` () = diff --git a/src/Fantomas.Core.Tests/NumberOfItemsListOrArrayTests.fs b/src/Fantomas.Core.Tests/NumberOfItemsListOrArrayTests.fs index 7c4f515a17..80c08bc14e 100644 --- a/src/Fantomas.Core.Tests/NumberOfItemsListOrArrayTests.fs +++ b/src/Fantomas.Core.Tests/NumberOfItemsListOrArrayTests.fs @@ -15,7 +15,8 @@ f xs [ x; y; z ] List.map (fun x -> x * x) [1;2;] """ { config with - ArrayOrListMultilineFormatter = NumberOfItems } + ArrayOrListMultilineFormatter = NumberOfItems + MultilineBracketStyle = Cramped } |> prepend newline |> should equal @@ -50,7 +51,8 @@ f xs [| x; y; z |] List.map (fun x -> x * x) [|1;2;|] """ { config with - ArrayOrListMultilineFormatter = NumberOfItems } + ArrayOrListMultilineFormatter = NumberOfItems + MultilineBracketStyle = Cramped } |> prepend newline |> should equal @@ -291,7 +293,8 @@ let ``long expressions with number of items set to 3 will get split due to max l """ { config with ArrayOrListMultilineFormatter = NumberOfItems - MaxArrayOrListNumberOfItems = 3 } + MaxArrayOrListNumberOfItems = 3 + MultilineBracketStyle = Cramped } |> prepend newline |> should equal @@ -308,7 +311,9 @@ let x = [ a; b; c ] let y = [ longValueThatIsALotOfCharactersSoooooLong; longValueThatIsALotOfCharactersSoooooLong ] let z = [ longValueThatIsALotOfCharactersSoooooLong; 100; 123 ] """ - { config with MaxArrayOrListWidth = 70 } + { config with + MaxArrayOrListWidth = 70 + MultilineBracketStyle = Cramped } |> prepend newline |> should equal diff --git a/src/Fantomas.Core.Tests/NumberOfItemsRecordTests.fs b/src/Fantomas.Core.Tests/NumberOfItemsRecordTests.fs index 59df404235..3a57a2682e 100644 --- a/src/Fantomas.Core.Tests/NumberOfItemsRecordTests.fs +++ b/src/Fantomas.Core.Tests/NumberOfItemsRecordTests.fs @@ -32,7 +32,8 @@ let ``record instance`` () = Street = "Bakerstreet" Number = 42 } """ - config + { config with + MultilineBracketStyle = Cramped } |> prepend newline |> should equal @@ -57,7 +58,8 @@ let ``nested record`` () = ZipCode = "9000" } Number = 42 } """ - config + { config with + MultilineBracketStyle = Cramped } |> prepend newline |> should equal @@ -81,7 +83,8 @@ let ``update record`` () = Bar = "barry" Progress = "fooey" } """ - config + { config with + MultilineBracketStyle = Cramped } |> prepend newline |> should equal @@ -116,7 +119,8 @@ let ``record instance with inherit keyword`` () = buildSettings = FSharpBuildSettings() targetPlatformData = targetPlatformData } """ - config + { config with + MultilineBracketStyle = Cramped } |> prepend newline |> should equal @@ -171,7 +175,8 @@ let ``anonymous record`` () = Street = "Bakerstreet" Number = 42 |} """ - config + { config with + MultilineBracketStyle = Cramped } |> prepend newline |> should equal @@ -202,7 +207,9 @@ let ``anonymous record with multiple field update`` () = formatSourceString """let a = {| foo with Level = 7; Square = 9 |} """ - { config with MaxRecordWidth = 35 } + { config with + MaxRecordWidth = 35 + MultilineBracketStyle = Cramped } |> prepend newline |> should equal @@ -218,7 +225,8 @@ let ``anonymous type`` () = formatSourceString """type a = {| foo : string; bar : string |} """ - config + { config with + MultilineBracketStyle = Cramped } |> prepend newline |> should equal @@ -233,7 +241,8 @@ let ``anonymous record with single field`` () = formatSourceString """let a = {| A = "meh" |} """ - config + { config with + MultilineBracketStyle = Cramped } |> prepend newline |> should equal @@ -251,7 +260,8 @@ let anonRecord = C= { C1 = "foo"; C2LongerIdentifier = "bar"} D = { D1 = "bar" } |} """ - config + { config with + MultilineBracketStyle = Cramped } |> prepend newline |> should equal @@ -273,7 +283,8 @@ let ``record as parameter to function`` () = """let configurations = buildConfiguration { XXXXXXXXXXXX = "XXXXXXXXXXXXX"; YYYYYYYYYYYY = "YYYYYYYYYYYYYYY" } """ - config + { config with + MultilineBracketStyle = Cramped } |> prepend newline |> should equal @@ -294,7 +305,8 @@ let ``records in list`` () = { Build = true; Configuration = "UNKNOWN"; Defines = [] } ] """ - config + { config with + MultilineBracketStyle = Cramped } |> prepend newline |> should equal @@ -320,7 +332,8 @@ let ``anonymous records in list`` () = {| Build = true; Configuration = "DEBUG"; Defines = ["FOO";"BAR"] |} ] """ - config + { config with + MultilineBracketStyle = Cramped } |> prepend newline |> should equal @@ -343,7 +356,8 @@ let ``records in array`` () = { Build = true; Configuration = "DEBUG"; Defines = ["FOO";"BAR"] } |] """ - config + { config with + MultilineBracketStyle = Cramped } |> prepend newline |> should equal @@ -363,7 +377,8 @@ let ``object expression`` () = """ let obj1 = { new System.Object() with member x.ToString() = "F#" } """ - config + { config with + MultilineBracketStyle = Cramped } |> prepend newline |> should equal @@ -383,7 +398,8 @@ let a = { new System.Object() with member x.ToString() = "C#" } ] """ - config + { config with + MultilineBracketStyle = Cramped } |> prepend newline |> should equal @@ -444,7 +460,8 @@ type Range = """ { config with MaxValueBindingWidth = 120 - NewlineBetweenTypeDefinitionAndMembers = false } + NewlineBetweenTypeDefinitionAndMembers = false + MultilineBracketStyle = Cramped } |> prepend newline |> should equal @@ -465,7 +482,8 @@ type MyRecord = interface IMyInterface """ { config with - NewlineBetweenTypeDefinitionAndMembers = false } + NewlineBetweenTypeDefinitionAndMembers = false + MultilineBracketStyle = Cramped } |> prepend newline |> should equal @@ -482,7 +500,8 @@ let ``SynPat.Record in pattern match, 1173`` () = | { Bar = bar; Level = 12; Vibes = plenty; Lorem = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. " } -> "7" | _ -> "8" """ - config + { config with + MultilineBracketStyle = Cramped } |> prepend newline |> should equal @@ -506,7 +525,8 @@ let ``record declaration`` () = Street: string Number: int } """ - config + { config with + MultilineBracketStyle = Cramped } |> prepend newline |> should equal @@ -530,7 +550,8 @@ type MyRecord = Street: string Number: int } """ - config + { config with + MultilineBracketStyle = Cramped } |> prepend newline |> should equal @@ -558,7 +579,8 @@ type MyRecord = member Score : unit -> int """ { config with - NewlineBetweenTypeDefinitionAndMembers = false } + NewlineBetweenTypeDefinitionAndMembers = false + MultilineBracketStyle = Cramped } |> prepend newline |> should equal @@ -588,7 +610,8 @@ type ShortExpressionInfo = member x.Foo() = () """ { config with - NewlineBetweenTypeDefinitionAndMembers = false } + NewlineBetweenTypeDefinitionAndMembers = false + MultilineBracketStyle = Cramped } |> prepend newline |> should equal @@ -609,7 +632,8 @@ let ``internal keyword before multiline record type, 1171`` () = formatSourceString """ type A = internal { ALongIdentifier: string; YetAnotherLongIdentifier: bool }""" - config + { config with + MultilineBracketStyle = Cramped } |> prepend newline |> should equal @@ -626,7 +650,8 @@ let ``internal keyword before multiline record type in signature file, 1171`` () """namespace Bar type A = internal { ALongIdentifier: string; YetAnotherLongIdentifier: bool }""" - config + { config with + MultilineBracketStyle = Cramped } |> prepend newline |> should equal @@ -643,7 +668,9 @@ type A = let ``indent update record fields far enough, 817`` () = formatSourceString "let expected = { ThisIsAThing.Empty with TheNewValue = 1; ThatValue = 2 }" - { config with IndentSize = 2 } + { config with + IndentSize = 2 + MultilineBracketStyle = Cramped } |> prepend newline |> should equal @@ -658,7 +685,9 @@ let expected = let ``indent update anonymous record fields far enough`` () = formatSourceString "let expected = {| ThisIsAThing.Empty with TheNewValue = 1; ThatValue = 2 |}" - { config with IndentSize = 2 } + { config with + IndentSize = 2 + MultilineBracketStyle = Cramped } |> prepend newline |> should equal @@ -671,7 +700,10 @@ let expected = [] let ``update record with standard indent`` () = - formatSourceString "let expected = { ThisIsAThing.Empty with TheNewValue = 1; ThatValue = 2 }" config + formatSourceString + "let expected = { ThisIsAThing.Empty with TheNewValue = 1; ThatValue = 2 }" + { config with + MultilineBracketStyle = Cramped } |> prepend newline |> should equal @@ -697,7 +729,8 @@ module Foo = let r = 3 """ - config + { config with + MultilineBracketStyle = Cramped } |> prepend newline |> should equal @@ -726,7 +759,8 @@ type TestType = Foo : int } """ - config + { config with + MultilineBracketStyle = Cramped } |> prepend newline |> should equal @@ -754,7 +788,8 @@ let config = { #endif } """ - config + { config with + MultilineBracketStyle = Cramped } |> prepend newline |> should equal @@ -781,7 +816,8 @@ let person = Address = { Street = "Bakerstreet"; Number = 42 } // end address } // end person """ - config + { config with + MultilineBracketStyle = Cramped } |> prepend newline |> should equal @@ -802,7 +838,8 @@ type R = { a: int; b: string; c: float option } type S = { AReallyLongExpressionThatIsMuchLongerThan50Characters: int } """ { config with - RecordMultilineFormatter = NumberOfItems } + RecordMultilineFormatter = NumberOfItems + MultilineBracketStyle = Cramped } |> prepend newline |> should equal @@ -858,7 +895,8 @@ f r' { r with a = x; b = y; z = c } g s' { s with AReallyLongExpressionThatIsMuchLongerThan50Characters = 1 } """ { config with - RecordMultilineFormatter = NumberOfItems } + RecordMultilineFormatter = NumberOfItems + MultilineBracketStyle = Cramped } |> prepend newline |> should equal @@ -977,7 +1015,8 @@ f r' {| r with a = x; b = y; z = c |} g s' {| s with AReallyLongExpressionThatIsMuchLongerThan50Characters = 1 |} """ { config with - RecordMultilineFormatter = NumberOfItems } + RecordMultilineFormatter = NumberOfItems + MultilineBracketStyle = Cramped } |> prepend newline |> should equal @@ -1089,7 +1128,8 @@ type A = {| x: int; y: obj |} type B = {| x: AReallyLongTypeThatIsMuchLongerThan40Characters |} """ { config with - RecordMultilineFormatter = NumberOfItems } + RecordMultilineFormatter = NumberOfItems + MultilineBracketStyle = Cramped } |> prepend newline |> should equal diff --git a/src/Fantomas.Core.Tests/OperatorTests.fs b/src/Fantomas.Core.Tests/OperatorTests.fs index ef01848955..e5b029b6db 100644 --- a/src/Fantomas.Core.Tests/OperatorTests.fs +++ b/src/Fantomas.Core.Tests/OperatorTests.fs @@ -671,7 +671,8 @@ let r = Fooey \"\"\" |} " - config + { config with + MultilineBracketStyle = Cramped } |> prepend newline |> should equal @@ -1205,7 +1206,8 @@ type Test = { WorkHoursPerWeek = 40u } """ { config with - NewlineBetweenTypeDefinitionAndMembers = false } + NewlineBetweenTypeDefinitionAndMembers = false + MultilineBracketStyle = Cramped } |> prepend newline |> should equal diff --git a/src/Fantomas.Core.Tests/PatternMatchingTests.fs b/src/Fantomas.Core.Tests/PatternMatchingTests.fs index 6b4bb86383..423ed05547 100644 --- a/src/Fantomas.Core.Tests/PatternMatchingTests.fs +++ b/src/Fantomas.Core.Tests/PatternMatchingTests.fs @@ -3,6 +3,7 @@ module Fantomas.Core.Tests.PatternMatchingTests open NUnit.Framework open FsUnit open Fantomas.Core.Tests.TestHelpers +open Fantomas.Core [] let ``match expressions`` () = @@ -790,7 +791,9 @@ let private update onSubmit msg model = { model with Errors = errors }, Cmd.none """ - { config with SpaceBeforeColon = true } + { config with + SpaceBeforeColon = true + MultilineBracketStyle = Cramped } |> prepend newline |> should equal @@ -936,7 +939,8 @@ let draftToken = else Other DraftToken.Create kind token """ - config + { config with + MultilineBracketStyle = Cramped } |> prepend newline |> should equal diff --git a/src/Fantomas.Core.Tests/QuotationTests.fs b/src/Fantomas.Core.Tests/QuotationTests.fs index 7e6d84f67a..4860e1958b 100644 --- a/src/Fantomas.Core.Tests/QuotationTests.fs +++ b/src/Fantomas.Core.Tests/QuotationTests.fs @@ -3,6 +3,7 @@ module Fantomas.Core.Tests.QuotationTests open NUnit.Framework open FsUnit open Fantomas.Core.Tests.TestHelpers +open Fantomas.Core [] let ``typed quotations`` () = @@ -148,7 +149,9 @@ let ``overly aggressive de-indentation, 2110`` () = Push = null Pop = null } } @> """ - { config with IndentSize = 2 } + { config with + IndentSize = 2 + MultilineBracketStyle = Cramped } |> prepend newline |> should equal diff --git a/src/Fantomas.Core.Tests/RecordDeclarationsWithXMLDocTests.fs b/src/Fantomas.Core.Tests/RecordDeclarationsWithXMLDocTests.fs index 513c13a742..dd8b5618c9 100644 --- a/src/Fantomas.Core.Tests/RecordDeclarationsWithXMLDocTests.fs +++ b/src/Fantomas.Core.Tests/RecordDeclarationsWithXMLDocTests.fs @@ -3,6 +3,7 @@ open NUnit.Framework open FsUnit open Fantomas.Core.Tests.TestHelpers +open Fantomas.Core [] let ``each record field has xml comment`` () = @@ -152,7 +153,8 @@ type SynExprTryWithTrivia = WithToEndRange: range } """ - config + { config with + MultilineBracketStyle = Cramped } |> prepend newline |> should equal @@ -176,7 +178,8 @@ type SynExprTryWithTrivia = WithToEndRange: range } """ - config + { config with + MultilineBracketStyle = Cramped } |> prepend newline |> should equal diff --git a/src/Fantomas.Core.Tests/SignatureTests.fs b/src/Fantomas.Core.Tests/SignatureTests.fs index 784ae08d83..e3271db467 100644 --- a/src/Fantomas.Core.Tests/SignatureTests.fs +++ b/src/Fantomas.Core.Tests/SignatureTests.fs @@ -18,7 +18,8 @@ let ``should keep the (string * string) list type signature in records`` () = FileLoggers : MSBuildFileLoggerConfig list option } """ - config + { config with + MultilineBracketStyle = Cramped } |> should equal """type MSBuildParams = @@ -74,7 +75,8 @@ let ``should not add parens in signature`` () = """ { config with MaxFunctionBindingWidth = 120 - NewlineBetweenTypeDefinitionAndMembers = false } + NewlineBetweenTypeDefinitionAndMembers = false + MultilineBracketStyle = Cramped } |> should equal """type Route = @@ -108,7 +110,8 @@ let ``should keep the (string option * Node) list type signature`` () = NextNodes : (string option * Node) list } """ - config + { config with + MultilineBracketStyle = Cramped } |> should equal """type Node = @@ -703,7 +706,8 @@ let ``internal keyword before long record type`` () = """namespace Bar type A = internal { ALongIdentifier: string; YetAnotherLongIdentifier: bool }""" - config + { config with + MultilineBracketStyle = Cramped } |> prepend newline |> should equal @@ -1068,7 +1072,9 @@ type TestType = Barry: string } """ - { config with MaxRecordWidth = 10 } + { config with + MaxRecordWidth = 10 + MultilineBracketStyle = Cramped } |> prepend newline |> should equal @@ -1097,7 +1103,8 @@ type TestType = Meh : TimeSpan } """ - config + { config with + MultilineBracketStyle = Cramped } |> prepend newline |> should equal @@ -1581,7 +1588,8 @@ type Foo = static member Baz : int """ { config with - NewlineBetweenTypeDefinitionAndMembers = false } + NewlineBetweenTypeDefinitionAndMembers = false + MultilineBracketStyle = Cramped } |> prepend newline |> should equal diff --git a/src/Fantomas.Core.Tests/SpaceBeforeClassConstructorTests.fs b/src/Fantomas.Core.Tests/SpaceBeforeClassConstructorTests.fs index 42d54402db..b7768bd95f 100644 --- a/src/Fantomas.Core.Tests/SpaceBeforeClassConstructorTests.fs +++ b/src/Fantomas.Core.Tests/SpaceBeforeClassConstructorTests.fs @@ -180,7 +180,8 @@ type ProtocolGlitchException = new(message: string, innerException: Exception) = { inherit CommunicationUnsuccessfulException(message, innerException) } """ - spaceBeforeConfig + { spaceBeforeConfig with + MultilineBracketStyle = Cramped } |> prepend newline |> should equal @@ -214,7 +215,8 @@ type DerivedClass = new(str2) = { inherit BaseClass(); string2 = str2 } """ - spaceBeforeConfig + { spaceBeforeConfig with + MultilineBracketStyle = Cramped } |> prepend newline |> should equal @@ -250,7 +252,8 @@ type DerivedClass = string2 = str2 } """ { config with - SpaceBeforeClassConstructor = false } + SpaceBeforeClassConstructor = false + MultilineBracketStyle = Cramped } |> prepend newline |> should equal diff --git a/src/Fantomas.Core.Tests/SpecialConstructsTests.fs b/src/Fantomas.Core.Tests/SpecialConstructsTests.fs index 34c7f99250..c0cddaac7c 100644 --- a/src/Fantomas.Core.Tests/SpecialConstructsTests.fs +++ b/src/Fantomas.Core.Tests/SpecialConstructsTests.fs @@ -3,6 +3,7 @@ module Fantomas.Core.Tests.SpecialConstructsTests open NUnit.Framework open FsUnit open Fantomas.Core.Tests.TestHelpers +open Fantomas.Core [] let ``embedded IL`` () = @@ -30,7 +31,8 @@ x.G[].TryFind 3 { config with SpaceAfterComma = false SpaceAfterSemicolon = false - SpaceAroundDelimiter = false } + SpaceAroundDelimiter = false + MultilineBracketStyle = Cramped } |> prepend newline |> should equal diff --git a/src/Fantomas.Core.Tests/Stroustrup/ExperimentalElmishTests.fs b/src/Fantomas.Core.Tests/Stroustrup/ExperimentalElmishTests.fs index 6f925f507f..ad6779c7a1 100644 --- a/src/Fantomas.Core.Tests/Stroustrup/ExperimentalElmishTests.fs +++ b/src/Fantomas.Core.Tests/Stroustrup/ExperimentalElmishTests.fs @@ -836,7 +836,8 @@ let private useLocationDetail (auth0 : Auth0Hook) (roles : RolesHook) id = { config with SpaceBeforeColon = true MaxArrayOrListWidth = 40 - MaxInfixOperatorExpression = 50 } + MaxInfixOperatorExpression = 50 + MultilineBracketStyle = Cramped } |> prepend newline |> should equal @@ -1286,7 +1287,8 @@ let stillCramped = [ x ; y ; z ] """ - config + { config with + MultilineBracketStyle = Cramped } |> prepend newline |> should equal diff --git a/src/Fantomas.Core.Tests/StructTests.fs b/src/Fantomas.Core.Tests/StructTests.fs index 59d8c7d69a..f737601b91 100644 --- a/src/Fantomas.Core.Tests/StructTests.fs +++ b/src/Fantomas.Core.Tests/StructTests.fs @@ -3,6 +3,7 @@ module Fantomas.Core.Tests.StructTests open NUnit.Framework open FsUnit open Fantomas.Core.Tests.TestHelpers +open Fantomas.Core [] let ``struct type`` () = @@ -166,7 +167,8 @@ struct // 1 // 5 |} // 6 """ - config + { config with + MultilineBracketStyle = Cramped } |> prepend newline |> should equal diff --git a/src/Fantomas.Core.Tests/SynConstTests.fs b/src/Fantomas.Core.Tests/SynConstTests.fs index 14b0761ae6..a58ea506e7 100644 --- a/src/Fantomas.Core.Tests/SynConstTests.fs +++ b/src/Fantomas.Core.Tests/SynConstTests.fs @@ -3,6 +3,7 @@ module Fantomas.Core.Tests.SynConstTests open NUnit.Framework open FsUnit open Fantomas.Core.Tests.TestHelpers +open Fantomas.Core // https://fsharp.github.io/FSharp.Compiler.Service/reference/fsharp-compiler-ast-synconst.html [] @@ -605,7 +606,8 @@ a:hover {color: #ecc;} " { config with MaxInfixOperatorExpression = 50 - MaxArrayOrListWidth = 40 } + MaxArrayOrListWidth = 40 + MultilineBracketStyle = Cramped } |> prepend newline |> should equal diff --git a/src/Fantomas.Core.Tests/SynExprSetTests.fs b/src/Fantomas.Core.Tests/SynExprSetTests.fs index c5491adcd3..7507fa3bb2 100644 --- a/src/Fantomas.Core.Tests/SynExprSetTests.fs +++ b/src/Fantomas.Core.Tests/SynExprSetTests.fs @@ -3,6 +3,7 @@ module Fantomas.Core.Tests.SynExprSetTests open NUnit.Framework open FsUnit open Fantomas.Core.Tests.TestHelpers +open Fantomas.Core /// See https://fsprojects.github.io/fantomas/reference/fsharp-compiler-syntax-synexpr.html#Set @@ -87,7 +88,8 @@ let ``don't add additional new line after SynExpr.LongIndentSet, 1111`` () = """ { config with MaxArrayOrListWidth = 40 - MaxInfixOperatorExpression = 50 } + MaxInfixOperatorExpression = 50 + MultilineBracketStyle = Cramped } |> prepend newline |> should equal diff --git a/src/Fantomas.Core.Tests/TypeAnnotationTests.fs b/src/Fantomas.Core.Tests/TypeAnnotationTests.fs index d24c12d665..c500fdcf83 100644 --- a/src/Fantomas.Core.Tests/TypeAnnotationTests.fs +++ b/src/Fantomas.Core.Tests/TypeAnnotationTests.fs @@ -18,7 +18,8 @@ let f = x """ - config + { config with + MultilineBracketStyle = Cramped } |> prepend newline |> should equal diff --git a/src/Fantomas.Core.Tests/TypeDeclarationTests.fs b/src/Fantomas.Core.Tests/TypeDeclarationTests.fs index 37cfcafae9..f81cb61ed2 100644 --- a/src/Fantomas.Core.Tests/TypeDeclarationTests.fs +++ b/src/Fantomas.Core.Tests/TypeDeclarationTests.fs @@ -1244,7 +1244,8 @@ and Room = Items: Item list Exits: Exits } """ - config + { config with + MultilineBracketStyle = Cramped } |> prepend newline |> should equal @@ -1293,7 +1294,8 @@ and [] Room = Items: Item list Exits: Exits } """ - config + { config with + MultilineBracketStyle = Cramped } |> prepend newline |> should equal @@ -1934,7 +1936,8 @@ type TestType = Foo : int } """ - config + { config with + MultilineBracketStyle = Cramped } |> prepend newline |> should equal @@ -1960,7 +1963,8 @@ type OlapCube = ThreeDimension : int } """ - config + { config with + MultilineBracketStyle = Cramped } |> prepend newline |> should equal @@ -2236,7 +2240,9 @@ type Auth0User = { UserId = userId AppMetaData = metaData }) """ - { config with SpaceBeforeColon = true } + { config with + SpaceBeforeColon = true + MultilineBracketStyle = Cramped } |> prepend newline |> should equal @@ -2306,7 +2312,8 @@ type RequestParser<'ctx, 'a> = internal { prohibited: ProhibitedRequestGetter list } """ - config + { config with + MultilineBracketStyle = Cramped } |> prepend newline |> should equal @@ -2350,7 +2357,8 @@ let deserialize (e: RecordedEvent) : MyEvent = | nameof BData -> BData (JsonSerializer.Deserialize e.Data) | t -> failwithf "Invalid EventType: %s" t """ - config + { config with + MultilineBracketStyle = Cramped } |> prepend newline |> should equal @@ -3010,7 +3018,8 @@ type V = // comment Y: OhSomethingElse Z: ALongTypeName } """ - config + { config with + MultilineBracketStyle = Cramped } |> prepend newline |> should equal @@ -3603,7 +3612,8 @@ type R = F3: int } """ - config + { config with + MultilineBracketStyle = Cramped } |> prepend newline |> should equal diff --git a/src/Fantomas.Core.Tests/TypeProviderTests.fs b/src/Fantomas.Core.Tests/TypeProviderTests.fs index 363c2ad974..621034ddd5 100644 --- a/src/Fantomas.Core.Tests/TypeProviderTests.fs +++ b/src/Fantomas.Core.Tests/TypeProviderTests.fs @@ -61,7 +61,8 @@ let ``should handle lines with more than 512 characters`` () = """ (new CsvFile(new Func(fun (parent : obj) (row : string[]) -> CommonRuntime.GetNonOptionalValue("Name", CommonRuntime.ConvertString(TextConversions.AsOption(row.[0])), TextConversions.AsOption(row.[0])), CommonRuntime.GetNonOptionalValue("Distance", CommonRuntime.ConvertDecimal("", TextConversions.AsOption(row.[1])), TextConversions.AsOption(row.[1])), CommonRuntime.GetNonOptionalValue("Time", CommonRuntime.ConvertDecimal("", TextConversions.AsOption(row.[2])), TextConversions.AsOption(row.[2]))), new Func(fun (row : string * decimal * decimal) -> [| CommonRuntime.ConvertStringBack(CommonRuntime.GetOptionalValue((let x, _, _ = row in x))); CommonRuntime.ConvertDecimalBack("", CommonRuntime.GetOptionalValue((let _, x, _ = row in x))); CommonRuntime.ConvertDecimalBack("", CommonRuntime.GetOptionalValue((let _, _, x = row in x))) |]), (ProviderFileSystem.readTextAtRunTimeWithDesignTimeOptions @"C:\Dev\FSharp.Data-master\src\..\tests\FSharp.Data.Tests\Data" "" "SmallTest.csv"), "", '"', true, false)).Cache() """ - config + { config with + MultilineBracketStyle = Cramped } |> prepend newline |> should equal diff --git a/src/Fantomas.Core.Tests/UnionTests.fs b/src/Fantomas.Core.Tests/UnionTests.fs index 682d6deae4..51ec6a0ff4 100644 --- a/src/Fantomas.Core.Tests/UnionTests.fs +++ b/src/Fantomas.Core.Tests/UnionTests.fs @@ -1098,7 +1098,8 @@ type A = | A of int | B of {| A: int; LongerThanLengthDeclaration: string|} """ - config + { config with + MultilineBracketStyle = Cramped } |> prepend newline |> should equal diff --git a/src/Fantomas.Core/CodeFormatter.fs b/src/Fantomas.Core/CodeFormatter.fs index de70e9071d..34bb100a79 100644 --- a/src/Fantomas.Core/CodeFormatter.fs +++ b/src/Fantomas.Core/CodeFormatter.fs @@ -31,11 +31,11 @@ type CodeFormatter = return result.Code } - static member FormatASTAsync(ast: ParsedInput, source, config) : Async = + static member FormatASTAsync(ast: ParsedInput, config, source) : Async = async { let sourceText = Some(CodeFormatterImpl.getSourceText source) let result = CodeFormatterImpl.formatAST ast sourceText config None - return result + return result.Code } static member FormatDocumentAsync(isSignature, source) = diff --git a/src/Fantomas.Core/CodeFormatter.fsi b/src/Fantomas.Core/CodeFormatter.fsi index 85fb76c538..314a0257a4 100644 --- a/src/Fantomas.Core/CodeFormatter.fsi +++ b/src/Fantomas.Core/CodeFormatter.fsi @@ -18,6 +18,9 @@ type CodeFormatter = /// Format an abstract syntax tree with the original source for trivia processing static member FormatASTAsync: ast: ParsedInput * source: string -> Async + /// Format an abstract syntax tree with the original source for trivia processing + static member FormatASTAsync: ast: ParsedInput * config: FormatConfig * source: string -> Async + /// /// Format a source string using an optional config. /// diff --git a/src/Fantomas.Core/FormatConfig.fs b/src/Fantomas.Core/FormatConfig.fs index 20692b189b..577c1a31a1 100644 --- a/src/Fantomas.Core/FormatConfig.fs +++ b/src/Fantomas.Core/FormatConfig.fs @@ -260,7 +260,7 @@ type FormatConfig = ExperimentalKeepIndentInBranch = false BlankLinesAroundNestedMultilineExpressions = true BarBeforeDiscriminatedUnionDeclaration = false - MultilineBracketStyle = Cramped + MultilineBracketStyle = Aligned KeepMaxNumberOfBlankLines = 100 NewlineBeforeMultilineComputationExpression = true ExperimentalElmish = false }