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

Add fsharp-analyzers to fbuild & vscode IDE #292

Merged
merged 3 commits into from
Dec 21, 2024
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
7 changes: 7 additions & 0 deletions .config/dotnet-tools.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@
"femto"
],
"rollForward": false
},
"fsharp-analyzers": {
"version": "0.28.0",
"commands": [
"fsharp-analyzers"
],
"rollForward": false
}
}
}
23 changes: 23 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -395,3 +395,6 @@ benchmarks/BenchmarkDotNet.Artifacts/

# Python Tests Output
.python-tests/

#FSharp Analyzers
analysisreports/
4 changes: 3 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,7 @@
"BoundModel.TypeCheck",
"BackgroundCompiler."
],
"FSharp.fsac.parallelReferenceResolution": false
"FSharp.fsac.parallelReferenceResolution": false,
"FSharp.enableAnalyzers": true,
"FSharp.analyzersPath": ["packages/analyzers"]
}
33 changes: 33 additions & 0 deletions build/build.fs
Original file line number Diff line number Diff line change
Expand Up @@ -136,13 +136,42 @@ 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 "."

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 ."
Expand Down Expand Up @@ -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
Expand All @@ -468,6 +498,9 @@ let initTargets () =
"DotnetRestore"
==>! "CheckFormatCode"

"DotnetRestore"
==>! "Analyzers"

//*** Dotnet Build ***//
"DotnetRestore"
==>! "Build"
Expand Down
6 changes: 6 additions & 0 deletions paket.dependencies
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 6 additions & 0 deletions paket.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading