diff --git a/.config/dotnet-tools.json b/.config/dotnet-tools.json index 47362a3d..d7e1c57b 100644 --- a/.config/dotnet-tools.json +++ b/.config/dotnet-tools.json @@ -29,6 +29,13 @@ "femto" ], "rollForward": false + }, + "fsharp-analyzers": { + "version": "0.28.0", + "commands": [ + "fsharp-analyzers" + ], + "rollForward": false } } } \ No newline at end of file diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 551d6481..8f2919f6 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -143,3 +143,26 @@ jobs: runCmd: | chmod +x ./build.sh ./build.sh RunTests + + analyze: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: Setup necessary dotnet SDKs + uses: actions/setup-dotnet@v3 + with: + global-json-file: global.json + dotnet-version: | + 8.x + - name: Analyze + run: | + chmod +x ./build.sh + ./build.sh Analyzers + # This is important, you want to continue your Action even if you found problems. + # As you always want the report to upload + continue-on-error: true + - name: Upload SARIF file + uses: github/codeql-action/upload-sarif@v2 + with: + # You can also specify the path to a folder for `sarif_file` + sarif_file: analysisreports diff --git a/.gitignore b/.gitignore index 681109d4..2686b073 100644 --- a/.gitignore +++ b/.gitignore @@ -395,3 +395,6 @@ benchmarks/BenchmarkDotNet.Artifacts/ # Python Tests Output .python-tests/ + +#FSharp Analyzers +analysisreports/ diff --git a/.vscode/settings.json b/.vscode/settings.json index 73af14d4..5e7b55e5 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -7,5 +7,7 @@ "BoundModel.TypeCheck", "BackgroundCompiler." ], - "FSharp.fsac.parallelReferenceResolution": false + "FSharp.fsac.parallelReferenceResolution": false, + "FSharp.enableAnalyzers": true, + "FSharp.analyzersPath": ["packages/analyzers"] } diff --git a/build/build.fs b/build/build.fs index fd686a60..365aa489 100644 --- a/build/build.fs +++ b/build/build.fs @@ -136,6 +136,8 @@ module dotnet = let fantomas args = DotNet.exec id "fantomas" args + let analyzers args = DotNet.exec id "fsharp-analyzers" args + let formatCode _ = let result = dotnet.fantomas "." @@ -143,6 +145,33 @@ let formatCode _ = if not result.OK then Trace.traceErrorfn "Errors while formatting all files: %A" result.Messages +let analyze _ = + let analyzerPaths = !! "packages/analyzers/**/analyzers/dotnet/fs" + + let createArgsForProject (project: string) analyzerPaths = + let projectName = Path.GetFileNameWithoutExtension project + + [ + yield "--project" + yield project + yield "--analyzers-path" + yield! analyzerPaths + if isCI.Value then + yield "--report" + yield $"analysisreports/{projectName}-analysis.sarif" + ] + |> String.concat " " + + !! "src/**/*.fsproj" + |> Seq.iter (fun fsproj -> + let result = + createArgsForProject fsproj analyzerPaths + |> dotnet.analyzers + + result.Errors + |> Seq.iter Trace.traceError + ) + let checkFormatCode _ = let result = dotnet.fantomas "--check ." @@ -445,6 +474,7 @@ let initTargets () = Target.create "DotnetPack" dotnetPack Target.create "FormatCode" formatCode Target.create "CheckFormatCode" checkFormatCode + Target.create "Analyzers" analyze Target.create "PublishToNuGet" publishNuget Target.create "GitRelease" gitRelease Target.create "GitHubRelease" githubRelease @@ -468,6 +498,9 @@ let initTargets () = "DotnetRestore" ==>! "CheckFormatCode" + "DotnetRestore" + ==>! "Analyzers" + //*** Dotnet Build ***// "DotnetRestore" ==>! "Build" diff --git a/paket.dependencies b/paket.dependencies index 43e61393..3916f8ef 100644 --- a/paket.dependencies +++ b/paket.dependencies @@ -56,3 +56,9 @@ group Build nuget Nuget.Common >= 6.6.1 nuget NuGet.Protocol >= 6.6.1 nuget System.Security.Cryptography.Pkcs >= 7.0.2 + +group analyzers + source https://api.nuget.org/v3/index.json + + nuget Ionide.Analyzers + nuget G-Research.FSharp.Analyzers diff --git a/paket.lock b/paket.lock index 8115e906..448949df 100644 --- a/paket.lock +++ b/paket.lock @@ -24,6 +24,12 @@ NUGET System.Threading.Tasks.Extensions (4.5.4) - restriction: == netstandard2.0 System.Runtime.CompilerServices.Unsafe (>= 4.5.3) - restriction: || (&& (< monoandroid) (< monotouch) (< net45) (>= netstandard1.0) (< netstandard2.0) (< win8) (< wpa81) (< xamarintvos) (< xamarinwatchos)) (&& (< monoandroid) (< netstandard1.0) (>= portable-net45+win8+wp8+wpa81) (< win8)) (&& (>= net45) (< netstandard2.0)) (&& (< net45) (< netcoreapp2.1) (>= netstandard2.0) (< xamarinios) (< xamarinmac) (< xamarintvos) (< xamarinwatchos)) (>= net461) (&& (< netstandard1.0) (>= win8)) (&& (< netstandard2.0) (>= wpa81)) (>= wp8) +GROUP analyzers +NUGET + remote: https://api.nuget.org/v3/index.json + G-Research.FSharp.Analyzers (0.12) + Ionide.Analyzers (0.13) + GROUP Benchmarks STORAGE: NONE NUGET