Skip to content

Commit

Permalink
Honor .fantomasignore file when processing a folder (fsprojects#1834)
Browse files Browse the repository at this point in the history
  • Loading branch information
kentcb authored Jul 20, 2021
1 parent 6869e2e commit 39decbe
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 4 deletions.
16 changes: 16 additions & 0 deletions src/Fantomas.CoreGlobalTool.Tests/CheckTests.fs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
module Fantomas.CoreGlobalTool.Tests.CheckTests

open System.IO
open NUnit.Framework
open FsUnit
open Fantomas.CoreGlobalTool.Tests.TestHelpers
Expand Down Expand Up @@ -114,3 +115,18 @@ let ``check with file and folder`` () =
(System.IO.Path.GetFileName(fileFixtureOne.Filename))

output |> should contain needsFormatting

[<Test>]
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")
15 changes: 15 additions & 0 deletions src/Fantomas.CoreGlobalTool.Tests/IgnoreFilesTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -111,3 +111,18 @@ let ``ignore file in folder while checking`` () =

File.ReadAllText inputFixture.Filename
|> should equal Source

[<Test>]
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")
9 changes: 5 additions & 4 deletions src/Fantomas.CoreGlobalTool/Program.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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<TextWriter, string>) 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
Expand Down

0 comments on commit 39decbe

Please sign in to comment.