diff --git a/fake-sample/script.fsx b/fake-sample/script.fsx index 440903232c..9a08fc32d0 100644 --- a/fake-sample/script.fsx +++ b/fake-sample/script.fsx @@ -11,33 +11,29 @@ open Fake.DotNet let sourceFiles = !! "*.fs" -Target.create - "CheckFormat" - (fun _ -> - let result = - sourceFiles - |> Seq.map (sprintf "\"%s\"") - |> String.concat " " - |> sprintf "%s --check" - |> DotNet.exec id "fantomas" +Target.create "CheckFormat" (fun _ -> + let result = + sourceFiles + |> Seq.map (sprintf "\"%s\"") + |> String.concat " " + |> sprintf "%s --check" + |> DotNet.exec id "fantomas" - if result.ExitCode = 0 then - Trace.log "No files need formatting" - elif result.ExitCode = 99 then - failwith "Some files need formatting, check output for more info" - else - Trace.logf "Errors while formatting: %A" result.Errors) + if result.ExitCode = 0 then + Trace.log "No files need formatting" + elif result.ExitCode = 99 then + failwith "Some files need formatting, check output for more info" + else + Trace.logf "Errors while formatting: %A" result.Errors) -Target.create - "Format" - (fun _ -> - let result = - sourceFiles - |> Seq.map (sprintf "\"%s\"") - |> String.concat " " - |> DotNet.exec id "fantomas" +Target.create "Format" (fun _ -> + let result = + sourceFiles + |> Seq.map (sprintf "\"%s\"") + |> String.concat " " + |> DotNet.exec id "fantomas" - if not result.OK then - printfn "Errors while formatting all files: %A" result.Messages) + if not result.OK then + printfn "Errors while formatting all files: %A" result.Messages) Target.runOrList () diff --git a/src/Fantomas.Core/FormatConfig.fs b/src/Fantomas.Core/FormatConfig.fs index e2abad7247..5c41e92ad3 100644 --- a/src/Fantomas.Core/FormatConfig.fs +++ b/src/Fantomas.Core/FormatConfig.fs @@ -26,6 +26,21 @@ type MultilineFormatterType = | "number_of_items" -> Some MultilineFormatterType.NumberOfItems | _ -> None +type PatternMatchStyle = + | LineSpecific + | Consistent + + static member ToConfigString(cfg: PatternMatchStyle) = + match cfg with + | LineSpecific -> "line_specific" + | Consistent -> "consistent" + + static member OfConfigString(cfgString: string) = + match cfgString with + | "line_specific" -> Some LineSpecific + | "consistent" -> Some Consistent + | _ -> None + type MultilineBracketStyle = | Cramped | Aligned @@ -227,7 +242,12 @@ type FormatConfig = [] [] - ExperimentalElmish: bool } + ExperimentalElmish: bool + + [] + [] + [] + ExperimentalPatternMatchStyle: PatternMatchStyle } member x.IsStroustrupStyle = x.MultilineBracketStyle = Stroustrup @@ -268,4 +288,5 @@ type FormatConfig = MultilineBracketStyle = Cramped KeepMaxNumberOfBlankLines = 100 NewlineBeforeMultilineComputationExpression = true - ExperimentalElmish = false } + ExperimentalElmish = false + ExperimentalPatternMatchStyle = LineSpecific } diff --git a/src/Fantomas.Tests/EditorConfigurationTests.fs b/src/Fantomas.Tests/EditorConfigurationTests.fs index 6c00fdc2a3..c890f5529a 100644 --- a/src/Fantomas.Tests/EditorConfigurationTests.fs +++ b/src/Fantomas.Tests/EditorConfigurationTests.fs @@ -543,3 +543,22 @@ fsharp_experimental_elmish = true let config = EditorConfig.readConfiguration fsharpFile.FSharpFile Assert.That(config.ExperimentalElmish, Is.True) + +[] +let fsharp_consistent_pattern_matching_style () = + let rootDir = tempName () + + let editorConfig = + """ +[*.fs] +fsharp_experimental_pattern_match_style = consistent +""" + + use configFixture = + new ConfigurationFile(defaultConfig, rootDir, content = editorConfig) + + use fsharpFile = new FSharpFile(rootDir) + + let config = EditorConfig.readConfiguration fsharpFile.FSharpFile + + Assert.That(config.ExperimentalPatternMatchStyle, Is.EqualTo Consistent) diff --git a/src/Fantomas/EditorConfig.fs b/src/Fantomas/EditorConfig.fs index f362fe4ba6..04ca628612 100644 --- a/src/Fantomas/EditorConfig.fs +++ b/src/Fantomas/EditorConfig.fs @@ -64,6 +64,8 @@ let (|Number|_|) (d: string) = | true, d -> Some(box d) | _ -> None +let (|PatternMatchStyle|_|) pms = PatternMatchStyle.OfConfigString pms + let (|MultilineFormatterType|_|) mft = MultilineFormatterType.OfConfigString mft @@ -86,6 +88,7 @@ let parseOptionsFromEditorConfig | true, Number n -> n | true, Boolean b -> b | true, MultilineFormatterType mft -> box mft + | true, PatternMatchStyle pms -> box pms | true, EndOfLineStyle eol -> box eol | true, BracketStyle bs -> box bs | _ -> defaultValue) @@ -105,6 +108,9 @@ let configToEditorConfig (config: FormatConfig) : string = | :? MultilineFormatterType as mft -> $"%s{toEditorConfigName recordField.PropertyName}=%s{MultilineFormatterType.ToConfigString mft}" |> Some + | :? PatternMatchStyle as pms -> + $"%s{toEditorConfigName recordField.PropertyName}=%s{PatternMatchStyle.ToConfigString pms}" + |> Some | :? EndOfLineStyle as eols -> $"%s{toEditorConfigName recordField.PropertyName}=%s{EndOfLineStyle.ToConfigString eols}" |> Some