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 Mar 27, 2023
1 parent 6933b99 commit 3d03227
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 109 deletions.
84 changes: 46 additions & 38 deletions docs/docs/end-users/Configuration.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,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 All @@ -55,15 +55,15 @@ However, there are settings that we do not recommend and generally should not be
<p><fantomas-setting-icon type="green"></fantomas-setting-icon><strong>Safe to change:</strong> 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.</p>
<p><fantomas-setting-icon type="orange"></fantomas-setting-icon><strong>Use with caution:</strong> Settings where it is not recommended to change the default value. They might lead to incomplete results.</p>
<p><fantomas-setting-icon type="red"></fantomas-setting-icon><strong>Do not use:</strong> Settings that don't follow any guidelines.</p>
<p><fantomas-setting-icon type="gr"></fantomas-setting-icon><strong>G-Research:</strong> G-Research styling guide. If you use one of these, for consistency reasons you should use all of them.</p>
<p><fantomas-setting-icon-gresearch></fantomas-setting-icon-gresearch><strong>G-Research:</strong> G-Research styling guide. If you use one of these, for consistency reasons you should use all of them.</p>
*)

(**
## Auxiliary settings
<fantomas-setting name="indent_size" orange></fantomas-setting>
`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.
Expand Down Expand Up @@ -572,56 +572,64 @@ formatCode
(*** include-it ***)

(**
<fantomas-setting name="fsharp_multiline_bracket_style" green></fantomas-setting>
<fantomas-setting name="fsharp_multiline_bracket_style" green gr></fantomas-setting>
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 }
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 3d03227

Please sign in to comment.