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 5e94096
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ public sealed class StaticFieldVisible : SonarDiagnosticAnalyzer
: Enumerable.Empty<Diagnostic>();

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

Expand Down
Original file line number Diff line number Diff line change
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 5e94096

Please sign in to comment.