Skip to content

Commit

Permalink
Check code after format (#655)
Browse files Browse the repository at this point in the history
* adapt process to use formatFileAsync API

* CoreGlobalTool checks if formatted code is valid

* Uses FakeHelper's format family functions which classify the format
result i.e. changed/unchanged/error, in preparation for a --check
command (#642)

* fix bug where stdin would not accept cat files

* update --stdin flag docs

* address code review concerns

* remove need for temp files in FormatResult

* Updated month in release notes

* Initial CLI check functionality draft

* Supports checking both files and folders
* Always reports changes to stdout

* make check code faster

* previously it was blocking for every element of the sequence and that
was delaying the output massivelly
* now it should be pretty responsive

* update docs

* add test CLI test project

* Refactor and test check functionality

* Added CoreGlobalTool.Test project
* Test specific CoreGlobalTool functionality
* Separated --check command logic into a separate module

* Removed src folder from solution

* Removed nunitlite

* Refactored checkCode to FAKEHelpers

Co-authored-by: Florian Verdonck <[email protected]>
  • Loading branch information
lpedrosa and nojaf authored Feb 21, 2020
1 parent 3d2e39e commit dfef3d5
Show file tree
Hide file tree
Showing 19 changed files with 477 additions and 213 deletions.
11 changes: 11 additions & 0 deletions build.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ Target.create "ProjectVersion" (fun _ ->

setProjectVersion "Fantomas"
setProjectVersion "Fantomas.CoreGlobalTool"
setProjectVersion "Fantomas.CoreGlobalTool.Tests"
setProjectVersion "Fantomas.Tests"
)

Expand All @@ -201,6 +202,16 @@ Target.create "UnitTests" (fun _ ->
// Current there is an issue with NUnit reporter, https://github.com/nunit/nunit3-vs-adapter/issues/589
}
) "src/Fantomas.Tests/Fantomas.Tests.fsproj"
DotNet.test (fun p ->
{ p with
Configuration = configuration
NoRestore = true
NoBuild = true
// TestAdapterPath = Some "."
// Logger = Some "nunit;LogFilePath=../../TestResults.xml"
// Current there is an issue with NUnit reporter, https://github.com/nunit/nunit3-vs-adapter/issues/589
}
) "src/Fantomas.CoreGlobalTool.Tests/Fantomas.CoreGlobalTool.Tests.fsproj"
)

// --------------------------------------------------------------------------------------
Expand Down
31 changes: 30 additions & 1 deletion docs/Documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@ This is helpful if the tool fails on some unknown F# constructs.

read input from standard input. This option is convenient to use with piping

type input.fs | Fantomas --stdin --out output.fs
echo 'open System;; let () = printfn "Hello World"' | Fantomas --stdin --out output.fs

or

cat input.fs | Fantomas --stdin --out output.fs

##### `--stdout`

Expand All @@ -46,6 +50,31 @@ this option to be used with `--stdin` to specify that we are formatting F# signa

type input.fsi | Fantomas --fsi --stdin --stdout

##### `--check`

Checks if the files provided require formatting and:

* Exits with `0` if no files require formatting
* Exits with `1` if some files require formatting. It also outputs the path of the files that require formatting.
* Exits with `99` if some files contain errors (e.g. parsing errors, etc.)

For example:

# given an example project
ls src/MyProject
File1.fs # correctly formatted
File2.fs # needs formatting
File3.fs # has compilation errors

# running a check
Fantomas --check src/MyProject
src/MyProject/File2.fs requires formatting
error: Failed to format src/MyProject/File3.fs: <description of the error>

# if you check the exit code
echo $?
99

#### Preferences

##### `--indent <number>`
Expand Down
21 changes: 21 additions & 0 deletions fantomas.sln
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,19 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26124.0
MinimumVisualStudioVersion = 15.0.26124.0
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".paket", ".paket", "{B570C54C-2FEA-4A94-A8C5-FD4157A94DE7}"
ProjectSection(SolutionItems) = preProject
paket.dependencies = paket.dependencies
EndProjectSection
EndProject
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "Fantomas", "src\Fantomas\Fantomas.fsproj", "{7EA16279-A5F1-4781-A343-4375A04BCE6F}"
EndProject
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "Fantomas.Tests", "src\Fantomas.Tests\Fantomas.Tests.fsproj", "{DED76E41-B89F-47BA-84C5-3AB0BECFA767}"
EndProject
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "Fantomas.CoreGlobalTool", "src\Fantomas.CoreGlobalTool\Fantomas.CoreGlobalTool.fsproj", "{DC08805B-C6E2-43F3-B381-E60EE88A079D}"
EndProject
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "Fantomas.CoreGlobalTool.Tests", "src\Fantomas.CoreGlobalTool.Tests\Fantomas.CoreGlobalTool.Tests.fsproj", "{DEDE6968-0BE8-4415-9262-8355B82AF2C0}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -58,5 +65,19 @@ Global
{DC08805B-C6E2-43F3-B381-E60EE88A079D}.Release|x64.Build.0 = Release|Any CPU
{DC08805B-C6E2-43F3-B381-E60EE88A079D}.Release|x86.ActiveCfg = Release|Any CPU
{DC08805B-C6E2-43F3-B381-E60EE88A079D}.Release|x86.Build.0 = Release|Any CPU
{DEDE6968-0BE8-4415-9262-8355B82AF2C0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{DEDE6968-0BE8-4415-9262-8355B82AF2C0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DEDE6968-0BE8-4415-9262-8355B82AF2C0}.Debug|x64.ActiveCfg = Debug|Any CPU
{DEDE6968-0BE8-4415-9262-8355B82AF2C0}.Debug|x64.Build.0 = Debug|Any CPU
{DEDE6968-0BE8-4415-9262-8355B82AF2C0}.Debug|x86.ActiveCfg = Debug|Any CPU
{DEDE6968-0BE8-4415-9262-8355B82AF2C0}.Debug|x86.Build.0 = Debug|Any CPU
{DEDE6968-0BE8-4415-9262-8355B82AF2C0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DEDE6968-0BE8-4415-9262-8355B82AF2C0}.Release|Any CPU.Build.0 = Release|Any CPU
{DEDE6968-0BE8-4415-9262-8355B82AF2C0}.Release|x64.ActiveCfg = Release|Any CPU
{DEDE6968-0BE8-4415-9262-8355B82AF2C0}.Release|x64.Build.0 = Release|Any CPU
{DEDE6968-0BE8-4415-9262-8355B82AF2C0}.Release|x86.ActiveCfg = Release|Any CPU
{DEDE6968-0BE8-4415-9262-8355B82AF2C0}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
EndGlobalSection
EndGlobal
7 changes: 4 additions & 3 deletions paket.dependencies
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ nuget FSharp.Core
nuget FSharp.Compiler.Service 34.0.1
nuget FsUnit
nuget FsCheck
nuget Microsoft.NET.Test.Sdk
nuget NUnit3TestAdapter
nuget Microsoft.NET.Test.Sdk 16.4.0
nuget nunit 3.12.0
nuget NUnit3TestAdapter 3.15.1
nuget NunitXml.TestLogger
nuget Argu
nuget Argu
Loading

0 comments on commit dfef3d5

Please sign in to comment.