Skip to content

Commit

Permalink
Add F# Analyzers (#603)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
1eyewonder and 64J0 authored Jul 25, 2024
1 parent 73724ac commit 5385767
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 1 deletion.
6 changes: 6 additions & 0 deletions .config/dotnet-tools.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@
"commands": [
"fantomas"
]
},
"fsharp-analyzers": {
"version": "0.26.0",
"commands": [
"fsharp-analyzers"
]
}
}
}
28 changes: 27 additions & 1 deletion .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,30 @@ jobs:
- name: Build
run: dotnet build -c Release --no-restore
- name: Test
run: dotnet test -c Release
run: dotnet test -c Release

analyzers:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup .NET Core
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.x
- name: Restore tools
run: dotnet tool restore
- name: Build solution
run: dotnet build -c Release Giraffe.sln

- name: Run Analyzers
run: dotnet msbuild /t:AnalyzeFSharpProject src/Giraffe/Giraffe.fsproj
# 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
# checkout code, build, run analyzers, ...
- 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: ./src/Giraffe/analysis.sarif
9 changes: 9 additions & 0 deletions Directory.Build.targets
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<Project>
<PropertyGroup>
<FSharpAnalyzersOtherFlags>--analyzers-path &quot;$(PkgG-Research_FSharp_Analyzers)&quot;</FSharpAnalyzersOtherFlags>
<FSharpAnalyzersOtherFlags>$(FSharpAnalyzersOtherFlags) --analyzers-path &quot;$(PkgIonide_Analyzers)&quot;</FSharpAnalyzersOtherFlags>
<FSharpAnalyzersOtherFlags>$(FSharpAnalyzersOtherFlags) --configuration $(Configuration)</FSharpAnalyzersOtherFlags>
<FSharpAnalyzersOtherFlags>$(FSharpAnalyzersOtherFlags) --exclude-analyzers PartialAppAnalyzer</FSharpAnalyzersOtherFlags>
<FSharpAnalyzersOtherFlags>$(FSharpAnalyzersOtherFlags) --report &quot;analysis.sarif&quot;</FSharpAnalyzersOtherFlags>
</PropertyGroup>
</Project>
9 changes: 9 additions & 0 deletions Directory.Solution.targets
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<Project>
<ItemGroup>
<ProjectsToAnalyze Include="src/**/*.fsproj" />
</ItemGroup>

<Target Name="AnalyzeSolution">
<MSBuild Projects="@(ProjectsToAnalyze)" Targets="AnalyzeFSharpProject" />
</Target>
</Project>
14 changes: 14 additions & 0 deletions src/Giraffe/Giraffe.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,20 @@
</ItemGroup>

<ItemGroup>
<!-- Analyzers -->
<PackageReference Include="FSharp.Analyzers.Build" Version="0.3.0">
<IncludeAssets>build</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="G-Research.FSharp.Analyzers" Version="0.10.0">
<IncludeAssets>analyzers</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Ionide.Analyzers" Version="0.11.0">
<IncludeAssets>analyzers</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>

<PackageReference Include="FSharp.Core" Version="6.0.0" />
<PackageReference Include="Microsoft.IO.RecyclableMemoryStream" Version="3.0.*" />
<PackageReference Include="System.Text.Json" Version="8.0.*" />
Expand Down

0 comments on commit 5385767

Please sign in to comment.