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

Integrate analyzers via msbuild #2968

Merged
merged 17 commits into from
Oct 26, 2023
Merged
Show file tree
Hide file tree
Changes from 13 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
2 changes: 1 addition & 1 deletion .config/dotnet-tools.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
]
},
"fsharp-analyzers": {
"version": "0.16.0",
"version": "0.17.0",
"commands": [
"fsharp-analyzers"
]
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
uses: github/codeql-action/upload-sarif@v2
if: matrix.os == 'ubuntu-latest'
with:
sarif_file: analysis.sarif
sarif_file: analysisreports
- name: "Documentation"
if: matrix.os == 'windows-latest' && github.ref == 'refs/heads/main'
uses: peaceiris/actions-gh-pages@v3
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -201,4 +201,4 @@ tests/.repositories/**

# Analyzer files
.analyzerpackages
analysis.sarif
*.sarif
6 changes: 6 additions & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,10 @@ Some common use cases include:
<PackageReference Include="Ionide.KeepAChangelog.Tasks" Version="0.1.8" PrivateAssets="all" />
<PackageReference Include="DotNet.ReproducibleBuilds" Version="1.1.1" PrivateAssets="all" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="G-Research.FSharp.Analyzers" Version="0.1.6">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>build</IncludeAssets>
</PackageReference>
</ItemGroup>
</Project>
18 changes: 18 additions & 0 deletions Directory.Build.targets
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<Project>

<Target
Name="AnalyzeProject"
DependsOnTargets="Restore;ResolveAssemblyReferencesDesignTime;ResolveProjectReferencesDesignTime;ResolvePackageDependenciesDesignTime;FindReferenceAssembliesForReferences;_GenerateCompileDependencyCache;_ComputeNonExistentFileProperty;BeforeBuild;BeforeCompile;CoreCompile">

<Message Importance="normal" Text="fsc arguments: @(FscCommandLineArgs)" />
<Message Importance="High" Text="Analyzing $(MSBuildProjectFile)"/>
<Exec
ContinueOnError="true"
Command="dotnet fsharp-analyzers --fsc-args &quot;@(FscCommandLineArgs)&quot; --analyzers-path &quot;$(PkgG-Research_FSharp_Analyzers)\analyzers\dotnet\fs&quot; --exclude-analyzer PartialAppAnalyzer --fail-on-warnings GRA-STRING-001 --verbose --report &quot;../../$(MSBuildProjectName)-analysis.sarif&quot;">
nojaf marked this conversation as resolved.
Show resolved Hide resolved
<Output TaskParameter="ExitCode" PropertyName="LastExitCode" />
</Exec>
<Error Condition="'$(LastExitCode)' == '-2'" Text="Problems were found $(MSBuildProjectFile)" />

</Target>

</Project>
15 changes: 15 additions & 0 deletions Directory.Solution.targets
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<Project>

<ItemGroup>
<ProjectsToAnalyze Include="src\**\*.fsproj" Exclude="src\Fantomas.FCS\Fantomas.FCS.fsproj"/>
</ItemGroup>

<Target Name="AnalyzeSolution">
<Exec Command="dotnet build -c Release fantomas.sln" />
<MSBuild
Projects="@(ProjectsToAnalyze)"
Targets="AnalyzeProject"
Properties="DesignTimeBuild=True;Configuration=Release;ProvideCommandLineArgs=True;SkipCompilerExecution=True" />
</Target>

</Project>
17 changes: 0 additions & 17 deletions analyzers/analyzers.fsproj

This file was deleted.

6 changes: 0 additions & 6 deletions analyzers/packages.lock.json

This file was deleted.

35 changes: 5 additions & 30 deletions build.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

open System
open System.IO
open System.Text.RegularExpressions
open Fun.Build
open CliWrap
open CliWrap.Buffered
Expand Down Expand Up @@ -58,31 +57,16 @@ let pushPackage nupkg =
return result.ExitCode
}

let analyzersProjectPath = __SOURCE_DIRECTORY__ </> "analyzers/analyzers.fsproj"

let analyzersVersion =
let s = File.ReadAllText(analyzersProjectPath)
let regex = Regex(@"\[\s*(\d+\.\d+\.\d+)\s*\]")
let matches = regex.Match(s)
matches.Groups[1].Value

let analyzeProjects (projectPaths: string seq) =
let projects = String.concat " " projectPaths
let analyzerPath =
$"./.analyzerpackages/g-research.fsharp.analyzers/{analyzersVersion}"
let failOnWarnings =
"GRA-STRING-001 GRA-STRING-002 GRA-STRING-003 GRA-UNIONCASE-001"
let excludeAnalyzers = "PartialAppAnalyzer"
let report = "./analysis.sarif"
$"dotnet fsharp-analyzers --project %s{projects} --analyzers-path \"%s{analyzerPath}\" --verbose --fail-on-warnings %s{failOnWarnings} --report %s{report} --exclude-analyzer %s{excludeAnalyzers}"
let analysisReportsDir = "analysisreports"

pipeline "Build" {
workingDir __SOURCE_DIRECTORY__
stage "RestoreTools" { run "dotnet tool restore" }
stage "Clean" {
run (
cleanFolders
[| "bin"
[| analysisReportsDir
"bin"
"src/Fantomas.FCS/bin/Release"
"src/Fantomas.FCS/obj/Release"
"src/Fantomas.Core/bin/Release"
Expand All @@ -94,22 +78,13 @@ pipeline "Build" {
)
}
stage "CheckFormat" { run "dotnet fantomas src docs build.fsx --check" }
stage "RestoreAnalyzers" { run $"dotnet restore %s{analyzersProjectPath}" }
stage "Build" { run "dotnet build -c Release" }
stage "Analyze" {
run (fun _ -> async { System.IO.Directory.CreateDirectory(analysisReportsDir) |> ignore })
envVars
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would put this closer to the tool invocation.
Can we do this right before the <Exec Command?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[| "DOTNET_ROLL_FORWARD_TO_PRERELEASE", "1"
"DOTNET_ROLL_FORWARD", "LatestMajor" |]
run (
analyzeProjects
[ "./src/Fantomas/Fantomas.fsproj"
"./src/Fantomas.Benchmarks/Fantomas.Benchmarks.fsproj"
"./src/Fantomas.Client/Fantomas.Client.fsproj"
"./src/Fantomas.Client.Tests/Fantomas.Client.Tests.fsproj"
"./src/Fantomas.Core/Fantomas.Core.fsproj"
"./src/Fantomas.Core.Tests/Fantomas.Core.Tests.fsproj"
"./src/Fantomas.Tests/Fantomas.Tests.fsproj" ]
)
run "dotnet msbuild /t:AnalyzeSolution"
}
stage "UnitTests" { run "dotnet test -c Release" }
stage "Pack" { run "dotnet pack --no-restore -c Release -o ./bin" }
Expand Down
6 changes: 6 additions & 0 deletions src/Fantomas.Benchmarks/packages.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@
"resolved": "6.0.4",
"contentHash": "CYqAfmO7JvN38M+ACkstS8taVfl8C0mCkvSiBAshfKuu2Nut6+8MuFU7Wahu09wGIyFPlRz5ArFWxSOM5mhMSA=="
},
"G-Research.FSharp.Analyzers": {
"type": "Direct",
"requested": "[0.1.6, )",
"resolved": "0.1.6",
"contentHash": "1WyLN4LsQVQUprNr5adpLcYA7Dbn1ohGQ3Pch4qoVflKWZRuFb81pDziFZN/KOqPHdlQUx2BLAE5LIKGD46o5g=="
},
"BenchmarkDotNet.Annotations": {
"type": "Transitive",
"resolved": "0.13.2",
Expand Down
6 changes: 6 additions & 0 deletions src/Fantomas.Client.Tests/packages.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@
"resolved": "6.0.1",
"contentHash": "VrFAiW8dEEekk+0aqlbvMNZzDvYXmgWZwAt68AUBqaWK8RnoEVUNglj66bZzhs4/U63q0EfXlhcEKnH1sTYLjw=="
},
"G-Research.FSharp.Analyzers": {
"type": "Direct",
"requested": "[0.1.6, )",
"resolved": "0.1.6",
"contentHash": "1WyLN4LsQVQUprNr5adpLcYA7Dbn1ohGQ3Pch4qoVflKWZRuFb81pDziFZN/KOqPHdlQUx2BLAE5LIKGD46o5g=="
},
"Microsoft.NET.Test.Sdk": {
"type": "Direct",
"requested": "[17.5.0, )",
Expand Down
6 changes: 6 additions & 0 deletions src/Fantomas.Client/packages.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@
"resolved": "5.0.1",
"contentHash": "96YN8cgEVSpFhENBs+oXmxskFOQIjdW/pGCtyR+X8URYGbbQk0Fpu56uKHTOl7BEj6bSiZCuE8sjr9FdlXjoUQ=="
},
"G-Research.FSharp.Analyzers": {
"type": "Direct",
"requested": "[0.1.6, )",
"resolved": "0.1.6",
"contentHash": "1WyLN4LsQVQUprNr5adpLcYA7Dbn1ohGQ3Pch4qoVflKWZRuFb81pDziFZN/KOqPHdlQUx2BLAE5LIKGD46o5g=="
},
"Ionide.KeepAChangelog.Tasks": {
"type": "Direct",
"requested": "[0.1.8, )",
Expand Down
6 changes: 6 additions & 0 deletions src/Fantomas.Core.Tests/packages.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@
"NUnit": "[3.13.2, 3.14.0)"
}
},
"G-Research.FSharp.Analyzers": {
"type": "Direct",
"requested": "[0.1.6, )",
"resolved": "0.1.6",
"contentHash": "1WyLN4LsQVQUprNr5adpLcYA7Dbn1ohGQ3Pch4qoVflKWZRuFb81pDziFZN/KOqPHdlQUx2BLAE5LIKGD46o5g=="
},
"Microsoft.NET.Test.Sdk": {
"type": "Direct",
"requested": "[17.5.0, )",
Expand Down
6 changes: 6 additions & 0 deletions src/Fantomas.Core/packages.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@
"resolved": "6.0.1",
"contentHash": "VrFAiW8dEEekk+0aqlbvMNZzDvYXmgWZwAt68AUBqaWK8RnoEVUNglj66bZzhs4/U63q0EfXlhcEKnH1sTYLjw=="
},
"G-Research.FSharp.Analyzers": {
"type": "Direct",
"requested": "[0.1.6, )",
"resolved": "0.1.6",
"contentHash": "1WyLN4LsQVQUprNr5adpLcYA7Dbn1ohGQ3Pch4qoVflKWZRuFb81pDziFZN/KOqPHdlQUx2BLAE5LIKGD46o5g=="
},
"Ionide.KeepAChangelog.Tasks": {
"type": "Direct",
"requested": "[0.1.8, )",
Expand Down
6 changes: 6 additions & 0 deletions src/Fantomas.FCS/packages.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@
"FsLexYacc.Runtime": "11.2.0"
}
},
"G-Research.FSharp.Analyzers": {
"type": "Direct",
"requested": "[0.1.6, )",
"resolved": "0.1.6",
"contentHash": "1WyLN4LsQVQUprNr5adpLcYA7Dbn1ohGQ3Pch4qoVflKWZRuFb81pDziFZN/KOqPHdlQUx2BLAE5LIKGD46o5g=="
},
"Ionide.KeepAChangelog.Tasks": {
"type": "Direct",
"requested": "[0.1.8, )",
Expand Down
6 changes: 6 additions & 0 deletions src/Fantomas.Tests/packages.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@
"NUnit": "[3.13.2, 3.14.0)"
}
},
"G-Research.FSharp.Analyzers": {
"type": "Direct",
"requested": "[0.1.6, )",
"resolved": "0.1.6",
"contentHash": "1WyLN4LsQVQUprNr5adpLcYA7Dbn1ohGQ3Pch4qoVflKWZRuFb81pDziFZN/KOqPHdlQUx2BLAE5LIKGD46o5g=="
},
"Microsoft.NET.Test.Sdk": {
"type": "Direct",
"requested": "[17.5.0, )",
Expand Down
6 changes: 6 additions & 0 deletions src/Fantomas/packages.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@
"resolved": "6.0.1",
"contentHash": "VrFAiW8dEEekk+0aqlbvMNZzDvYXmgWZwAt68AUBqaWK8RnoEVUNglj66bZzhs4/U63q0EfXlhcEKnH1sTYLjw=="
},
"G-Research.FSharp.Analyzers": {
"type": "Direct",
"requested": "[0.1.6, )",
"resolved": "0.1.6",
"contentHash": "1WyLN4LsQVQUprNr5adpLcYA7Dbn1ohGQ3Pch4qoVflKWZRuFb81pDziFZN/KOqPHdlQUx2BLAE5LIKGD46o5g=="
},
"Ignore": {
"type": "Direct",
"requested": "[0.1.46, )",
Expand Down
Loading