From 3d032274ea46c9a27fa8fb92447704faa665b8e1 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 | 84 ++++++++++--------- docs/docs/end-users/Rider.md | 3 +- .../EditorConfigurationTests.fs | 39 --------- src/Fantomas/EditorConfig.fs | 31 +------ 4 files changed, 48 insertions(+), 109 deletions(-) diff --git a/docs/docs/end-users/Configuration.fsx b/docs/docs/end-users/Configuration.fsx index a4af68e244..d36fa21e6d 100644 --- a/docs/docs/end-users/Configuration.fsx +++ b/docs/docs/end-users/Configuration.fsx @@ -39,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 @@ -55,7 +55,7 @@ However, there are settings that we do not recommend and generally should not be

Safe to change: Settings that aren't attached to any guidelines. Depending on your team or your own preferences, feel free to change these as it's been agreed on the codebase, however, you can always use it's defaults.

Use with caution: Settings where it is not recommended to change the default value. They might lead to incomplete results.

Do not use: Settings that don't follow any guidelines.

-

G-Research: G-Research styling guide. If you use one of these, for consistency reasons you should use all of them.

+

G-Research: G-Research styling guide. If you use one of these, for consistency reasons you should use all of them.

*) (** @@ -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. @@ -572,56 +572,64 @@ formatCode (*** include-it ***) (** - + -How to format bracketted expressions (e.g. records, arrays, lists, etc.) that span multiple lines. +`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). -_This setting replaces the deprecated settings `fsharp_multiline_block_brackets_on_same_column` and `fsharp_experimental_stroustrup_style`._ - -Possible values: - -* `cramped` -* `aligned` -* `experimental_stroustrup` - -Default = `cramped`. +Default = Cramped. *) -(** -**Cramped** - The default way in F# to format brackets. -*) formatCode """ - let band = { Vocals = "John"; Bass = "Paul"; Guitar = "George"; Drums = "Ringo" } - let songs = [ "Come Together"; "Hey Jude"; "Yesterday"; "Yellow Submarine"; "Here Comes the Sun" ] - """ - { FormatConfig.Default with - MultilineBracketStyle = Cramped } -(*** include-it ***) + let myRecord = + { Level = 1 + Progress = "foo" + Bar = "bar" + Street = "Bakerstreet" + Number = 42 } -(** -**Aligned** - Alternative way of formatting brackets. This will align the braces at the same column level. -*) + type Range = + { From: float + To: float + FileName: string } -formatCode - """ - let band = { Vocals = "John"; Bass = "Paul"; Guitar = "George"; Drums = "Ringo" } - let songs = [ "Come Together"; "Hey Jude"; "Yesterday"; "Yellow Submarine"; "Here Comes the Sun" ] + 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 = Aligned } (*** include-it ***) -(** -**ExperimentalStroustrup** - Experimental setting. Places the opening brace on the same line as the binding, and the closing brace on its own line. - -_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)._ -*) - formatCode """ - let band = { Vocals = "John"; Bass = "Paul"; Guitar = "George"; Drums = "Ringo" } - let songs = [ "Come Together"; "Hey Jude"; "Yesterday"; "Yellow Submarine"; "Here Comes the Sun" ] + 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 } 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