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

Extend InputPath DU to improve error messages #2384

Merged
merged 3 commits into from
Jul 26, 2022
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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## [Unreleased]

### Changed
* Show a better error message when the folder does not exist. [#2341](https://github.com/fsprojects/fantomas/issues/2341)

## [5.0.0-beta-002] - 2022-07-19

### Fixed
Expand Down
16 changes: 16 additions & 0 deletions src/Fantomas.Tests/Integration/CheckTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,22 @@ let ``invalid files should report exit code 1`` () =
let { ExitCode = exitCode } = checkCode [ fileFixture.Filename ]
exitCode |> should equal 1

[<Test>]
let ``non-existing file should report exit code 1`` () =
let { ExitCode = exitCode } = checkCode [ "somenonexistingfile.fs" ]
exitCode |> should equal 1

[<Test>]
let ``unsupported file should report exit code 1`` () =
use fileFixture = new TemporaryFileCodeSample(CorrectlyFormatted, extension = "txt")
let { ExitCode = exitCode } = checkCode [ fileFixture.Filename ]
exitCode |> should equal 1

[<Test>]
let ``missing file should report exit code 1`` () =
let { ExitCode = exitCode } = checkCode []
exitCode |> should equal 1

[<Test>]
let ``files that need formatting should report exit code 99`` () =
use fileFixture = new TemporaryFileCodeSample(NeedsFormatting)
Expand Down
22 changes: 22 additions & 0 deletions src/Fantomas.Tests/Integration/ExitCodeTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,30 @@ open Fantomas.Tests.TestHelpers
[<Literal>]
let WithErrors = """let a ="""

[<Literal>]
let CorrectlyFormatted =
"""module A

"""

[<Test>]
let ``invalid files should report exit code 1`` () =
use fileFixture = new TemporaryFileCodeSample(WithErrors)
let { ExitCode = exitCode } = formatCode [ fileFixture.Filename ]
exitCode |> should equal 1

[<Test>]
let ``non-existing file should report exit code 1`` () =
let { ExitCode = exitCode } = formatCode [ "somenonexistingfile.fs" ]
exitCode |> should equal 1

[<Test>]
let ``unsupported file should report exit code 1`` () =
use fileFixture = new TemporaryFileCodeSample(CorrectlyFormatted, extension = "txt")
let { ExitCode = exitCode } = formatCode [ fileFixture.Filename ]
exitCode |> should equal 1

[<Test>]
let ``missing file should report exit code 1`` () =
let { ExitCode = exitCode } = formatCode []
exitCode |> should equal 1
24 changes: 20 additions & 4 deletions src/Fantomas/Program.fs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ type InputPath =
| File of string
| Folder of string
| Multiple of files: string list * folder: string list
| NoFSharpFile of string
| NotFound of string
| Unspecified

[<RequireQualifiedAccess>]
Expand Down Expand Up @@ -186,9 +188,15 @@ let runCheckCommand (recurse: bool) (inputPath: InputPath) : int =
if checkResult.HasErrors then 1 else 99

match inputPath with
| InputPath.NoFSharpFile s ->
eprintfn "Input path '%s' is unsupported file type" s
1
| InputPath.NotFound s ->
eprintfn "Input path '%s' not found" s
1
| InputPath.Unspecified _ ->
eprintfn "No input path provided. Nothing to do."
0
eprintfn "No input path provided. Call with --help for usage information."
1
| InputPath.File f when (IgnoreFile.isIgnoredFile (IgnoreFile.current.Force()) f) ->
printfn "'%s' was ignored" f
0
Expand Down Expand Up @@ -232,8 +240,10 @@ let main argv =
InputPath.Folder input
elif File.Exists input && isFSharpFile input then
InputPath.File input
elif File.Exists input then
InputPath.NoFSharpFile input
else
InputPath.Unspecified
InputPath.NotFound input
| Some inputs ->
let isFolder (path: string) = Path.GetExtension(path) = ""

Expand Down Expand Up @@ -353,8 +363,14 @@ let main argv =
else
try
match inputPath, outputPath with
| InputPath.NoFSharpFile s, _ ->
eprintfn "Input path '%s' is unsupported file type." s
exit 1
| InputPath.NotFound s, _ ->
eprintfn "Input path '%s' not found." s
exit 1
| InputPath.Unspecified, _ ->
eprintfn "Input path is missing..."
eprintfn "Input path is missing. Call with --help for usage information."
exit 1
| InputPath.File f, _ when (IgnoreFile.isIgnoredFile (IgnoreFile.current.Force()) f) ->
printfn "'%s' was ignored" f
Expand Down