-
Notifications
You must be signed in to change notification settings - Fork 468
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
Re-implement CodeAnalysisTreatWarningsAsErrors with globalconfig files #6427
Re-implement CodeAnalysisTreatWarningsAsErrors with globalconfig files #6427
Conversation
Fixes dotnet#6281 Prior implementation for `CodeAnalysisTreatWarningsAsErrors` passed `/warnaserror+:CAxxxx` to the command line for each CA rule ID. This led to couple of issues: 1. All disabled by default CA warnings seem to get enabled as errors 2. Editorconfig/globalconfig based configuration of the enabled CA rules stops working. The new implementation updates our globalconfig tooling to generate parallel globalconfigs with `_warnaserror` suffix, such that rules which would have had effective warning severity are set to error severity in the new globalconfig files. The targets/props that picks the appropriate globalconfig based on the `AnalysisLevel` property now chooses the file with `_warnaserror` suffix if user has enabled code analysis warnings to be treated as errors. Another couple of notes: 1. Given that the buggy implementation of `CodeAnalysisTreatWarningsAsErrors` has already shipped in .NET7 and prior SDKs, we use a separate property `EffectiveCodeAnalysisTreatWarningsAsErrors`, so users using the newer NuGet package, but older .NET SDK can still get this functionality. Users that move to the newer .NET8 preview SDK with this fix can use `CodeAnalysisTreatWarningsAsErrors` itself. 2. I have adjusted the tooling to generate the config files into buildtransitive folder instead of build folder. This is needed as a follow-up to dotnet#6325 for globalconfig files to be correctly mapped. 3. I have also renamed all the tooling generated globalconfig files to have .globalconfig extension instead of .editorconfig extension, as that was misleading. I have verified that `CodeAnalysisTreatWarningsAsErrors` works fine with the locally built package when `EffectiveCodeAnalysisTreatWarningsAsErrors` is set to true. If I manually edit the targets/props shipped inside .NET7 SDK to delete all the prior shipped `CodeAnalysisTreatWarningsAsErrors` logic, then setting `CodeAnalysisTreatWarningsAsErrors` also works fine.
@jmarolf @Youssef1313 for review |
{ | ||
result.AppendLine(FileElement(Path.Combine(globalAnalyzerConfigsDir, editorconfig), $"build\\config")); | ||
result.AppendLine(FileElement(Path.Combine(globalAnalyzerConfigsDir, globalconfig), $"buildtransitive\\config")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Youssef1313 This is the fix to generate config files in buildtransitive
folder next to props/targets
React to package structure updates in dotnet/roslyn-analyzers#6325 and dotnet/roslyn-analyzers#6427 to generate props/targets/config files in `buildtransitive` folder
479771d
to
1d7244a
Compare
/azp run |
Azure Pipelines successfully started running 3 pipeline(s). |
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## main #6427 +/- ##
=======================================
Coverage 96.14% 96.15%
=======================================
Files 1365 1365
Lines 317494 317494
Branches 10269 10269
=======================================
+ Hits 305269 305271 +2
+ Misses 9791 9787 -4
- Partials 2434 2436 +2 |
Thank you for the review @Youssef1313 |
React to package structure updates in dotnet/roslyn-analyzers#6325 and dotnet/roslyn-analyzers#6427 to generate props/targets/config files in `buildtransitive` folder
[main] Update dependencies from dotnet/roslyn-analyzers - Update GenerateLayout.targets React to package structure updates in dotnet/roslyn-analyzers#6325 and dotnet/roslyn-analyzers#6427 to generate props/targets/config files in `buildtransitive` folder - Update GenerateLayout.targets
Fixes [AB#1726853](https://devdiv.visualstudio.com/DevDiv/_workitems/edit/1726853) dotnet#6427 re-implemented CodeAnalysisTreatWarningsAsErrors support using global config files instead of appending CA rule IDs to WarningsAsErrors and WarningsNotAsErrors properties. However, this new implementation only works as expected for `CodeAnalysisTreatWarningsAsErrors = true` case, but doesn't prevent escalating CA warnings to errors for `CodeAnalysisTreatWarningsAsErrors = false` and `TreatWarningsAsErrors = true` case. I am restoring the WarningsNotAsErrors logic deleted from dotnet#6427 to fix this case. I am also planning to file a separate tracking issue in Roslyn to see if we can implement this whole CodeAnalysisTreatWarningsAsErrors functionality in the compiler layer itself, instead of the current hybrid implementations in this repo, which seems to be quite a bit fragile.
Fixes [AB#1726853](https://devdiv.visualstudio.com/DevDiv/_workitems/edit/1726853) dotnet#6427 re-implemented CodeAnalysisTreatWarningsAsErrors support using global config files instead of appending CA rule IDs to WarningsAsErrors and WarningsNotAsErrors properties. However, this new implementation only works as expected for `CodeAnalysisTreatWarningsAsErrors = true` case, but doesn't prevent escalating CA warnings to errors for `CodeAnalysisTreatWarningsAsErrors = false` and `TreatWarningsAsErrors = true` case. I am restoring the WarningsNotAsErrors logic deleted from dotnet#6427 to fix this case. I am also planning to file a separate tracking issue in Roslyn to see if we can implement this whole CodeAnalysisTreatWarningsAsErrors functionality in the compiler layer itself, instead of the current hybrid implementations in this repo, which seems to be quite a bit fragile.
Fixes #6281
Prior implementation for
CodeAnalysisTreatWarningsAsErrors
passed/warnaserror+:CAxxxx
to the compiler command line for each CA rule ID. This led to couple of issues:The new implementation updates our globalconfig tooling to generate parallel globalconfigs with
_warnaserror
suffix, such that rules which would have had effective warning severity are set to error severity in the new globalconfig files. The targets/props that picks the appropriate globalconfig based on theAnalysisLevel
property now chooses the file with_warnaserror
suffix if user has enabled code analysis warnings to be treated as errors.Another couple of notes:
CodeAnalysisTreatWarningsAsErrors
has already shipped in .NET7 and prior SDKs, we use a separate propertyEffectiveCodeAnalysisTreatWarningsAsErrors
, so users using the newer NuGet package, but older .NET SDK can still get this functionality. Users that move to the newer .NET8 preview SDK with this fix can useCodeAnalysisTreatWarningsAsErrors
itself.buildTransitive
directory #6325 for globalconfig files to be correctly mapped.I have verified that
CodeAnalysisTreatWarningsAsErrors
works fine with the locally built package whenEffectiveCodeAnalysisTreatWarningsAsErrors
is set to true. If I manually edit the targets/props shipped inside .NET7 SDK to delete all the prior shippedCodeAnalysisTreatWarningsAsErrors
logic, then settingCodeAnalysisTreatWarningsAsErrors
also works fine.