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

Re-implement CodeAnalysisTreatWarningsAsErrors with globalconfig files #6427

Merged

Conversation

mavasani
Copy link
Contributor

@mavasani mavasani commented Jan 12, 2023

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:

  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 Generate packages props and targets in buildTransitive directory #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.

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.
@mavasani mavasani requested a review from a team as a code owner January 12, 2023 10:29
@mavasani
Copy link
Contributor Author

@jmarolf @Youssef1313 for review

{
result.AppendLine(FileElement(Path.Combine(globalAnalyzerConfigsDir, editorconfig), $"build\\config"));
result.AppendLine(FileElement(Path.Combine(globalAnalyzerConfigsDir, globalconfig), $"buildtransitive\\config"));
Copy link
Contributor Author

@mavasani mavasani Jan 12, 2023

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

mavasani added a commit to dotnet/sdk that referenced this pull request Jan 12, 2023
React to package structure updates in dotnet/roslyn-analyzers#6325 and dotnet/roslyn-analyzers#6427 to generate props/targets/config files in `buildtransitive` folder
@mavasani mavasani force-pushed the CodeAnalysisTreatWarningsAsErrors_GlobalConfigs branch from 479771d to 1d7244a Compare January 12, 2023 12:33
@mavasani
Copy link
Contributor Author

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 3 pipeline(s).

@codecov
Copy link

codecov bot commented Jan 12, 2023

Codecov Report

Merging #6427 (1d7244a) into main (7b6ad7e) will increase coverage by 0.00%.
The diff coverage is 100.00%.

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     

@mavasani
Copy link
Contributor Author

Thank you for the review @Youssef1313

@mavasani mavasani merged commit afee469 into dotnet:main Jan 13, 2023
@mavasani mavasani deleted the CodeAnalysisTreatWarningsAsErrors_GlobalConfigs branch January 13, 2023 04:08
@github-actions github-actions bot added this to the vNext milestone Jan 13, 2023
mavasani added a commit to dotnet/sdk that referenced this pull request Jan 16, 2023
React to package structure updates in dotnet/roslyn-analyzers#6325 and dotnet/roslyn-analyzers#6427 to generate props/targets/config files in `buildtransitive` folder
dotnet-maestro bot added a commit to dotnet/sdk that referenced this pull request Jan 17, 2023
[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
mavasani added a commit to mavasani/roslyn-analyzers that referenced this pull request Jan 20, 2023
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 added a commit to mavasani/roslyn-analyzers that referenced this pull request Jan 20, 2023
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.
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.

Some rules can no longer be silenced with an .editorconfig file in .NET 7
2 participants