Skip to content

Commit

Permalink
Strongly typed the modifier checks in NamingConventionsAnalyzer
Browse files Browse the repository at this point in the history
  • Loading branch information
Vannevelj committed Jun 3, 2015
1 parent 52beabe commit 0030d15
Showing 1 changed file with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Collections.Immutable;
using System.Linq;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;
Expand Down Expand Up @@ -44,11 +43,16 @@ private void AnalyzeSymbol(SyntaxNodeAnalysisContext context)

foreach (var variable in nodeAsField.Declaration.Variables)
{
if (nodeAsField.Modifiers.Any(x => new[] { "internal", "protected", "public" }.Contains(x.Text)))
var modifiers = nodeAsField.Modifiers;

if (modifiers.Any(SyntaxKind.InternalKeyword) ||
modifiers.Any(SyntaxKind.ProtectedKeyword) ||
modifiers.Any(SyntaxKind.PublicKeyword))
{
CheckNaming(variable.Identifier, "field", NamingConvention.UpperCamelCase, context);
}
else if (nodeAsField.Modifiers.Any(x => x.Text == "private") || nodeAsField.Modifiers.Count == 0 /* no access modifier defaults to private */)
else if (modifiers.Any(SyntaxKind.PrivateKeyword) ||
nodeAsField.Modifiers.Count == 0 /* no access modifier defaults to private */)
{
CheckNaming(variable.Identifier, "field", NamingConvention.UnderscoreLowerCamelCase, context);
}
Expand Down

0 comments on commit 0030d15

Please sign in to comment.