diff --git a/CHANGELOG.md b/CHANGELOG.md index 3d6bfe9b85..91265b5900 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ - Open-ended expressions (lambda, if-then-else, match, ...) in non-last positions of infix, tuple, list/array, and record expressions now stay multiline to preserve semantics. [#3279](https://github.com/fsprojects/fantomas/issues/3279) - Lambda in tuple in list on single line changes code meaning. [#3278](https://github.com/fsprojects/fantomas/issues/3278) - Custom operator applied to lambda collapses to single line changing semantics. [#3274](https://github.com/fsprojects/fantomas/issues/3274) +- Unrecognized `.editorconfig` property values now emit a warning to stderr instead of being silently ignored. [#1236](https://github.com/fsprojects/fantomas/issues/1236) ## [8.0.0-alpha-007] - 2026-03-10 diff --git a/src/Fantomas.Tests/EditorConfigurationTests.fs b/src/Fantomas.Tests/EditorConfigurationTests.fs index 6c00fdc2a3..1e2bb9485c 100644 --- a/src/Fantomas.Tests/EditorConfigurationTests.fs +++ b/src/Fantomas.Tests/EditorConfigurationTests.fs @@ -543,3 +543,33 @@ fsharp_experimental_elmish = true let config = EditorConfig.readConfiguration fsharpFile.FSharpFile Assert.That(config.ExperimentalElmish, Is.True) + +[] +let ``invalid editorconfig value emits warning to stderr and uses default`` () = + let rootDir = tempName () + + let editorConfig = + """ +[*.fs] +fsharp_experimental_elmish = not_a_bool +""" + + use configFixture = + new ConfigurationFile(defaultConfig, rootDir, content = editorConfig) + + use fsharpFile = new FSharpFile(rootDir) + + let capturedErr = new System.IO.StringWriter() + let originalErr = Console.Error + Console.SetError(capturedErr) + + let config = + try + EditorConfig.readConfiguration fsharpFile.FSharpFile + finally + Console.SetError(originalErr) + + let output = capturedErr.ToString() + Assert.That(output, Does.Contain("fsharp_experimental_elmish")) + Assert.That(output, Does.Contain("not_a_bool")) + config.ExperimentalElmish == defaultConfig.ExperimentalElmish diff --git a/src/Fantomas/EditorConfig.fs b/src/Fantomas/EditorConfig.fs index c529d75d7a..5afd73da35 100644 --- a/src/Fantomas/EditorConfig.fs +++ b/src/Fantomas/EditorConfig.fs @@ -88,7 +88,12 @@ let parseOptionsFromEditorConfig | true, MultilineFormatterType mft -> box mft | true, EndOfLineStyle eol -> box eol | true, BracketStyle bs -> box bs - | _ -> defaultValue) + | false, _ -> defaultValue + | true, invalidValue -> + eprintfn + $"warning: unrecognized value '%s{invalidValue}' for property '%s{editorConfigName}' in .editorconfig, using default." + + defaultValue) |> fun newValues -> let formatConfigType = FormatConfig.Default.GetType()