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 analyzers/tests for non-local diagnostics #6690

Merged
merged 2 commits into from
Jun 21, 2023

Conversation

mavasani
Copy link
Member

@mavasani mavasani commented Jun 16, 2023

Fixes #6598

Recommended to review ignoring whitespace differences

  • Move to latest Microsoft.CodeAnalysis package for unit tests
  • Fix analyzers reporting non-local diagnostics
  • Add comments to tests where CodeFixTestBehaviors.SkipLocalDiagnosticCheck cannot be removed
  • Also fixed a code fixer relying on implicit tracking node functionality, which fails after moving to latest MS.CA bits.

Fixes dotnet#6598

- Move to latest Microsoft.CodeAnalysis package for unit tests
- Fix analyzers reporting non-local diagnostics
- Add comments to tests where `CodeFixTestBehaviors.SkipLocalDiagnosticCheck` cannot be removed
- Also fixed a code fixer relying on implicit tracking node functionality, which fails after moving to latest MS.CA bits.
@mavasani mavasani requested a review from sharwell June 16, 2023 10:42
@mavasani mavasani requested a review from a team as a code owner June 16, 2023 10:42
@codecov
Copy link

codecov bot commented Jun 16, 2023

Codecov Report

Merging #6690 (cbb3352) into main (2f0301e) will increase coverage by 0.00%.
The diff coverage is 95.79%.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #6690   +/-   ##
=======================================
  Coverage   96.39%   96.39%           
=======================================
  Files        1379     1379           
  Lines      322416   322431   +15     
  Branches    10461    10464    +3     
=======================================
+ Hits       310784   310803   +19     
+ Misses       9139     9136    -3     
+ Partials     2493     2492    -1     

!fieldInitializerValue.ConstantValue.HasValue ||
!context.Options.MatchesConfiguredVisibility(DefaultRule, lastField, context.Compilation, defaultRequiredVisibility: SymbolVisibilityGroup.Internal | SymbolVisibilityGroup.Private) ||
!context.Options.MatchesConfiguredModifiers(DefaultRule, lastField, context.Compilation, defaultRequiredModifiers: SymbolModifiers.Static))
context.RegisterOperationAction(context =>
Copy link
Member

Choose a reason for hiding this comment

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

💡 This will be called a large number of times. It would be better to declare a Action<OperationAnalysisContext> in the containing scope and pass that in instead of allocating a new delegate for every field.

@@ -17,6 +17,14 @@ namespace Microsoft.NetCore.Analyzers.Runtime.UnitTests
{
public class SealInternalTypesTests
{
// NOTE: 'SealInternalTypes' analyzer reports a compilation end diagnostic.
// Code fixes are not yet supported for compilation end diagnostics,
Copy link
Member

Choose a reason for hiding this comment

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

Code fixes are not yet supported for compilation end diagnostics

❔ Does this apply to dotnet-format?

Copy link
Member Author

Choose a reason for hiding this comment

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

Does this apply to dotnet-format?

I am not sure.

End Sub

Private Shared Function HasEqualityOperator(type As INamedTypeSymbol) As Boolean
For Each method In type.GetMembers().OfType(Of IMethodSymbol)
Copy link
Member

Choose a reason for hiding this comment

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

💡 Would be better to iterate over GetMembers() and have the OfType<IMethodSymbol>() check in the body.

@CyrusNajmabadi
Copy link
Member

Fix analyzers reporting non-local diagnostics

We did doc this somewhere, right? Given the number of changes in roslyn itself, and here, this will def impact the ecossytem. The wins are so great, it's def worth it. I just want to make sure we did doc this so we can point people to the issue when they run into it on their end. thanks!

@mavasani
Copy link
Member Author

Merging the PR as-is to unblock Cyrus. I’ll address @sharwell’s feedback with a follow up PR later today.

@mavasani mavasani merged commit 455013a into dotnet:main Jun 21, 2023
11 checks passed
@mavasani mavasani deleted the NonLocalDiagnosticFixes branch June 21, 2023 01:06
@github-actions github-actions bot added this to the vNext milestone Jun 21, 2023
mavasani added a commit to mavasani/roslyn-analyzers that referenced this pull request Jun 21, 2023
mavasani added a commit that referenced this pull request Jun 22, 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.

Analyzers should not try to fix non-local diagnostics
3 participants