Skip to content

Commit

Permalink
Sunset MultilineBlockBracketsOnSameColumn & ExperimentalStroustrupSty…
Browse files Browse the repository at this point in the history
…le (#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
  • Loading branch information
dawedawe authored and nojaf committed Jan 24, 2023
1 parent b015ce0 commit ac3b07b
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 103 deletions.
71 changes: 39 additions & 32 deletions docs/docs/end-users/Configuration.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
*)

Expand All @@ -40,7 +39,7 @@ You can quickly try your settings via the <a href="https://fsprojects.github.io/
<img src="{{root}}/online_tool_usage.gif" alt="drawing" width="100%"/>
*)

#r "nuget: Fantomas.Core, 5.*"
#r "nuget: Fantomas.Core, 5.2.0-alpha-012"

open Fantomas.Core.FormatConfig
open Fantomas.Core
Expand Down Expand Up @@ -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.
<fantomas-setting name="fsharp_multiline_bracket_style" green gr></fantomas-setting>
<fantomas-setting name="fsharp_multiline_block_brackets_on_same_column" green gr></fantomas-setting>
`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
Expand Down Expand Up @@ -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.
<fantomas-setting name="fsharp_newline_between_type_definition_and_members" green gr></fantomas-setting>
Adds a new line between a type definition and its first member.
Expand Down Expand Up @@ -767,27 +795,6 @@ formatCode
Some additional settings that don't fit into any style guide.
<fantomas-setting name="fsharp_experimental_stroustrup_style" orange></fantomas-setting>
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 ***)

(**
<fantomas-setting name="fsharp_blank_lines_around_nested_multiline_expressions" green></fantomas-setting>
Surround **nested** multi-line expressions with blank lines.
Expand Down
3 changes: 1 addition & 2 deletions docs/docs/end-users/Rider.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,14 @@ 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
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
```
Expand Down
39 changes: 0 additions & 39 deletions src/Fantomas.Tests/EditorConfigurationTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -448,26 +448,6 @@ insert_final_newline = false

Assert.IsFalse config.InsertFinalNewline

[<Test>]
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)

[<Test>]
let ``fsharp_multiline_bracket_style = experimental_stroustrup`` () =
let rootDir = tempName ()
Expand Down Expand Up @@ -524,22 +504,3 @@ fsharp_multiline_bracket_style = cramped
let config = EditorConfig.readConfiguration fsharpFile.FSharpFile

Assert.AreEqual(Cramped, config.MultilineBracketStyle)

[<Test>]
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)
31 changes: 1 addition & 30 deletions src/Fantomas/EditorConfig.fs
Original file line number Diff line number Diff line change
Expand Up @@ -75,24 +75,6 @@ let private (|Boolean|_|) b =
elif b = "false" then Some(box false)
else None

let private (|OldStroustrup|OldAligned|Unspecified|) (input: IReadOnlyDictionary<string, string>) =
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<string, string>)
Expand All @@ -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
Expand Down

0 comments on commit ac3b07b

Please sign in to comment.