From c6ef6ad6c09eb84cbbfe449912cb941dab7585a3 Mon Sep 17 00:00:00 2001 From: Josh DeGraw Date: Tue, 31 Jan 2023 11:46:42 -0700 Subject: [PATCH 1/3] Remove experimental prefix from stroustrup bracket style --- .../AlignedMultilineBracketStyleTests.fs | 2 +- src/Fantomas.Core.Tests/DallasTests.fs | 2 +- .../NumberOfItemsListOrArrayTests.fs | 8 ++-- .../DotIndexedSetExpressionTests.fs | 2 +- .../Stroustrup/DotSetExpressionTests.fs | 2 +- .../Stroustrup/ElmishTests.fs | 2 +- .../FunctionApplicationDualListTests.fs | 2 +- .../FunctionApplicationSingleListTests.fs | 2 +- .../KeepIndentInBranchExpressionTests.fs | 2 +- .../Stroustrup/LambdaExpressionTests.fs | 2 +- .../Stroustrup/LetOrUseBangExpressionTests.fs | 2 +- .../Stroustrup/LongIdentSetExpressionTests.fs | 2 +- ...LineLambdaClosingNewlineExpressionTests.fs | 2 +- .../NamedArgumentExpressionTests.fs | 2 +- .../Stroustrup/SetExpressionTests.fs | 2 +- .../SynBindingFunctionExpressionTests.fs | 2 +- ...ndingFunctionLongPatternExpressionTests.fs | 2 +- ...ngFunctionWithReturnTypeExpressionTests.fs | 2 +- .../SynBindingValueExpressionTests.fs | 2 +- .../SynExprAndBangExpressionTests.fs | 2 +- .../SynMatchClauseExpressionTests.fs | 2 +- .../SynTypeDefnSigReprSimpleTests.fs | 2 +- .../SynTypeDefnSimpleReprRecordTests.fs | 2 +- .../YieldOrReturnBangExpressionTests.fs | 2 +- .../YieldOrReturnExpressionTests.fs | 2 +- src/Fantomas.Core/CodePrinter.fs | 37 ++++++++----------- src/Fantomas.Core/Context.fs | 14 +++---- src/Fantomas.Core/FormatConfig.fs | 13 ++++--- .../EditorConfigurationTests.fs | 2 +- 29 files changed, 56 insertions(+), 66 deletions(-) diff --git a/src/Fantomas.Core.Tests/AlignedMultilineBracketStyleTests.fs b/src/Fantomas.Core.Tests/AlignedMultilineBracketStyleTests.fs index 235ef7f052..9389d84b13 100644 --- a/src/Fantomas.Core.Tests/AlignedMultilineBracketStyleTests.fs +++ b/src/Fantomas.Core.Tests/AlignedMultilineBracketStyleTests.fs @@ -1526,7 +1526,7 @@ let ``update record in stroustrup style`` () = let v = { rainbow with Boss = "Jeffrey" ; Lackeys = [ "Zippy"; "George"; "Bungle" ] } """ { config with - MultilineBracketStyle = ExperimentalStroustrup } + MultilineBracketStyle = Stroustrup } |> prepend newline |> should equal diff --git a/src/Fantomas.Core.Tests/DallasTests.fs b/src/Fantomas.Core.Tests/DallasTests.fs index 039a54707c..2ecbbc8ddd 100644 --- a/src/Fantomas.Core.Tests/DallasTests.fs +++ b/src/Fantomas.Core.Tests/DallasTests.fs @@ -1857,7 +1857,7 @@ let someTest input1 input2 = } """ { config with - MultilineBracketStyle = ExperimentalStroustrup } + MultilineBracketStyle = Stroustrup } |> prepend newline |> should equal diff --git a/src/Fantomas.Core.Tests/NumberOfItemsListOrArrayTests.fs b/src/Fantomas.Core.Tests/NumberOfItemsListOrArrayTests.fs index 44a00d904e..6d4caa649a 100644 --- a/src/Fantomas.Core.Tests/NumberOfItemsListOrArrayTests.fs +++ b/src/Fantomas.Core.Tests/NumberOfItemsListOrArrayTests.fs @@ -88,7 +88,7 @@ h [ longValueThatIsALotOfCharactersSoooooLong; longValueThatIsALotOfCharactersSo """ { config with ArrayOrListMultilineFormatter = NumberOfItems - MultilineBracketStyle = ExperimentalStroustrup } + MultilineBracketStyle = Stroustrup } |> prepend newline |> should equal @@ -206,7 +206,7 @@ h [ longValueThatIsALotOfCharactersSoooooLong; longValueThatIsALotOfCharactersSo """ { config with ArrayOrListMultilineFormatter = NumberOfItems - MultilineBracketStyle = ExperimentalStroustrup } + MultilineBracketStyle = Stroustrup } |> prepend newline |> should equal @@ -240,7 +240,7 @@ h [ longValueThatIsALotOfCharactersSoooooLong; longValueThatIsALotOfCharactersSo """ { config with ArrayOrListMultilineFormatter = NumberOfItems - MultilineBracketStyle = ExperimentalStroustrup } + MultilineBracketStyle = Stroustrup } |> prepend newline |> should equal @@ -272,7 +272,7 @@ h [ longValueThatIsALotOfCharactersSoooooLong; longValueThatIsALotOfCharactersSo """ { config with ArrayOrListMultilineFormatter = NumberOfItems - MultilineBracketStyle = ExperimentalStroustrup } + MultilineBracketStyle = Stroustrup } |> prepend newline |> should equal diff --git a/src/Fantomas.Core.Tests/Stroustrup/DotIndexedSetExpressionTests.fs b/src/Fantomas.Core.Tests/Stroustrup/DotIndexedSetExpressionTests.fs index f9f69eaf8d..ea829c6124 100644 --- a/src/Fantomas.Core.Tests/Stroustrup/DotIndexedSetExpressionTests.fs +++ b/src/Fantomas.Core.Tests/Stroustrup/DotIndexedSetExpressionTests.fs @@ -7,7 +7,7 @@ open Fantomas.Core let config = { config with - MultilineBracketStyle = ExperimentalStroustrup + MultilineBracketStyle = Stroustrup MaxArrayOrListWidth = 40 } [] diff --git a/src/Fantomas.Core.Tests/Stroustrup/DotSetExpressionTests.fs b/src/Fantomas.Core.Tests/Stroustrup/DotSetExpressionTests.fs index c9c021c6de..b95a5b7d45 100644 --- a/src/Fantomas.Core.Tests/Stroustrup/DotSetExpressionTests.fs +++ b/src/Fantomas.Core.Tests/Stroustrup/DotSetExpressionTests.fs @@ -7,7 +7,7 @@ open Fantomas.Core let config = { config with - MultilineBracketStyle = ExperimentalStroustrup + MultilineBracketStyle = Stroustrup MaxArrayOrListWidth = 40 } [] diff --git a/src/Fantomas.Core.Tests/Stroustrup/ElmishTests.fs b/src/Fantomas.Core.Tests/Stroustrup/ElmishTests.fs index 9272a1064e..692a4c36cd 100644 --- a/src/Fantomas.Core.Tests/Stroustrup/ElmishTests.fs +++ b/src/Fantomas.Core.Tests/Stroustrup/ElmishTests.fs @@ -7,7 +7,7 @@ open Fantomas.Core let config = { config with - MultilineBracketStyle = ExperimentalStroustrup } + MultilineBracketStyle = Stroustrup } [] let ``long named arguments should go on newline`` () = diff --git a/src/Fantomas.Core.Tests/Stroustrup/FunctionApplicationDualListTests.fs b/src/Fantomas.Core.Tests/Stroustrup/FunctionApplicationDualListTests.fs index b2fc44e629..e45b9cd5f7 100644 --- a/src/Fantomas.Core.Tests/Stroustrup/FunctionApplicationDualListTests.fs +++ b/src/Fantomas.Core.Tests/Stroustrup/FunctionApplicationDualListTests.fs @@ -7,7 +7,7 @@ open Fantomas.Core let config = { config with - MultilineBracketStyle = ExperimentalStroustrup } + MultilineBracketStyle = Stroustrup } [] let ``two short lists`` () = diff --git a/src/Fantomas.Core.Tests/Stroustrup/FunctionApplicationSingleListTests.fs b/src/Fantomas.Core.Tests/Stroustrup/FunctionApplicationSingleListTests.fs index 4da71aaef8..5a7d4b6111 100644 --- a/src/Fantomas.Core.Tests/Stroustrup/FunctionApplicationSingleListTests.fs +++ b/src/Fantomas.Core.Tests/Stroustrup/FunctionApplicationSingleListTests.fs @@ -7,7 +7,7 @@ open Fantomas.Core let config = { config with - MultilineBracketStyle = ExperimentalStroustrup } + MultilineBracketStyle = Stroustrup } [] let ``short function application`` () = diff --git a/src/Fantomas.Core.Tests/Stroustrup/KeepIndentInBranchExpressionTests.fs b/src/Fantomas.Core.Tests/Stroustrup/KeepIndentInBranchExpressionTests.fs index 540cf9a861..55054b5833 100644 --- a/src/Fantomas.Core.Tests/Stroustrup/KeepIndentInBranchExpressionTests.fs +++ b/src/Fantomas.Core.Tests/Stroustrup/KeepIndentInBranchExpressionTests.fs @@ -10,7 +10,7 @@ open Fantomas.Core let config = { config with ExperimentalKeepIndentInBranch = true - MultilineBracketStyle = ExperimentalStroustrup + MultilineBracketStyle = Stroustrup MaxArrayOrListWidth = 40 } // There currently is no conflict with this setting, but I'm guessing the case was never brought up. diff --git a/src/Fantomas.Core.Tests/Stroustrup/LambdaExpressionTests.fs b/src/Fantomas.Core.Tests/Stroustrup/LambdaExpressionTests.fs index f42cbad66e..887c056d32 100644 --- a/src/Fantomas.Core.Tests/Stroustrup/LambdaExpressionTests.fs +++ b/src/Fantomas.Core.Tests/Stroustrup/LambdaExpressionTests.fs @@ -7,7 +7,7 @@ open Fantomas.Core let config = { config with - MultilineBracketStyle = ExperimentalStroustrup + MultilineBracketStyle = Stroustrup MaxArrayOrListWidth = 40 } [] diff --git a/src/Fantomas.Core.Tests/Stroustrup/LetOrUseBangExpressionTests.fs b/src/Fantomas.Core.Tests/Stroustrup/LetOrUseBangExpressionTests.fs index 9bebd3a3cc..9c1376e62d 100644 --- a/src/Fantomas.Core.Tests/Stroustrup/LetOrUseBangExpressionTests.fs +++ b/src/Fantomas.Core.Tests/Stroustrup/LetOrUseBangExpressionTests.fs @@ -7,7 +7,7 @@ open Fantomas.Core.Tests.TestHelper let config = { config with - MultilineBracketStyle = ExperimentalStroustrup + MultilineBracketStyle = Stroustrup MaxArrayOrListWidth = 40 } [] diff --git a/src/Fantomas.Core.Tests/Stroustrup/LongIdentSetExpressionTests.fs b/src/Fantomas.Core.Tests/Stroustrup/LongIdentSetExpressionTests.fs index aa07affc2c..b8f4f287e9 100644 --- a/src/Fantomas.Core.Tests/Stroustrup/LongIdentSetExpressionTests.fs +++ b/src/Fantomas.Core.Tests/Stroustrup/LongIdentSetExpressionTests.fs @@ -7,7 +7,7 @@ open Fantomas.Core.Tests.TestHelper let config = { config with - MultilineBracketStyle = ExperimentalStroustrup + MultilineBracketStyle = Stroustrup MaxArrayOrListWidth = 40 } [] diff --git a/src/Fantomas.Core.Tests/Stroustrup/MultiLineLambdaClosingNewlineExpressionTests.fs b/src/Fantomas.Core.Tests/Stroustrup/MultiLineLambdaClosingNewlineExpressionTests.fs index d94a51d744..26a92441c8 100644 --- a/src/Fantomas.Core.Tests/Stroustrup/MultiLineLambdaClosingNewlineExpressionTests.fs +++ b/src/Fantomas.Core.Tests/Stroustrup/MultiLineLambdaClosingNewlineExpressionTests.fs @@ -8,7 +8,7 @@ open Fantomas.Core let config = { config with MultiLineLambdaClosingNewline = true - MultilineBracketStyle = ExperimentalStroustrup + MultilineBracketStyle = Stroustrup MaxArrayOrListWidth = 40 } [] diff --git a/src/Fantomas.Core.Tests/Stroustrup/NamedArgumentExpressionTests.fs b/src/Fantomas.Core.Tests/Stroustrup/NamedArgumentExpressionTests.fs index bd7b190baf..2e6a07ead7 100644 --- a/src/Fantomas.Core.Tests/Stroustrup/NamedArgumentExpressionTests.fs +++ b/src/Fantomas.Core.Tests/Stroustrup/NamedArgumentExpressionTests.fs @@ -7,7 +7,7 @@ open Fantomas.Core let config = { config with - MultilineBracketStyle = ExperimentalStroustrup + MultilineBracketStyle = Stroustrup MaxArrayOrListWidth = 40 } [] diff --git a/src/Fantomas.Core.Tests/Stroustrup/SetExpressionTests.fs b/src/Fantomas.Core.Tests/Stroustrup/SetExpressionTests.fs index 5019f4c81c..d175588d89 100644 --- a/src/Fantomas.Core.Tests/Stroustrup/SetExpressionTests.fs +++ b/src/Fantomas.Core.Tests/Stroustrup/SetExpressionTests.fs @@ -7,7 +7,7 @@ open Fantomas.Core let config = { config with - MultilineBracketStyle = ExperimentalStroustrup + MultilineBracketStyle = Stroustrup MaxArrayOrListWidth = 40 } [] diff --git a/src/Fantomas.Core.Tests/Stroustrup/SynBindingFunctionExpressionTests.fs b/src/Fantomas.Core.Tests/Stroustrup/SynBindingFunctionExpressionTests.fs index 5d4a2d4b46..4bef1fbbe4 100644 --- a/src/Fantomas.Core.Tests/Stroustrup/SynBindingFunctionExpressionTests.fs +++ b/src/Fantomas.Core.Tests/Stroustrup/SynBindingFunctionExpressionTests.fs @@ -7,7 +7,7 @@ open Fantomas.Core.Tests.TestHelper let config = { config with - MultilineBracketStyle = ExperimentalStroustrup + MultilineBracketStyle = Stroustrup MaxArrayOrListWidth = 40 } [] diff --git a/src/Fantomas.Core.Tests/Stroustrup/SynBindingFunctionLongPatternExpressionTests.fs b/src/Fantomas.Core.Tests/Stroustrup/SynBindingFunctionLongPatternExpressionTests.fs index 1db23e704e..3c990d3c51 100644 --- a/src/Fantomas.Core.Tests/Stroustrup/SynBindingFunctionLongPatternExpressionTests.fs +++ b/src/Fantomas.Core.Tests/Stroustrup/SynBindingFunctionLongPatternExpressionTests.fs @@ -8,7 +8,7 @@ open Fantomas.Core.Tests.TestHelper let config = { config with MaxLineLength = 80 - MultilineBracketStyle = ExperimentalStroustrup + MultilineBracketStyle = Stroustrup MaxArrayOrListWidth = 40 } // TODO: conclude on what should happen here diff --git a/src/Fantomas.Core.Tests/Stroustrup/SynBindingFunctionWithReturnTypeExpressionTests.fs b/src/Fantomas.Core.Tests/Stroustrup/SynBindingFunctionWithReturnTypeExpressionTests.fs index 46fe7938ca..721d834f4c 100644 --- a/src/Fantomas.Core.Tests/Stroustrup/SynBindingFunctionWithReturnTypeExpressionTests.fs +++ b/src/Fantomas.Core.Tests/Stroustrup/SynBindingFunctionWithReturnTypeExpressionTests.fs @@ -7,7 +7,7 @@ open Fantomas.Core.Tests.TestHelper let config = { config with - MultilineBracketStyle = ExperimentalStroustrup + MultilineBracketStyle = Stroustrup MaxArrayOrListWidth = 40 } [] diff --git a/src/Fantomas.Core.Tests/Stroustrup/SynBindingValueExpressionTests.fs b/src/Fantomas.Core.Tests/Stroustrup/SynBindingValueExpressionTests.fs index d0c0e4c638..0f6eef956c 100644 --- a/src/Fantomas.Core.Tests/Stroustrup/SynBindingValueExpressionTests.fs +++ b/src/Fantomas.Core.Tests/Stroustrup/SynBindingValueExpressionTests.fs @@ -7,7 +7,7 @@ open Fantomas.Core let config = { config with - MultilineBracketStyle = ExperimentalStroustrup + MultilineBracketStyle = Stroustrup MaxArrayOrListWidth = 40 } [] diff --git a/src/Fantomas.Core.Tests/Stroustrup/SynExprAndBangExpressionTests.fs b/src/Fantomas.Core.Tests/Stroustrup/SynExprAndBangExpressionTests.fs index 19f80e7752..d74b31ded0 100644 --- a/src/Fantomas.Core.Tests/Stroustrup/SynExprAndBangExpressionTests.fs +++ b/src/Fantomas.Core.Tests/Stroustrup/SynExprAndBangExpressionTests.fs @@ -7,7 +7,7 @@ open Fantomas.Core.Tests.TestHelper let config = { config with - MultilineBracketStyle = ExperimentalStroustrup + MultilineBracketStyle = Stroustrup MaxArrayOrListWidth = 40 } [] diff --git a/src/Fantomas.Core.Tests/Stroustrup/SynMatchClauseExpressionTests.fs b/src/Fantomas.Core.Tests/Stroustrup/SynMatchClauseExpressionTests.fs index f16e94a968..aa8b9ca295 100644 --- a/src/Fantomas.Core.Tests/Stroustrup/SynMatchClauseExpressionTests.fs +++ b/src/Fantomas.Core.Tests/Stroustrup/SynMatchClauseExpressionTests.fs @@ -7,7 +7,7 @@ open Fantomas.Core let config = { config with - MultilineBracketStyle = ExperimentalStroustrup + MultilineBracketStyle = Stroustrup MaxArrayOrListWidth = 40 } [] diff --git a/src/Fantomas.Core.Tests/Stroustrup/SynTypeDefnSigReprSimpleTests.fs b/src/Fantomas.Core.Tests/Stroustrup/SynTypeDefnSigReprSimpleTests.fs index 2f4698f006..3fdb9c16eb 100644 --- a/src/Fantomas.Core.Tests/Stroustrup/SynTypeDefnSigReprSimpleTests.fs +++ b/src/Fantomas.Core.Tests/Stroustrup/SynTypeDefnSigReprSimpleTests.fs @@ -7,7 +7,7 @@ open Fantomas.Core let config = { config with - MultilineBracketStyle = ExperimentalStroustrup } + MultilineBracketStyle = Stroustrup } [] let ``record type definition`` () = diff --git a/src/Fantomas.Core.Tests/Stroustrup/SynTypeDefnSimpleReprRecordTests.fs b/src/Fantomas.Core.Tests/Stroustrup/SynTypeDefnSimpleReprRecordTests.fs index 8c86841863..fa6cbce5aa 100644 --- a/src/Fantomas.Core.Tests/Stroustrup/SynTypeDefnSimpleReprRecordTests.fs +++ b/src/Fantomas.Core.Tests/Stroustrup/SynTypeDefnSimpleReprRecordTests.fs @@ -7,7 +7,7 @@ open Fantomas.Core let config = { config with - MultilineBracketStyle = ExperimentalStroustrup } + MultilineBracketStyle = Stroustrup } [] let ``record type definition`` () = diff --git a/src/Fantomas.Core.Tests/Stroustrup/YieldOrReturnBangExpressionTests.fs b/src/Fantomas.Core.Tests/Stroustrup/YieldOrReturnBangExpressionTests.fs index 3d61264029..80e58f97fc 100644 --- a/src/Fantomas.Core.Tests/Stroustrup/YieldOrReturnBangExpressionTests.fs +++ b/src/Fantomas.Core.Tests/Stroustrup/YieldOrReturnBangExpressionTests.fs @@ -7,7 +7,7 @@ open Fantomas.Core.Tests.TestHelper let config = { config with - MultilineBracketStyle = ExperimentalStroustrup + MultilineBracketStyle = Stroustrup MaxArrayOrListWidth = 40 } [] diff --git a/src/Fantomas.Core.Tests/Stroustrup/YieldOrReturnExpressionTests.fs b/src/Fantomas.Core.Tests/Stroustrup/YieldOrReturnExpressionTests.fs index 1d7841e7cb..7a859b8610 100644 --- a/src/Fantomas.Core.Tests/Stroustrup/YieldOrReturnExpressionTests.fs +++ b/src/Fantomas.Core.Tests/Stroustrup/YieldOrReturnExpressionTests.fs @@ -7,7 +7,7 @@ open Fantomas.Core.Tests.TestHelper let config = { config with - MultilineBracketStyle = ExperimentalStroustrup + MultilineBracketStyle = Stroustrup MaxArrayOrListWidth = 40 } [] diff --git a/src/Fantomas.Core/CodePrinter.fs b/src/Fantomas.Core/CodePrinter.fs index 787c2917d5..3bc2c8b459 100644 --- a/src/Fantomas.Core/CodePrinter.fs +++ b/src/Fantomas.Core/CodePrinter.fs @@ -502,11 +502,11 @@ let genExpr (e: Expr) = | RecordNodeExtra.With we -> genSingleTextNode node.OpeningBrace +> ifElseCtx - (fun ctx -> ctx.Config.ExperimentalStroustrupStyle) + (fun ctx -> ctx.Config.IsStroustrupStyle) (indent +> sepNln) addSpaceIfSpaceAroundDelimiter +> genCopyExpr fieldsExpr we - +> onlyIfCtx (fun ctx -> ctx.Config.ExperimentalStroustrupStyle) unindent + +> onlyIfCtx (fun ctx -> ctx.Config.IsStroustrupStyle) unindent +> sepNln +> genSingleTextNode node.ClosingBrace | RecordNodeExtra.None -> @@ -633,11 +633,11 @@ let genExpr (e: Expr) = | Some ci -> genSingleTextNodeSuffixDelimiter node.OpeningBrace +> ifElseCtx - (fun ctx -> ctx.Config.ExperimentalStroustrupStyle) + (fun ctx -> ctx.Config.IsStroustrupStyle) (indent +> sepNln) sepNlnWhenWriteBeforeNewlineNotEmpty // comment after curly brace +> genCopyExpr fieldsExpr ci - +> onlyIfCtx (fun ctx -> ctx.Config.ExperimentalStroustrupStyle) unindent + +> onlyIfCtx (fun ctx -> ctx.Config.IsStroustrupStyle) unindent +> sepNln +> genSingleTextNode node.ClosingBrace | None -> @@ -851,7 +851,7 @@ let genExpr (e: Expr) = onlyIf (isMultiline && ctx.Config.MultiLineLambdaClosingNewline - && not (ctx.Config.ExperimentalStroustrupStyle && node.Lambda.Expr.IsStroustrupStyleExpr)) + && not (ctx.Config.IsStroustrupStyle && node.Lambda.Expr.IsStroustrupStyleExpr)) sepNln ctx) +> genSingleTextNode node.ClosingParen @@ -1052,9 +1052,7 @@ let genExpr (e: Expr) = +> onlyIfCtx (fun ctx -> ctx.Config.MultiLineLambdaClosingNewline - && (not ( - ctx.Config.ExperimentalStroustrupStyle && lambdaNode.Expr.IsStroustrupStyleExpr - ))) + && (not (ctx.Config.IsStroustrupStyle && lambdaNode.Expr.IsStroustrupStyleExpr))) sepNln +> genSingleTextNode appParen.Paren.ClosingParen | _ -> @@ -1912,7 +1910,7 @@ let genClause (isLastItem: bool) (node: MatchClauseNode) = ctx) let genPatAndBody ctx = - if ctx.Config.ExperimentalStroustrupStyle && node.BodyExpr.IsStroustrupStyleExpr then + if ctx.Config.IsStroustrupStyle && node.BodyExpr.IsStroustrupStyleExpr then let startColumn = ctx.Column (genPatInClause node.Pattern +> atIndentLevel false startColumn genWhenAndBody) ctx else @@ -2114,7 +2112,7 @@ let genFunctionNameWithMultilineLids (trailing: Context -> Context) (longIdent: |> genNode parentNode let (|EndsWithDualListApp|_|) (config: FormatConfig) (appNode: ExprAppNode) = - if not config.ExperimentalStroustrupStyle then + if not config.IsStroustrupStyle then None else let mutable otherArgs = ListCollector() @@ -2131,7 +2129,7 @@ let (|EndsWithDualListApp|_|) (config: FormatConfig) (appNode: ExprAppNode) = visit appNode.Arguments let (|EndsWithSingleListApp|_|) (config: FormatConfig) (appNode: ExprAppNode) = - if not config.ExperimentalStroustrupStyle then + if not config.IsStroustrupStyle then None else let mutable otherArgs = ListCollector() @@ -2171,9 +2169,7 @@ let genAppWithLambda sep (node: ExprAppWithLambdaNode) = | Choice1Of2 lambdaNode -> genSingleTextNode node.OpeningParen +> (genLambdaWithParen lambdaNode |> genNode lambdaNode) - +> onlyIf - (not (ctx.Config.ExperimentalStroustrupStyle && lambdaNode.Expr.IsStroustrupStyleExpr)) - sepNln + +> onlyIf (not (ctx.Config.IsStroustrupStyle && lambdaNode.Expr.IsStroustrupStyleExpr)) sepNln +> genSingleTextNode node.ClosingParen | Choice2Of2 matchLambdaNode -> genSingleTextNode node.OpeningParen @@ -2196,10 +2192,7 @@ let genAppWithLambda sep (node: ExprAppWithLambdaNode) = (fun isMultiline -> onlyIf (isMultiline - && not ( - ctx.Config.ExperimentalStroustrupStyle - && lambdaNode.Expr.IsStroustrupStyleExpr - )) + && not (ctx.Config.IsStroustrupStyle && lambdaNode.Expr.IsStroustrupStyleExpr)) sepNln +> genSingleTextNode node.ClosingParen) | Choice2Of2 matchLambdaNode -> @@ -3216,9 +3209,9 @@ let genTypeDefn (td: TypeDefn) = +> genMemberDefnList members match ctx.Config.MultilineBracketStyle with - | ExperimentalStroustrup when hasNoMembers -> stroustrupWithoutMembers ctx + | Stroustrup when hasNoMembers -> stroustrupWithoutMembers ctx | Aligned - | ExperimentalStroustrup -> aligned ctx + | Stroustrup -> aligned ctx | Cramped when anyFieldHasXmlDoc -> aligned ctx | Cramped -> cramped ctx @@ -3242,7 +3235,7 @@ let genTypeDefn (td: TypeDefn) = let size = getRecordSize ctx node.Fields let short = bodyExpr size - if ctx.Config.ExperimentalStroustrupStyle && hasNoMembers then + if ctx.Config.IsStroustrupStyle && hasNoMembers then (sepSpace +> short) ctx else isSmallExpression size short (indentSepNlnUnindent short) ctx @@ -3254,7 +3247,7 @@ let genTypeDefn (td: TypeDefn) = fun (ctx: Context) -> (match node.Type with - | Type.AnonRecord _ when not hasMembers && ctx.Config.ExperimentalStroustrupStyle -> + | Type.AnonRecord _ when not hasMembers && ctx.Config.IsStroustrupStyle -> header +> sepSpaceOrIndentAndNlnIfTypeExceedsPageWidthUnlessStroustrup genType node.Type |> genNode node diff --git a/src/Fantomas.Core/Context.fs b/src/Fantomas.Core/Context.fs index a3d1200483..aab18943a8 100644 --- a/src/Fantomas.Core/Context.fs +++ b/src/Fantomas.Core/Context.fs @@ -753,11 +753,7 @@ let sepSpaceOrDoubleIndentAndNlnIfExpressionExceedsPageWidth expr (ctx: Context) ctx let sepSpaceOrIndentAndNlnIfExceedsPageWidthUnlessStroustrup isStroustrup f (node: Node) (ctx: Context) = - if - ctx.Config.ExperimentalStroustrupStyle - && isStroustrup - && Seq.isEmpty node.ContentBefore - then + if ctx.Config.IsStroustrupStyle && isStroustrup && Seq.isEmpty node.ContentBefore then (sepSpace +> f) ctx else sepSpaceOrIndentAndNlnIfExpressionExceedsPageWidth f ctx @@ -866,7 +862,7 @@ let ifAlignOrStroustrupBrackets f g = (fun ctx -> match ctx.Config.MultilineBracketStyle with | Aligned - | ExperimentalStroustrup -> true + | Stroustrup -> true | Cramped -> false) f g @@ -907,7 +903,7 @@ let addParenIfAutoNln expr f = let autoIndentAndNlnExpressUnlessStroustrup (f: Expr -> Context -> Context) (e: Expr) (ctx: Context) = let shouldUseStroustrup = - ctx.Config.ExperimentalStroustrupStyle + ctx.Config.IsStroustrupStyle && e.IsStroustrupStyleExpr && let node = Expr.Node e in Seq.isEmpty node.ContentBefore @@ -919,7 +915,7 @@ let autoIndentAndNlnExpressUnlessStroustrup (f: Expr -> Context -> Context) (e: let autoIndentAndNlnTypeUnlessStroustrup (f: Type -> Context -> Context) (t: Type) (ctx: Context) = let shouldUseStroustrup = - ctx.Config.ExperimentalStroustrupStyle + ctx.Config.IsStroustrupStyle && t.IsStroustrupStyleType && let node = Type.Node t in Seq.isEmpty node.ContentBefore @@ -935,7 +931,7 @@ let autoIndentAndNlnIfExpressionExceedsPageWidthUnlessStroustrup (ctx: Context) = let isStroustrup = - ctx.Config.ExperimentalStroustrupStyle + ctx.Config.IsStroustrupStyle && e.IsStroustrupStyleExpr && Seq.isEmpty (Expr.Node e).ContentBefore diff --git a/src/Fantomas.Core/FormatConfig.fs b/src/Fantomas.Core/FormatConfig.fs index 115e0b4dea..c48992f4e7 100644 --- a/src/Fantomas.Core/FormatConfig.fs +++ b/src/Fantomas.Core/FormatConfig.fs @@ -26,19 +26,20 @@ type MultilineFormatterType = type MultilineBracketStyle = | Cramped | Aligned - | ExperimentalStroustrup + | Stroustrup static member ToConfigString(cfg: MultilineBracketStyle) = match cfg with | Cramped -> "cramped" | Aligned -> "aligned" - | ExperimentalStroustrup -> "experimental_stroustrup" + | Stroustrup -> "stroustrup" static member OfConfigString(cfgString: string) = match cfgString with | "cramped" -> Some Cramped | "aligned" -> Some Aligned - | "experimental_stroustrup" -> Some ExperimentalStroustrup + | "experimental_stroustrup" -> Some Stroustrup // TODO: Should we keep this working or just drop this altogether + | "stroustrup" -> Some Stroustrup | _ -> None [] @@ -210,8 +211,8 @@ type FormatConfig = BarBeforeDiscriminatedUnionDeclaration: bool [] - [] - [] + [] + [] MultilineBracketStyle: MultilineBracketStyle [] @@ -223,7 +224,7 @@ type FormatConfig = [] StrictMode: bool } - member x.ExperimentalStroustrupStyle = x.MultilineBracketStyle = ExperimentalStroustrup + member x.IsStroustrupStyle = x.MultilineBracketStyle = Stroustrup static member Default = { IndentSize = 4 diff --git a/src/Fantomas.Tests/EditorConfigurationTests.fs b/src/Fantomas.Tests/EditorConfigurationTests.fs index 45158793b0..5cdcbb1adc 100644 --- a/src/Fantomas.Tests/EditorConfigurationTests.fs +++ b/src/Fantomas.Tests/EditorConfigurationTests.fs @@ -464,7 +464,7 @@ fsharp_multiline_bracket_style = experimental_stroustrup let config = EditorConfig.readConfiguration fsharpFile.FSharpFile - Assert.AreEqual(ExperimentalStroustrup, config.MultilineBracketStyle) + Assert.AreEqual(Stroustrup, config.MultilineBracketStyle) [] let ``fsharp_multiline_bracket_style = aligned`` () = From 0f32f15d39d5ebde4f1436d1ae54db8b4f6c4286 Mon Sep 17 00:00:00 2001 From: Josh DeGraw Date: Tue, 31 Jan 2023 11:47:04 -0700 Subject: [PATCH 2/3] Update docs --- docs/docs/end-users/Configuration.fsx | 12 ++++++------ fantomas.sln | 1 + 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/docs/docs/end-users/Configuration.fsx b/docs/docs/end-users/Configuration.fsx index b7a2c394a1..81ab27540f 100644 --- a/docs/docs/end-users/Configuration.fsx +++ b/docs/docs/end-users/Configuration.fsx @@ -28,7 +28,7 @@ fsharp_bar_before_discriminated_union_declaration = true #\ Apply specific settings for a targeted subfolder [src/Elmish/View.fs] -fsharp_multiline_bracket_style = experimental_stroustrup +fsharp_multiline_bracket_style = stroustrup ``` *) @@ -39,9 +39,9 @@ You can quickly try your settings via the *) -#r "nuget: Fantomas.Core, 5.2.0-alpha-012" +#r "../../../src/Fantomas.Core/bin/Release/netstandard2.0/Fantomas.FCS.dll" +#r "../../../src/Fantomas.Core/bin/Release/netstandard2.0/Fantomas.Core.dll" -open Fantomas.Core.FormatConfig open Fantomas.Core let formatCode input configIndent = @@ -63,7 +63,7 @@ However, there are settings that we do not recommend and generally should not be -` indent_size` has to be between 1 and 10. +`indent_size` has to be between 1 and 10. This preference sets the indentation The common values are 2 and 4. @@ -576,7 +576,7 @@ formatCode `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. -`ExperimentalStroustrup` Please contribute to [fsprojects/fantomas#1408](https://github.com/fsprojects/fantomas/issues/1408) and engage in [fsharp/fslang-design#706](https://github.com/fsharp/fslang-design/issues/706). +`Stroustrup` Please contribute to [fsprojects/fantomas#1408](https://github.com/fsprojects/fantomas/issues/1408) and engage in [fsharp/fslang-design#706](https://github.com/fsharp/fslang-design/issues/706). Default = Cramped. *) @@ -632,7 +632,7 @@ formatCode (19, 20, 21) |] """ { FormatConfig.Default with - MultilineBracketStyle = ExperimentalStroustrup } + MultilineBracketStyle = Stroustrup } (*** include-it ***) (** diff --git a/fantomas.sln b/fantomas.sln index d1b1f4ad68..5e8c33d462 100644 --- a/fantomas.sln +++ b/fantomas.sln @@ -16,6 +16,7 @@ EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "docs", "docs", "{29F22904-C9E0-40AA-B971-9AE377C17F59}" ProjectSection(SolutionItems) = preProject docs\index.html = docs\index.html + docs\docs\end-users\Configuration.fsx = docs\docs\end-users\Configuration.fsx EndProjectSection EndProject Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "Fantomas.Client", "src\Fantomas.Client\Fantomas.Client.fsproj", "{AA895F94-CCF2-4FCF-A9BB-E16987B57535}" From 6bdc3e0a47f00557ac1e0815617006dd9231ddc3 Mon Sep 17 00:00:00 2001 From: nojaf Date: Wed, 1 Feb 2023 09:04:30 +0100 Subject: [PATCH 3/3] Remove experimental_stroustrup, Configuration.fsx tweaks. --- docs/docs/end-users/Configuration.fsx | 88 ++++++++++--------- src/Fantomas.Core/FormatConfig.fs | 1 - .../EditorConfigurationTests.fs | 4 +- 3 files changed, 49 insertions(+), 44 deletions(-) diff --git a/docs/docs/end-users/Configuration.fsx b/docs/docs/end-users/Configuration.fsx index 81ab27540f..72501fc13e 100644 --- a/docs/docs/end-users/Configuration.fsx +++ b/docs/docs/end-users/Configuration.fsx @@ -15,6 +15,12 @@ Your IDE should respect your settings, however the implementation of that is edi UI might be available depending on the IDE. *) +#r "../../../src/Fantomas/bin/Release/net6.0/Fantomas.FCS.dll" +#r "../../../src/Fantomas/bin/Release/net6.0/Fantomas.Core.dll" + +printf $"version: {Fantomas.Core.CodeFormatter.GetVersion()}" +(*** include-output ***) + (** ## Usage Inside .editorconfig you can specify the file extension and code location to be use per config: @@ -39,13 +45,13 @@ You can quickly try your settings via the *) -#r "../../../src/Fantomas.Core/bin/Release/netstandard2.0/Fantomas.FCS.dll" -#r "../../../src/Fantomas.Core/bin/Release/netstandard2.0/Fantomas.Core.dll" - open Fantomas.Core let formatCode input configIndent = - CodeFormatter.FormatDocumentAsync(false, input, configIndent) + async { + let! result = CodeFormatter.FormatDocumentAsync(false, input, configIndent) + printf $"%s{result.Code}" + } |> Async.RunSynchronously (** @@ -87,7 +93,7 @@ formatCode """ { FormatConfig.Default with IndentSize = 2 } -(*** include-it ***) +(*** include-output ***) (** @@ -105,7 +111,7 @@ formatCode """ { FormatConfig.Default with MaxLineLength = 60 } -(*** include-it ***) +(*** include-output ***) (** @@ -130,7 +136,7 @@ formatCode """ { FormatConfig.Default with InsertFinalNewline = false } -(*** include-it ***) +(*** include-output ***) (** @@ -148,7 +154,7 @@ formatCode """ { FormatConfig.Default with SpaceBeforeParameter = false } -(*** include-it ***) +(*** include-output ***) (** @@ -169,7 +175,7 @@ match x with """ { FormatConfig.Default with SpaceBeforeLowercaseInvocation = false } -(*** include-it ***) +(*** include-output ***) (** @@ -190,7 +196,7 @@ match x with """ { FormatConfig.Default with SpaceBeforeUppercaseInvocation = true } -(*** include-it ***) +(*** include-output ***) (** @@ -209,7 +215,7 @@ formatCode { FormatConfig.Default with SpaceBeforeClassConstructor = true } -(*** include-it ***) +(*** include-output ***) (** @@ -229,7 +235,7 @@ formatCode """ { FormatConfig.Default with SpaceBeforeMember = true } -(*** include-it ***) +(*** include-output ***) (** @@ -247,7 +253,7 @@ formatCode """ { FormatConfig.Default with SpaceBeforeColon = true } -(*** include-it ***) +(*** include-output ***) (** @@ -264,7 +270,7 @@ formatCode """ { FormatConfig.Default with SpaceAfterComma = false } -(*** include-it ***) +(*** include-output ***) (** @@ -282,7 +288,7 @@ formatCode """ { FormatConfig.Default with SpaceBeforeSemicolon = true } -(*** include-it ***) +(*** include-output ***) (** @@ -300,7 +306,7 @@ formatCode """ { FormatConfig.Default with SpaceAfterSemicolon = false } -(*** include-it ***) +(*** include-output ***) (** @@ -317,7 +323,7 @@ formatCode """ { FormatConfig.Default with SpaceAroundDelimiter = false } -(*** include-it ***) +(*** include-output ***) (** ## Maximum width constraints @@ -341,7 +347,7 @@ formatCode """ { FormatConfig.Default with MaxIfThenShortWidth = 15 } -(*** include-it ***) +(*** include-output ***) (** @@ -358,7 +364,7 @@ formatCode """ { FormatConfig.Default with MaxIfThenElseShortWidth = 10 } -(*** include-it ***) +(*** include-output ***) (** @@ -374,7 +380,7 @@ formatCode """ { FormatConfig.Default with MaxInfixOperatorExpression = 20 } -(*** include-it ***) +(*** include-output ***) (** @@ -393,7 +399,7 @@ formatCode """ { FormatConfig.Default with MaxRecordWidth = 20 } -(*** include-it ***) +(*** include-output ***) (** @@ -425,7 +431,7 @@ formatCode { FormatConfig.Default with MaxRecordNumberOfItems = 2 RecordMultilineFormatter = MultilineFormatterType.NumberOfItems } -(*** include-it ***) +(*** include-output ***) (** @@ -453,7 +459,7 @@ formatCode """ { FormatConfig.Default with RecordMultilineFormatter = MultilineFormatterType.NumberOfItems } -(*** include-it ***) +(*** include-output ***) (** @@ -471,7 +477,7 @@ formatCode """ { FormatConfig.Default with MaxArrayOrListWidth = 20 } -(*** include-it ***) +(*** include-output ***) (** @@ -491,7 +497,7 @@ formatCode { FormatConfig.Default with MaxArrayOrListNumberOfItems = 2 ArrayOrListMultilineFormatter = MultilineFormatterType.NumberOfItems } -(*** include-it ***) +(*** include-output ***) (** @@ -511,7 +517,7 @@ formatCode """ { FormatConfig.Default with ArrayOrListMultilineFormatter = MultilineFormatterType.NumberOfItems } -(*** include-it ***) +(*** include-output ***) (** @@ -530,7 +536,7 @@ formatCode """ { FormatConfig.Default with MaxValueBindingWidth = 10 } -(*** include-it ***) +(*** include-output ***) (** @@ -549,7 +555,7 @@ formatCode """ { FormatConfig.Default with MaxFunctionBindingWidth = 10 } -(*** include-it ***) +(*** include-output ***) (** @@ -569,14 +575,14 @@ formatCode """ { FormatConfig.Default with MaxDotGetExpressionWidth = 100 } -(*** include-it ***) +(*** include-output ***) (** `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. -`Stroustrup` Please contribute to [fsprojects/fantomas#1408](https://github.com/fsprojects/fantomas/issues/1408) and engage in [fsharp/fslang-design#706](https://github.com/fsharp/fslang-design/issues/706). +`Stroustrup` Allow for easier reordering of members and keeping the code succinct. Default = Cramped. *) @@ -606,7 +612,7 @@ formatCode """ { FormatConfig.Default with MultilineBracketStyle = Aligned } -(*** include-it ***) +(*** include-output ***) formatCode """ @@ -633,7 +639,7 @@ formatCode """ { FormatConfig.Default with MultilineBracketStyle = Stroustrup } -(*** include-it ***) +(*** include-output ***) (** ## G-Research style @@ -657,7 +663,7 @@ type Range = """ { FormatConfig.Default with NewlineBetweenTypeDefinitionAndMembers = true } -(*** include-it ***) +(*** include-output ***) (** @@ -679,7 +685,7 @@ let run """ { FormatConfig.Default with AlignFunctionSignatureToIndentation = true } -(*** include-it ***) +(*** include-output ***) (** @@ -712,7 +718,7 @@ type D() = """ { FormatConfig.Default with AlternativeLongMemberDefinitions = true } -(*** include-it ***) +(*** include-output ***) (** @@ -740,7 +746,7 @@ let printListWithOffset a list1 = """ { FormatConfig.Default with MultiLineLambdaClosingNewline = true } -(*** include-it ***) +(*** include-output ***) (** @@ -770,7 +776,7 @@ let main argv = """ { FormatConfig.Default with ExperimentalKeepIndentInBranch = true } -(*** include-it ***) +(*** include-output ***) (** @@ -788,7 +794,7 @@ formatCode { FormatConfig.Default with BarBeforeDiscriminatedUnionDeclaration = true } -(*** include-it ***) +(*** include-output ***) (** ## Other @@ -822,7 +828,7 @@ formatCode """ { FormatConfig.Default with BlankLinesAroundNestedMultilineExpressions = false } -(*** include-it ***) +(*** include-output ***) (** @@ -840,7 +846,7 @@ formatCode """ { FormatConfig.Default with KeepMaxNumberOfBlankLines = 1 } -(*** include-it ***) +(*** include-output ***) (** @@ -867,7 +873,7 @@ formatCode """ { FormatConfig.Default with StrictMode = true } -(*** include-it ***) +(*** include-output ***) (** diff --git a/src/Fantomas.Core/FormatConfig.fs b/src/Fantomas.Core/FormatConfig.fs index c48992f4e7..b62da15643 100644 --- a/src/Fantomas.Core/FormatConfig.fs +++ b/src/Fantomas.Core/FormatConfig.fs @@ -38,7 +38,6 @@ type MultilineBracketStyle = match cfgString with | "cramped" -> Some Cramped | "aligned" -> Some Aligned - | "experimental_stroustrup" -> Some Stroustrup // TODO: Should we keep this working or just drop this altogether | "stroustrup" -> Some Stroustrup | _ -> None diff --git a/src/Fantomas.Tests/EditorConfigurationTests.fs b/src/Fantomas.Tests/EditorConfigurationTests.fs index 5cdcbb1adc..7eadffe4cb 100644 --- a/src/Fantomas.Tests/EditorConfigurationTests.fs +++ b/src/Fantomas.Tests/EditorConfigurationTests.fs @@ -448,13 +448,13 @@ insert_final_newline = false Assert.IsFalse config.InsertFinalNewline [] -let ``fsharp_multiline_bracket_style = experimental_stroustrup`` () = +let ``fsharp_multiline_bracket_style = stroustrup`` () = let rootDir = tempName () let editorConfig = """ [*.fs] -fsharp_multiline_bracket_style = experimental_stroustrup +fsharp_multiline_bracket_style = stroustrup """ use configFixture =