Skip to content

Commit 732ab1f

Browse files
committed
adds fantomas check and format targets
1 parent 1cdaee5 commit 732ab1f

File tree

2 files changed

+78
-0
lines changed

2 files changed

+78
-0
lines changed

.config/dotnet-tools.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@
1919
"commands": [
2020
"fable"
2121
]
22+
},
23+
"fantomas-tool": {
24+
"version": "4.5.4",
25+
"commands": [
26+
"fantomas"
27+
]
2228
}
2329
}
2430
}

build.fsx

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,16 @@ let summary = "FsToolkit.ErrorHandling is a utility library to work with the Res
1919
let configuration = "Release"
2020
let solutionFile = "FsToolkit.ErrorHandling.sln"
2121

22+
let srcCodeGlob =
23+
!! (__SOURCE_DIRECTORY__ </> "src/**/*.fs")
24+
++ (__SOURCE_DIRECTORY__ </> "src/**/*.fsx")
25+
-- (__SOURCE_DIRECTORY__ </> "src/**/obj/**/*.fs")
26+
27+
let testsCodeGlob =
28+
!! (__SOURCE_DIRECTORY__ </> "tests/**/*.fs")
29+
++ (__SOURCE_DIRECTORY__ </> "tests/**/*.fsx")
30+
-- (__SOURCE_DIRECTORY__ </> "tests/**/obj/**/*.fs")
31+
2232
let gitOwner ="demystifyfp"
2333

2434
let distDir = __SOURCE_DIRECTORY__ @@ "bin"
@@ -31,6 +41,63 @@ let nugetToken = Environment.environVarOrNone "NUGET_TOKEN"
3141
Option.iter(TraceSecrets.register "<NUGET_TOKEN>")
3242

3343

44+
45+
let failOnBadExitAndPrint (p : ProcessResult) =
46+
if p.ExitCode <> 0 then
47+
p.Errors |> Seq.iter Trace.traceError
48+
failwithf "failed with exitcode %d" p.ExitCode
49+
module dotnet =
50+
let watch cmdParam program args =
51+
DotNet.exec cmdParam (sprintf "watch %s" program) args
52+
53+
let run cmdParam args =
54+
DotNet.exec cmdParam "run" args
55+
56+
let tool optionConfig command args =
57+
DotNet.exec optionConfig (sprintf "%s" command) args
58+
|> failOnBadExitAndPrint
59+
60+
let fantomas args =
61+
DotNet.exec id "fantomas" args
62+
63+
64+
let formatCode _ =
65+
let result =
66+
[
67+
srcCodeGlob
68+
testsCodeGlob
69+
]
70+
|> Seq.collect id
71+
// Ignore AssemblyInfo
72+
|> Seq.filter(fun f -> f.EndsWith("AssemblyInfo.fs") |> not)
73+
|> String.concat " "
74+
|> dotnet.fantomas
75+
76+
if not result.OK then
77+
printfn "Errors while formatting all files: %A" result.Messages
78+
79+
80+
let checkFormatCode _ =
81+
let result =
82+
[
83+
srcCodeGlob
84+
testsCodeGlob
85+
]
86+
|> Seq.collect id
87+
// Ignore AssemblyInfo
88+
|> Seq.filter(fun f -> f.EndsWith("AssemblyInfo.fs") |> not)
89+
|> String.concat " "
90+
|> sprintf "%s --check"
91+
|> dotnet.fantomas
92+
93+
if result.ExitCode = 0 then
94+
Trace.log "No files need formatting"
95+
elif result.ExitCode = 99 then
96+
failwith "Some files need formatting, check output for more info"
97+
else
98+
Trace.logf "Errors while formatting: %A" result.Errors
99+
100+
34101
Target.create "Clean" (fun _ ->
35102
!! "bin"
36103
++ "src/**/bin"
@@ -151,6 +218,10 @@ Target.create "NuGet" (fun _ ->
151218
("PackageReleaseNotes", releaseNotes)]}}))
152219
)
153220

221+
222+
Target.create "FormatCode" formatCode
223+
Target.create "CheckFormatCode" checkFormatCode
224+
154225
Target.create "PublishNuget" (fun _ ->
155226
Paket.push(fun p ->
156227
{ p with
@@ -206,6 +277,7 @@ Target.create "UpdateDocs" (fun _ ->
206277
==> "AssemblyInfo"
207278
==> "Restore"
208279
==> "NpmRestore"
280+
==> "CheckFormatCode"
209281
==> "Build"
210282
==> "RunTests"
211283
==> "RunFableTests"

0 commit comments

Comments
 (0)