From ac3b07bfc454fabcb6f2ea5d8cad2f279abc5d00 Mon Sep 17 00:00:00 2001 From: dawe Date: Fri, 20 Jan 2023 09:02:50 +0100 Subject: [PATCH] Sunset MultilineBlockBracketsOnSameColumn & ExperimentalStroustrupStyle (#2728) * Extend logging and verbosity options (#2693) * First stab at logging. --verbosity d should be the same as in the past --verbosity n should be pretty quiet * Make use of Serilog * improve test specificity * add log messages about count of processed files * Use interpolated strings for all logger functions. Change some logs to be error logs. * remove MultilineBlockBracketsOnSameColumn & ExperimentalStroustrupStyle from src/ * remove MultilineBlockBracketsOnSameColumn & ExperimentalStroustrupStyle from Rider.md * remove MultilineBlockBracketsOnSameColumn & ExperimentalStroustrupStyle from Configuration.fsx * remove orange (use with caution) marker from fsharp_multiline_bracket_style --- docs/docs/end-users/Configuration.fsx | 71 ++++++++++--------- docs/docs/end-users/Rider.md | 3 +- .../EditorConfigurationTests.fs | 39 ---------- src/Fantomas/EditorConfig.fs | 31 +------- 4 files changed, 41 insertions(+), 103 deletions(-) diff --git a/docs/docs/end-users/Configuration.fsx b/docs/docs/end-users/Configuration.fsx index bc5ee77f2a..d36fa21e6d 100644 --- a/docs/docs/end-users/Configuration.fsx +++ b/docs/docs/end-users/Configuration.fsx @@ -28,8 +28,7 @@ fsharp_bar_before_discriminated_union_declaration = true #\ Apply specific settings for a targeted subfolder [src/Elmish/View.fs] -fsharp_multiline_block_brackets_on_same_column = true -fsharp_experimental_stroustrup_style = true +fsharp_multiline_bracket_style = experimental_stroustrup ``` *) @@ -40,7 +39,7 @@ You can quickly try your settings via the *) -#r "nuget: Fantomas.Core, 5.*" +#r "nuget: Fantomas.Core, 5.2.0-alpha-012" open Fantomas.Core.FormatConfig open Fantomas.Core @@ -573,16 +572,13 @@ formatCode (*** include-it ***) (** -## G-Research style - -A series of settings required to conform with the [G-Research style guide](https://github.com/G-Research/fsharp-formatting-conventions). -From a consistency point of view, it is recommend to enable all these settings instead of cherry-picking a few. + - +`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). -Alternative way of formatting records, arrays and lists. This will align the braces at the same column level. - -Default = false. +Default = Cramped. *) formatCode @@ -612,7 +608,39 @@ formatCode MultilineBracketStyle = Aligned } (*** include-it ***) +formatCode + """ + let myRecord = + { Level = 1 + Progress = "foo" + Bar = "bar" + Street = "Bakerstreet" + Number = 42 } + + type Range = + { From: float + To: float + FileName: string } + + let a = + [| (1, 2, 3) + (4, 5, 6) + (7, 8, 9) + (10, 11, 12) + (13, 14, 15) + (16, 17,18) + (19, 20, 21) |] + """ + { FormatConfig.Default with + MultilineBracketStyle = ExperimentalStroustrup } +(*** include-it ***) + (** +## G-Research style + +A series of settings required to conform with the [G-Research style guide](https://github.com/G-Research/fsharp-formatting-conventions). +From a consistency point of view, it is recommend to enable all these settings instead of cherry-picking a few. + Adds a new line between a type definition and its first member. @@ -767,27 +795,6 @@ formatCode Some additional settings that don't fit into any style guide. - - -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 = false. - -Requires `fsharp_multiline_block_brackets_on_same_column` to be `true` to take effect. -*) - -formatCode - """ -type PostalAddress = - { Address: string - City: string - Zip: string } -""" - { FormatConfig.Default with - MultilineBracketStyle = MultilineBracketStyle.ExperimentalStroustrup } -(*** include-it ***) - -(** Surround **nested** multi-line expressions with blank lines. diff --git a/docs/docs/end-users/Rider.md b/docs/docs/end-users/Rider.md index 3d77eba68b..bf97231beb 100644 --- a/docs/docs/end-users/Rider.md +++ b/docs/docs/end-users/Rider.md @@ -46,7 +46,7 @@ fsharp_array_or_list_multiline_formatter=character_width fsharp_max_value_binding_width=80 fsharp_max_function_binding_width=40 fsharp_max_dot_get_expression_width=80 -fsharp_multiline_block_brackets_on_same_column=false +fsharp_multiline_bracket_style = cramped fsharp_newline_between_type_definition_and_members=true fsharp_align_function_signature_to_indentation=false fsharp_alternative_long_member_definitions=false @@ -54,7 +54,6 @@ fsharp_multi_line_lambda_closing_newline=false fsharp_experimental_keep_indent_in_branch=false fsharp_blank_lines_around_nested_multiline_expressions=true fsharp_bar_before_discriminated_union_declaration=false -fsharp_experimental_stroustrup_style=false fsharp_keep_max_number_of_blank_lines=100 fsharp_strict_mode=false ``` diff --git a/src/Fantomas.Tests/EditorConfigurationTests.fs b/src/Fantomas.Tests/EditorConfigurationTests.fs index 962fd81924..eda9023e31 100644 --- a/src/Fantomas.Tests/EditorConfigurationTests.fs +++ b/src/Fantomas.Tests/EditorConfigurationTests.fs @@ -448,26 +448,6 @@ insert_final_newline = false Assert.IsFalse config.InsertFinalNewline -[] -let ``fsharp_experimental_stroustrup_style = true`` () = - let rootDir = tempName () - - let editorConfig = - """ -[*.fs] -fsharp_multiline_block_brackets_on_same_column = true -fsharp_experimental_stroustrup_style = true -""" - - use configFixture = - new ConfigurationFile(defaultConfig, rootDir, content = editorConfig) - - use fsharpFile = new FSharpFile(rootDir) - - let config = EditorConfig.readConfiguration fsharpFile.FSharpFile - - Assert.AreEqual(ExperimentalStroustrup, config.MultilineBracketStyle) - [] let ``fsharp_multiline_bracket_style = experimental_stroustrup`` () = let rootDir = tempName () @@ -524,22 +504,3 @@ fsharp_multiline_bracket_style = cramped let config = EditorConfig.readConfiguration fsharpFile.FSharpFile Assert.AreEqual(Cramped, config.MultilineBracketStyle) - -[] -let ``fsharp_multiline_block_brackets_on_same_column = true`` () = - let rootDir = tempName () - - let editorConfig = - """ -[*.fs] -fsharp_multiline_block_brackets_on_same_column = true -""" - - use configFixture = - new ConfigurationFile(defaultConfig, rootDir, content = editorConfig) - - use fsharpFile = new FSharpFile(rootDir) - - let config = EditorConfig.readConfiguration fsharpFile.FSharpFile - - Assert.AreEqual(Aligned, config.MultilineBracketStyle) diff --git a/src/Fantomas/EditorConfig.fs b/src/Fantomas/EditorConfig.fs index 41870ece44..39e6f4826c 100644 --- a/src/Fantomas/EditorConfig.fs +++ b/src/Fantomas/EditorConfig.fs @@ -75,24 +75,6 @@ let private (|Boolean|_|) b = elif b = "false" then Some(box false) else None -let private (|OldStroustrup|OldAligned|Unspecified|) (input: IReadOnlyDictionary) = - let toOption = - function - | true, "true" -> Some true - | true, "false" -> Some false - | _ -> None - - let hasStroustrup = - input.TryGetValue("fsharp_experimental_stroustrup_style") |> toOption - - let hasAligned = - input.TryGetValue("fsharp_multiline_block_brackets_on_same_column") |> toOption - - match hasAligned, hasStroustrup with - | Some true, Some true -> OldStroustrup - | Some true, _ -> OldAligned - | _ -> Unspecified - let parseOptionsFromEditorConfig (fallbackConfig: FormatConfig) (editorConfigProperties: IReadOnlyDictionary) @@ -109,18 +91,7 @@ let parseOptionsFromEditorConfig |> fun newValues -> let formatConfigType = FormatConfig.Default.GetType() - - let config = - Microsoft.FSharp.Reflection.FSharpValue.MakeRecord(formatConfigType, newValues) :?> FormatConfig - - match editorConfigProperties with - | Unspecified -> config - | OldStroustrup -> - { config with - MultilineBracketStyle = ExperimentalStroustrup } - | OldAligned -> - { config with - MultilineBracketStyle = Aligned } + Microsoft.FSharp.Reflection.FSharpValue.MakeRecord(formatConfigType, newValues) :?> FormatConfig let configToEditorConfig (config: FormatConfig) : string = Reflection.getRecordFields config