-
-
Notifications
You must be signed in to change notification settings - Fork 26
Utilize RunAnalyzer and Fsc args in msbuild analyze if available #241
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
Merged
Merged
Changes from 7 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
533fddd
Adds ability to use FSC args in analyzer if available
TheAngryByrd 152165f
Make Analyzer after build more configurable
TheAngryByrd 530335b
Utilize FSharpAnalyzers_Exe for testing in repo
TheAngryByrd 1e8d4a7
Enhance FSharp.Analyzers.Build.targets with additional comments
TheAngryByrd 380cf3f
Refactor to use RunAnalyzersDuringBuild and RunAnalyzers properly
TheAngryByrd 1e313f6
Add documentation section on running analyzers after build with confi…
TheAngryByrd 1fc45cb
Clarify behavior of FSharpAnalyzerAfterBuild target regarding increme…
TheAngryByrd 104a1f2
Refactor analyzer property names for consistency in MSBuild integration
TheAngryByrd cdaa7b2
Clarify wording in MSBuild documentation for running analyzers after …
TheAngryByrd 7c85d63
Improve formatting and comments in MsBuildExample.fsproj for clarity …
TheAngryByrd a4389a1
Add documentation on treating warnings as errors in MSBuild
TheAngryByrd File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
|
|
||
| <Import Project="../../src/FSharp.Analyzers.Build/buildMultitargeting/FSharp.Analyzers.Build.targets" /> | ||
|
|
||
|
|
||
| <PropertyGroup> | ||
| <RunAnalyzersDuringBuild>true</RunAnalyzersDuringBuild> | ||
| <FSharpAnalyzersOtherFlags>--analyzers-path "../../artifacts/bin/OptionAnalyzer/debug" -v d</FSharpAnalyzersOtherFlags> | ||
| <FSharpAnalyzers_Exe>../../artifacts/bin/FSharp.Analyzers.Cli/debug/FSharp.Analyzers.Cli.dll</FSharpAnalyzers_Exe> | ||
TheAngryByrd marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| <!-- <FSharpAnalyzers_AlwaysRunAfterBuild>true</FSharpAnalyzers_AlwaysRunAfterBuild> --> | ||
| </PropertyGroup> | ||
|
|
||
| <PropertyGroup> | ||
| <OutputType>Exe</OutputType> | ||
| <TargetFrameworks>net8.0;net9.0</TargetFrameworks> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <Compile Include="Program.fs" /> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <ProjectReference Include="../OptionAnalyzer/OptionAnalyzer.fsproj" ReferenceOutputAssembly="false" /> | ||
| <ProjectReference Include="../../src/FSharp.Analyzers.Cli/FSharp.Analyzers.Cli.fsproj" ReferenceOutputAssembly="false" /> | ||
| </ItemGroup> | ||
|
|
||
| </Project> | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| // For more information see https://aka.ms/fsharp-console-apps | ||
|
|
||
| let value = Some 42 | ||
|
|
||
| printfn "The value is: %d" value.Value // This will cause a warning from the OptionAnalyzer |
66 changes: 64 additions & 2 deletions
66
src/FSharp.Analyzers.Build/build/FSharp.Analyzers.Build.targets
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,73 @@ | ||
| <Project> | ||
|
|
||
| <PropertyGroup> | ||
| <!-- Used for dotnet host discovery --> | ||
| <FSharpAnalyzers_ExeHost Condition="'$(FSharpAnalyzers_ExeHost)' == ''">dotnet</FSharpAnalyzers_ExeHost> | ||
| <!-- Points to the dotnet tool or the FSharp.Analyzers.Cli.dll for debugging --> | ||
| <FSharpAnalyzers_Exe Condition="'$(FSharpAnalyzers_Exe)' == ''">fsharp-analyzers</FSharpAnalyzers_Exe> | ||
| <!-- The build will continue even if the analyzer fails --> | ||
| <FSharpAnalyzers_ContinueOnError Condition="'$(FSharpAnalyzers_ContinueOnError)' == ''">true</FSharpAnalyzers_ContinueOnError> | ||
| <_FSharpAnalyzers_ProjectOptions>--project "$(MSBuildProjectFile)"</_FSharpAnalyzers_ProjectOptions> | ||
| </PropertyGroup> | ||
|
|
||
| <Target Name="_AnalyzeFSharpProject"> | ||
| <Error Condition="$(FSharpAnalyzersOtherFlags) == ''" Text="A property FSharpAnalyzersOtherFlags should exists with all the analyzer cli arguments!" /> | ||
| <Exec | ||
| ContinueOnError="true" | ||
| ContinueOnError="$(FSharpAnalyzers_ContinueOnError)" | ||
| IgnoreExitCode="true" | ||
| Command="dotnet fsharp-analyzers --project "$(MSBuildProjectFile)" $(FSharpAnalyzersOtherFlags)" /> | ||
| Command="$(FSharpAnalyzers_ExeHost) $(FSharpAnalyzers_Exe) $(_FSharpAnalyzers_ProjectOptions) $(FSharpAnalyzersOtherFlags)" /> | ||
| </Target> | ||
|
|
||
| <Target Name="AnalyzeFSharpProject" DependsOnTargets="_AnalyzeFSharpProject" /> | ||
|
|
||
| <Target Name="_FSharpAnalyzersDetermineRunAnalyzersValues" BeforeTargets="CoreCompile"> | ||
| <!-- | ||
| Roslyn uses multiple values for determining whether to run analyzers | ||
| see: https://learn.microsoft.com/en-us/visualstudio/code-quality/disable-code-analysis?view=vs-2019#net-framework-projects-1 | ||
|
|
||
| RunAnalyzersDuringBuild : Controls whether analyzers run at build time. | ||
| RunAnalyzers: It takes precedence over RunAnalyzersDuringBuild | ||
| --> | ||
| <PropertyGroup> | ||
| <_FSharpAnalyzers_RunDuringBuild Condition="'$(RunAnalyzersDuringBuild)' != ''">$(RunAnalyzersDuringBuild)</_FSharpAnalyzers_RunDuringBuild> | ||
| <_FSharpAnalyzers_RunDuringBuild Condition="'$(RunAnalyzers)' != ''">$(RunAnalyzers)</_FSharpAnalyzers_RunDuringBuild> | ||
| </PropertyGroup> | ||
| </Target> | ||
|
|
||
| <Target | ||
| Name="_SetupFSharpAnalyzerProjectOptions" | ||
| DependsOnTargets="_FSharpAnalyzersDetermineRunAnalyzersValues" | ||
| BeforeTargets="CoreCompile" | ||
| Condition="'$(_FSharpAnalyzers_RunDuringBuild)' == 'true'"> | ||
| <PropertyGroup> | ||
| <!-- | ||
| Required for F# Targets CoreCompile to output command line arguments | ||
| https://github.com/dotnet/fsharp/blob/53929f2e01281a614a15033dfaae6fb6d00bb543/src/FSharp.Build/Fsc.fs#L721-L725 | ||
| https://github.com/dotnet/fsharp/blob/53929f2e01281a614a15033dfaae6fb6d00bb543/src/FSharp.Build/Microsoft.FSharp.Targets#L418C19-L418C32 | ||
| --> | ||
| <ProvideCommandLineArgs>true</ProvideCommandLineArgs> | ||
| </PropertyGroup> | ||
| </Target> | ||
|
|
||
| <Target | ||
| Name="_FSharpAnalyzerAfterBuild" | ||
| DependsOnTargets="_SetupFSharpAnalyzerProjectOptions;CoreCompile" | ||
| AfterTargets="AfterBuild" | ||
| Condition="'$(_FSharpAnalyzers_RunDuringBuild)' == 'true'"> | ||
| <Error Condition="$(FSharpAnalyzersOtherFlags) == ''" Text="A property FSharpAnalyzersOtherFlags should exists with all the analyzer cli arguments!" /> | ||
| <PropertyGroup> | ||
| <!-- | ||
| If FscCommandLineArgs is empty, then CoreCompile did not run, we'll try to skip running the analyzer if this wasn't explicitly set to true | ||
| --> | ||
| <FSharpAnalyzers_AlwaysRunAfterBuild Condition="'$(FSharpAnalyzers_AlwaysRunAfterBuild)' == '' and '@(FscCommandLineArgs->Count())' != '0'">true</FSharpAnalyzers_AlwaysRunAfterBuild> | ||
TheAngryByrd marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| <!-- We'll try to use FscCommandLineArgs- to speed up analyzer execution since this skips requiring a design-time build --> | ||
| <_FSharpAnalyzers_ProjectOptions Condition="'@(FscCommandLineArgs->Count())' != '0'">--fsc-args "@(FscCommandLineArgs)"</_FSharpAnalyzers_ProjectOptions> | ||
| </PropertyGroup> | ||
| <Exec | ||
| ContinueOnError="$(FSharpAnalyzers_ContinueOnError)" | ||
| Condition="'$(FSharpAnalyzers_AlwaysRunAfterBuild)' == 'true'" | ||
| Command="$(FSharpAnalyzers_ExeHost) $(FSharpAnalyzers_Exe) $(_FSharpAnalyzers_ProjectOptions) $(FSharpAnalyzersOtherFlags)" /> | ||
| </Target> | ||
|
|
||
| <Target Name="FSharpAnalyzerAfterBuild" DependsOnTargets="_FSharpAnalyzerAfterBuild"/> | ||
| </Project> | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.