@@ -40,6 +40,13 @@ internal class SA1312VariableNamesMustBeginWithLowerCaseLetter : DiagnosticAnaly
4040
4141 private static readonly Action < CompilationStartAnalysisContext > CompilationStartAction = HandleCompilationStart ;
4242 private static readonly Action < SyntaxNodeAnalysisContext > VariableDeclarationAction = HandleVariableDeclaration ;
43+ private static readonly Action < SyntaxNodeAnalysisContext > CatchDeclarationAction = HandleCatchDeclaration ;
44+ private static readonly Action < SyntaxNodeAnalysisContext > QueryContinuationAction = HandleQueryContinuation ;
45+ private static readonly Action < SyntaxNodeAnalysisContext > FromClauseAction = HandleFromClause ;
46+ private static readonly Action < SyntaxNodeAnalysisContext > LetClauseAction = HandleLetClause ;
47+ private static readonly Action < SyntaxNodeAnalysisContext > JoinClauseAction = HandleJoinClause ;
48+ private static readonly Action < SyntaxNodeAnalysisContext > JoinIntoClauseAction = HandleJoinIntoClause ;
49+ private static readonly Action < SyntaxNodeAnalysisContext > ForEachStatementAction = HandleForEachStatement ;
4350
4451 /// <inheritdoc/>
4552 public override ImmutableArray < DiagnosticDescriptor > SupportedDiagnostics { get ; } =
@@ -54,6 +61,13 @@ public override void Initialize(AnalysisContext context)
5461 private static void HandleCompilationStart ( CompilationStartAnalysisContext context )
5562 {
5663 context . RegisterSyntaxNodeActionHonorExclusions ( VariableDeclarationAction , SyntaxKind . VariableDeclaration ) ;
64+ context . RegisterSyntaxNodeActionHonorExclusions ( CatchDeclarationAction , SyntaxKind . CatchDeclaration ) ;
65+ context . RegisterSyntaxNodeActionHonorExclusions ( QueryContinuationAction , SyntaxKind . QueryContinuation ) ;
66+ context . RegisterSyntaxNodeActionHonorExclusions ( FromClauseAction , SyntaxKind . FromClause ) ;
67+ context . RegisterSyntaxNodeActionHonorExclusions ( LetClauseAction , SyntaxKind . LetClause ) ;
68+ context . RegisterSyntaxNodeActionHonorExclusions ( JoinClauseAction , SyntaxKind . JoinClause ) ;
69+ context . RegisterSyntaxNodeActionHonorExclusions ( JoinIntoClauseAction , SyntaxKind . JoinIntoClause ) ;
70+ context . RegisterSyntaxNodeActionHonorExclusions ( ForEachStatementAction , SyntaxKind . ForEachStatement ) ;
5771 }
5872
5973 private static void HandleVariableDeclaration ( SyntaxNodeAnalysisContext context )
@@ -86,20 +100,60 @@ private static void HandleVariableDeclaration(SyntaxNodeAnalysisContext context)
86100 }
87101
88102 var identifier = variableDeclarator . Identifier ;
89- if ( identifier . IsMissing )
90- {
91- continue ;
92- }
103+ CheckIdentifier ( context , identifier ) ;
104+ }
105+ }
93106
94- string name = identifier . ValueText ;
95- if ( string . IsNullOrEmpty ( name ) || char . IsLower ( name [ 0 ] ) )
96- {
97- continue ;
98- }
107+ private static void HandleCatchDeclaration ( SyntaxNodeAnalysisContext context )
108+ {
109+ CheckIdentifier ( context , ( ( CatchDeclarationSyntax ) context . Node ) . Identifier ) ;
110+ }
111+
112+ private static void HandleQueryContinuation ( SyntaxNodeAnalysisContext context )
113+ {
114+ CheckIdentifier ( context , ( ( QueryContinuationSyntax ) context . Node ) . Identifier ) ;
115+ }
116+
117+ private static void HandleFromClause ( SyntaxNodeAnalysisContext context )
118+ {
119+ CheckIdentifier ( context , ( ( FromClauseSyntax ) context . Node ) . Identifier ) ;
120+ }
121+
122+ private static void HandleLetClause ( SyntaxNodeAnalysisContext context )
123+ {
124+ CheckIdentifier ( context , ( ( LetClauseSyntax ) context . Node ) . Identifier ) ;
125+ }
126+
127+ private static void HandleJoinClause ( SyntaxNodeAnalysisContext context )
128+ {
129+ CheckIdentifier ( context , ( ( JoinClauseSyntax ) context . Node ) . Identifier ) ;
130+ }
131+
132+ private static void HandleJoinIntoClause ( SyntaxNodeAnalysisContext context )
133+ {
134+ CheckIdentifier ( context , ( ( JoinIntoClauseSyntax ) context . Node ) . Identifier ) ;
135+ }
136+
137+ private static void HandleForEachStatement ( SyntaxNodeAnalysisContext context )
138+ {
139+ CheckIdentifier ( context , ( ( ForEachStatementSyntax ) context . Node ) . Identifier ) ;
140+ }
99141
100- // Variable names must begin with lower-case letter
101- context . ReportDiagnostic ( Diagnostic . Create ( Descriptor , identifier . GetLocation ( ) , name ) ) ;
142+ private static void CheckIdentifier ( SyntaxNodeAnalysisContext context , SyntaxToken identifier )
143+ {
144+ if ( identifier . IsMissing )
145+ {
146+ return ;
102147 }
148+
149+ string name = identifier . ValueText ;
150+ if ( string . IsNullOrEmpty ( name ) || char . IsLower ( name [ 0 ] ) )
151+ {
152+ return ;
153+ }
154+
155+ // Variable names must begin with lower-case letter
156+ context . ReportDiagnostic ( Diagnostic . Create ( Descriptor , identifier . GetLocation ( ) , name ) ) ;
103157 }
104158 }
105159}
0 commit comments