Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Honor .fantomasignore file when processing a folder #1834

Merged
merged 1 commit into from
Jul 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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