Skip to content

Commit

Permalink
if no access modifier exist the field is private
Browse files Browse the repository at this point in the history
  • Loading branch information
mary-georgiou-sonarsource committed Feb 17, 2023
1 parent c906d02 commit 47f6635
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
Expand Up @@ -49,8 +49,9 @@ public sealed class StaticFieldVisible : SonarDiagnosticAnalyzer
: Enumerable.Empty<Diagnostic>();

private static bool FieldIsRelevant(FieldDeclarationSyntax node) =>
!node.Modifiers.Any(SyntaxKind.PrivateKeyword)
&& node.Modifiers.Any(SyntaxKind.StaticKeyword)
node.Modifiers.Any(SyntaxKind.StaticKeyword)
&& node.Modifiers.Count > 1
&& !node.Modifiers.Any(SyntaxKind.PrivateKeyword)
&& !node.Modifiers.Any(SyntaxKind.ReadOnlyKeyword);

private static bool FieldIsThreadSafe(IFieldSymbol fieldSymbol) =>
Expand Down
Expand Up @@ -20,8 +20,7 @@ public class StaticFieldVisible

private static double Pi8 = 3.14;
private double Pi9 = 3.14;
static double Pi10 = 3.14; // Noncompliant "internal" is the default if no access modifier is specified
// https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/access-modifiers
static double Pi10 = 3.14; // Compliant - if not access modifier exist the field is private
public readonly double Pi11 = 3.14;

[ThreadStatic]
Expand Down

0 comments on commit 47f6635

Please sign in to comment.