-
Notifications
You must be signed in to change notification settings - Fork 226
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
Refactor the code to only use 'IsPubliclyAccessible' #544
Conversation
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.
Double-check that the rules are consistent with rspecs.
Otherwise, LGTM.
@@ -29,7 +29,7 @@ private class MyPrivateSubClass | |||
|
|||
protected class MyProtectedSubClass | |||
{ | |||
public double Pi4 = 3.14; | |||
public double Pi4 = 3.14; // Noncompliant |
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.
Double-check (if you haven't already) that the behaviour is consistent with rspec.
@@ -61,7 +61,7 @@ protected sealed override void Initialize(SonarAnalysisContext context) | |||
|
|||
if (containingMethod == null || | |||
containingMethod.IsOverride || | |||
!containingMethod.IsPublicApi() || | |||
!containingMethod.IsPubliclyAccessible() || |
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.
Double-check with rspec.
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.
Minor changes, otherwise LGTM
if (symbol == null || !symbol.IsPublicApi()) | ||
|
||
if (symbol != null && | ||
symbol.GetEffectiveAccessibility() == Accessibility.Public) |
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.
You could remove the previous check, GetEffectiveVisibility will handle the null
{ | ||
return false; | ||
} | ||
|
||
var effectiveAccessibility = GetEffectiveAccessibility(symbol); | ||
|
||
return effectiveAccessibility == Accessibility.Public || |
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.
I don't if using a HashSet would be faster...
return result; | ||
} | ||
|
||
public static bool IsPubliclyAccessible(this ISymbol symbol) | ||
{ | ||
if (symbol == null) |
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.
This is not needed. The next call will return NotApplicable... I don't know if this check will improve performance though... Probably not.
@@ -36,7 +36,7 @@ protected static bool FieldIsRelevant(IFieldSymbol fieldSymbol) | |||
return fieldSymbol != null && | |||
!fieldSymbol.IsStatic && | |||
!fieldSymbol.IsConst && | |||
fieldSymbol.IsPublicApi() && | |||
fieldSymbol.GetEffectiveAccessibility() == Accessibility.Public && |
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.
Why not IsPubliclyAccessible here?
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.
Because we care only about public fields not protected.
@@ -58,7 +58,7 @@ protected sealed override void Initialize(SonarAnalysisContext context) | |||
var symbol = c.SemanticModel.GetDeclaredSymbol(anyVariable) as IFieldSymbol; | |||
if (symbol == null || | |||
!symbol.IsConst || | |||
!symbol.IsPublicApi()) | |||
symbol.GetEffectiveAccessibility()!= Accessibility.Public) |
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.
Spaces around !=
No description provided.