diff --git a/src/Fantomas.CoreGlobalTool.Tests/CheckTests.fs b/src/Fantomas.CoreGlobalTool.Tests/CheckTests.fs index a434789ae2..9bfc2723a6 100644 --- a/src/Fantomas.CoreGlobalTool.Tests/CheckTests.fs +++ b/src/Fantomas.CoreGlobalTool.Tests/CheckTests.fs @@ -1,5 +1,6 @@ module Fantomas.CoreGlobalTool.Tests.CheckTests +open System.IO open NUnit.Framework open FsUnit open Fantomas.CoreGlobalTool.Tests.TestHelpers @@ -114,3 +115,18 @@ let ``check with file and folder`` () = (System.IO.Path.GetFileName(fileFixtureOne.Filename)) output |> should contain needsFormatting + +[] +let ``honor ignore file when processing a folder`` () = + let fileName = "A" + let subFolder = System.Guid.NewGuid().ToString("N") + + use ignoreFixture = + new TemporaryFileCodeSample("let a = 0", fileName = fileName, subFolder = subFolder) + + use inputFixture = new FantomasIgnoreFile("*.fsx") + + let { Output = output } = + runFantomasTool (sprintf "--check .%c%s" Path.DirectorySeparatorChar subFolder) + + output |> should not' (contain "ignored") diff --git a/src/Fantomas.CoreGlobalTool.Tests/IgnoreFilesTests.fs b/src/Fantomas.CoreGlobalTool.Tests/IgnoreFilesTests.fs index 90a800a0b2..1c50d5a25e 100644 --- a/src/Fantomas.CoreGlobalTool.Tests/IgnoreFilesTests.fs +++ b/src/Fantomas.CoreGlobalTool.Tests/IgnoreFilesTests.fs @@ -111,3 +111,18 @@ let ``ignore file in folder while checking`` () = File.ReadAllText inputFixture.Filename |> should equal Source + +[] +let ``honor ignore file when processing a folder`` () = + let fileName = "A" + let subFolder = System.Guid.NewGuid().ToString("N") + + use ignoreFixture = + new TemporaryFileCodeSample(Source, fileName = fileName, subFolder = subFolder) + + use inputFixture = new FantomasIgnoreFile("*.fsx") + + let { Output = output } = + runFantomasTool (sprintf ".%c%s" Path.DirectorySeparatorChar subFolder) + + output |> should not' (contain "ignored") diff --git a/src/Fantomas.CoreGlobalTool/Program.fs b/src/Fantomas.CoreGlobalTool/Program.fs index 6d68a2f1e4..0544081234 100644 --- a/src/Fantomas.CoreGlobalTool/Program.fs +++ b/src/Fantomas.CoreGlobalTool/Program.fs @@ -108,10 +108,11 @@ let private hasByteOrderMark file = /// Format a source string using given config and write to a text writer let processSourceString isFsiFile s (tw: Choice) config = let fileName = - if isFsiFile then - "/tmp.fsi" - else - "/tmp.fsx" + match tw, isFsiFile with + | Choice1Of2 _, isFsi -> + let extension = if isFsi then "fsi" else "fs" + sprintf "/tmp.%s" extension + | Choice2Of2 f, _ -> f let writeResult (formatted: string) = match tw with