Skip to content

Commit 0bb57df

Browse files
Add fsharp-analyzers to fbuild & vscode IDE (#292)
* Added fsharp-analyzers to fbuild & vscode IDE * Try upload analysis --------- Co-authored-by: Jimmy Byrd <[email protected]> Co-authored-by: Jimmy Byrd <[email protected]>
1 parent 200ff61 commit 0bb57df

File tree

7 files changed

+81
-1
lines changed

7 files changed

+81
-1
lines changed

.config/dotnet-tools.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,13 @@
2929
"femto"
3030
],
3131
"rollForward": false
32+
},
33+
"fsharp-analyzers": {
34+
"version": "0.28.0",
35+
"commands": [
36+
"fsharp-analyzers"
37+
],
38+
"rollForward": false
3239
}
3340
}
3441
}

.github/workflows/build.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,3 +143,26 @@ jobs:
143143
runCmd: |
144144
chmod +x ./build.sh
145145
./build.sh RunTests
146+
147+
analyze:
148+
runs-on: ubuntu-latest
149+
steps:
150+
- uses: actions/checkout@v3
151+
- name: Setup necessary dotnet SDKs
152+
uses: actions/setup-dotnet@v3
153+
with:
154+
global-json-file: global.json
155+
dotnet-version: |
156+
8.x
157+
- name: Analyze
158+
run: |
159+
chmod +x ./build.sh
160+
./build.sh Analyzers
161+
# This is important, you want to continue your Action even if you found problems.
162+
# As you always want the report to upload
163+
continue-on-error: true
164+
- name: Upload SARIF file
165+
uses: github/codeql-action/upload-sarif@v2
166+
with:
167+
# You can also specify the path to a folder for `sarif_file`
168+
sarif_file: analysisreports

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,3 +395,6 @@ benchmarks/BenchmarkDotNet.Artifacts/
395395

396396
# Python Tests Output
397397
.python-tests/
398+
399+
#FSharp Analyzers
400+
analysisreports/

.vscode/settings.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,7 @@
77
"BoundModel.TypeCheck",
88
"BackgroundCompiler."
99
],
10-
"FSharp.fsac.parallelReferenceResolution": false
10+
"FSharp.fsac.parallelReferenceResolution": false,
11+
"FSharp.enableAnalyzers": true,
12+
"FSharp.analyzersPath": ["packages/analyzers"]
1113
}

build/build.fs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,13 +136,42 @@ module dotnet =
136136

137137
let fantomas args = DotNet.exec id "fantomas" args
138138

139+
let analyzers args = DotNet.exec id "fsharp-analyzers" args
140+
139141

140142
let formatCode _ =
141143
let result = dotnet.fantomas "."
142144

143145
if not result.OK then
144146
Trace.traceErrorfn "Errors while formatting all files: %A" result.Messages
145147

148+
let analyze _ =
149+
let analyzerPaths = !! "packages/analyzers/**/analyzers/dotnet/fs"
150+
151+
let createArgsForProject (project: string) analyzerPaths =
152+
let projectName = Path.GetFileNameWithoutExtension project
153+
154+
[
155+
yield "--project"
156+
yield project
157+
yield "--analyzers-path"
158+
yield! analyzerPaths
159+
if isCI.Value then
160+
yield "--report"
161+
yield $"analysisreports/{projectName}-analysis.sarif"
162+
]
163+
|> String.concat " "
164+
165+
!! "src/**/*.fsproj"
166+
|> Seq.iter (fun fsproj ->
167+
let result =
168+
createArgsForProject fsproj analyzerPaths
169+
|> dotnet.analyzers
170+
171+
result.Errors
172+
|> Seq.iter Trace.traceError
173+
)
174+
146175

147176
let checkFormatCode _ =
148177
let result = dotnet.fantomas "--check ."
@@ -445,6 +474,7 @@ let initTargets () =
445474
Target.create "DotnetPack" dotnetPack
446475
Target.create "FormatCode" formatCode
447476
Target.create "CheckFormatCode" checkFormatCode
477+
Target.create "Analyzers" analyze
448478
Target.create "PublishToNuGet" publishNuget
449479
Target.create "GitRelease" gitRelease
450480
Target.create "GitHubRelease" githubRelease
@@ -468,6 +498,9 @@ let initTargets () =
468498
"DotnetRestore"
469499
==>! "CheckFormatCode"
470500

501+
"DotnetRestore"
502+
==>! "Analyzers"
503+
471504
//*** Dotnet Build ***//
472505
"DotnetRestore"
473506
==>! "Build"

paket.dependencies

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,9 @@ group Build
5656
nuget Nuget.Common >= 6.6.1
5757
nuget NuGet.Protocol >= 6.6.1
5858
nuget System.Security.Cryptography.Pkcs >= 7.0.2
59+
60+
group analyzers
61+
source https://api.nuget.org/v3/index.json
62+
63+
nuget Ionide.Analyzers
64+
nuget G-Research.FSharp.Analyzers

paket.lock

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@ NUGET
2424
System.Threading.Tasks.Extensions (4.5.4) - restriction: == netstandard2.0
2525
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)
2626

27+
GROUP analyzers
28+
NUGET
29+
remote: https://api.nuget.org/v3/index.json
30+
G-Research.FSharp.Analyzers (0.12)
31+
Ionide.Analyzers (0.13)
32+
2733
GROUP Benchmarks
2834
STORAGE: NONE
2935
NUGET

0 commit comments

Comments
 (0)