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

Fix regression in CodeAnalysisTreatWarningsAsErrors when set to false #6450

Merged

Conversation

mavasani
Copy link
Contributor

Fixes AB#1726853

#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 #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.
@mavasani mavasani requested a review from a team as a code owner January 20, 2023 07:56
@mavasani mavasani requested review from Youssef1313 and removed request for a team January 20, 2023 07:56
Comment on lines +1615 to +1624
<!--
Design-time target to handle 'CodeAnalysisTreatWarningsAsErrors = false' for the CA rule ids implemented in this package.
Note that a similar 'WarningsNotAsErrors' property group is present in the generated props file to ensure this functionality on command line builds.
-->
<Target Name=""_CodeAnalysisTreatWarningsAsErrors"" BeforeTargets=""CoreCompile"" Condition=""'$(DesignTimeBuild)' == 'true' OR '$(BuildingProject)' != 'true'"">
<PropertyGroup>
<EffectiveCodeAnalysisTreatWarningsAsErrors Condition=""'$(EffectiveCodeAnalysisTreatWarningsAsErrors)' == ''"">$(CodeAnalysisTreatWarningsAsErrors)</EffectiveCodeAnalysisTreatWarningsAsErrors>
<WarningsNotAsErrors Condition=""'$(EffectiveCodeAnalysisTreatWarningsAsErrors)' == 'false' and '$(TreatWarningsAsErrors)' == 'true'"">$(WarningsNotAsErrors);$(CodeAnalysisRuleIds)</WarningsNotAsErrors>
</PropertyGroup>
</Target>
Copy link
Member

Choose a reason for hiding this comment

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

Isn't this the same logic as in props? I'm not quite sure what is the need to wrap it in a target that runs only for design-time builds.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was added earlier to account for a regression. I am just restoring the old functionality here for WarningsNotAsErrors. Either way, I personally don't like any of the current CodeAnalysisTreatWarningsAsErrors implementations. I am going to drive implementing this in the core analyzer driver in Roslyn and delete all the code we have in this repo related to CodeAnalysisTreatWarningsAsErrors.

@codecov
Copy link

codecov bot commented Jan 20, 2023

Codecov Report

Merging #6450 (5db8a82) into main (b08c60a) will decrease coverage by 0.01%.
The diff coverage is n/a.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6450      +/-   ##
==========================================
- Coverage   96.15%   96.14%   -0.01%     
==========================================
  Files        1365     1365              
  Lines      317523   317523              
  Branches    10269    10269              
==========================================
- Hits       305301   305296       -5     
- Misses       9786     9789       +3     
- Partials     2436     2438       +2     

@mavasani mavasani merged commit df911e6 into dotnet:main Jan 20, 2023
@mavasani mavasani deleted the FixCodeAnalysisTreatWarningsAsErrorsRegression branch January 20, 2023 09:32
@github-actions github-actions bot added this to the vNext milestone Jan 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants