Skip to content

Improve PropertiesShouldNotBeWriteOnly performance #6736

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 1 commit into from
Jul 3, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -70,25 +70,26 @@ private static void AnalyzeSymbol(SymbolAnalysisContext context)
return;
}

// Only analyze externally visible properties by default
if (!context.Options.MatchesConfiguredVisibility(AddGetterRule, property, context.Compilation))
{
Debug.Assert(!context.Options.MatchesConfiguredVisibility(MakeMoreAccessibleRule, property, context.Compilation));
return;
}

Debug.Assert(context.Options.MatchesConfiguredVisibility(MakeMoreAccessibleRule, property, context.Compilation));
Debug.Assert(context.Options.MatchesConfiguredVisibility(MakeMoreAccessibleRule, property, context.Compilation) == context.Options.MatchesConfiguredVisibility(AddGetterRule, property, context.Compilation));

// We handled the non-CA1044 cases earlier. Now, we handle CA1044 cases
// If there is no getter then it is not accessible
if (property.IsWriteOnly)
{
context.ReportDiagnostic(property.CreateDiagnostic(AddGetterRule, property.Name));
// Only analyze externally visible properties by default
if (context.Options.MatchesConfiguredVisibility(AddGetterRule, property, context.Compilation))
{
context.ReportDiagnostic(property.CreateDiagnostic(AddGetterRule, property.Name));
}
}
// Otherwise if there is a setter, check for its relative accessibility
else if (!property.IsReadOnly && (property.GetMethod!.DeclaredAccessibility < property.SetMethod!.DeclaredAccessibility))
{
context.ReportDiagnostic(property.CreateDiagnostic(MakeMoreAccessibleRule, property.Name));
// Only analyze externally visible properties by default
if (context.Options.MatchesConfiguredVisibility(MakeMoreAccessibleRule, property, context.Compilation))
{
context.ReportDiagnostic(property.CreateDiagnostic(MakeMoreAccessibleRule, property.Name));
}
}
}
}
Expand Down