Skip to content

Commit 5385767

Browse files
1eyewonder64J0
andauthored
Add F# Analyzers (#603)
* Added fsharp analyzers in response to seeing Follow-up from "Minor code optimisation #567" #577 * Moved packages to proj file instead of props file * add analyzers CI workflow and define the report name at Directory.Build.Targets --------- Co-authored-by: 64J0 <[email protected]>
1 parent 73724ac commit 5385767

File tree

5 files changed

+65
-1
lines changed

5 files changed

+65
-1
lines changed

.config/dotnet-tools.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@
77
"commands": [
88
"fantomas"
99
]
10+
},
11+
"fsharp-analyzers": {
12+
"version": "0.26.0",
13+
"commands": [
14+
"fsharp-analyzers"
15+
]
1016
}
1117
}
1218
}

.github/workflows/build-and-test.yml

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,30 @@ jobs:
3838
- name: Build
3939
run: dotnet build -c Release --no-restore
4040
- name: Test
41-
run: dotnet test -c Release
41+
run: dotnet test -c Release
42+
43+
analyzers:
44+
runs-on: ubuntu-latest
45+
steps:
46+
- name: Checkout
47+
uses: actions/checkout@v4
48+
- name: Setup .NET Core
49+
uses: actions/setup-dotnet@v4
50+
with:
51+
dotnet-version: 8.x
52+
- name: Restore tools
53+
run: dotnet tool restore
54+
- name: Build solution
55+
run: dotnet build -c Release Giraffe.sln
56+
57+
- name: Run Analyzers
58+
run: dotnet msbuild /t:AnalyzeFSharpProject src/Giraffe/Giraffe.fsproj
59+
# This is important, you want to continue your Action even if you found problems.
60+
# As you always want the report to upload
61+
continue-on-error: true
62+
# checkout code, build, run analyzers, ...
63+
- name: Upload SARIF file
64+
uses: github/codeql-action/upload-sarif@v2
65+
with:
66+
# You can also specify the path to a folder for `sarif_file`
67+
sarif_file: ./src/Giraffe/analysis.sarif

Directory.Build.targets

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<Project>
2+
<PropertyGroup>
3+
<FSharpAnalyzersOtherFlags>--analyzers-path &quot;$(PkgG-Research_FSharp_Analyzers)&quot;</FSharpAnalyzersOtherFlags>
4+
<FSharpAnalyzersOtherFlags>$(FSharpAnalyzersOtherFlags) --analyzers-path &quot;$(PkgIonide_Analyzers)&quot;</FSharpAnalyzersOtherFlags>
5+
<FSharpAnalyzersOtherFlags>$(FSharpAnalyzersOtherFlags) --configuration $(Configuration)</FSharpAnalyzersOtherFlags>
6+
<FSharpAnalyzersOtherFlags>$(FSharpAnalyzersOtherFlags) --exclude-analyzers PartialAppAnalyzer</FSharpAnalyzersOtherFlags>
7+
<FSharpAnalyzersOtherFlags>$(FSharpAnalyzersOtherFlags) --report &quot;analysis.sarif&quot;</FSharpAnalyzersOtherFlags>
8+
</PropertyGroup>
9+
</Project>

Directory.Solution.targets

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<Project>
2+
<ItemGroup>
3+
<ProjectsToAnalyze Include="src/**/*.fsproj" />
4+
</ItemGroup>
5+
6+
<Target Name="AnalyzeSolution">
7+
<MSBuild Projects="@(ProjectsToAnalyze)" Targets="AnalyzeFSharpProject" />
8+
</Target>
9+
</Project>

src/Giraffe/Giraffe.fsproj

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,20 @@
4949
</ItemGroup>
5050

5151
<ItemGroup>
52+
<!-- Analyzers -->
53+
<PackageReference Include="FSharp.Analyzers.Build" Version="0.3.0">
54+
<IncludeAssets>build</IncludeAssets>
55+
<PrivateAssets>all</PrivateAssets>
56+
</PackageReference>
57+
<PackageReference Include="G-Research.FSharp.Analyzers" Version="0.10.0">
58+
<IncludeAssets>analyzers</IncludeAssets>
59+
<PrivateAssets>all</PrivateAssets>
60+
</PackageReference>
61+
<PackageReference Include="Ionide.Analyzers" Version="0.11.0">
62+
<IncludeAssets>analyzers</IncludeAssets>
63+
<PrivateAssets>all</PrivateAssets>
64+
</PackageReference>
65+
5266
<PackageReference Include="FSharp.Core" Version="6.0.0" />
5367
<PackageReference Include="Microsoft.IO.RecyclableMemoryStream" Version="3.0.*" />
5468
<PackageReference Include="System.Text.Json" Version="8.0.*" />

0 commit comments

Comments
 (0)