protected override void Initialize(ParameterLoadingAnalysisContext context) { context.RegisterSyntaxNodeActionInNonGenerated( c => { var declaration = (InterfaceStatementSyntax)c.Node; if (!FieldNameChecker.IsRegexMatch(declaration.Identifier.ValueText, Pattern)) { c.ReportDiagnostic(Diagnostic.Create(Rule, declaration.Identifier.GetLocation(), Pattern)); } }, SyntaxKind.InterfaceStatement); }
protected override void Initialize(ParameterLoadingAnalysisContext context) { context.RegisterSyntaxNodeActionInNonGenerated( c => { var declaration = (NamespaceStatementSyntax)c.Node; var declarationName = declaration.Name?.ToString(); if (declarationName != null && !FieldNameChecker.IsRegexMatch(declarationName, Pattern)) { c.ReportDiagnostic(Diagnostic.Create(Rule, declaration.Name.GetLocation(), Pattern)); } }, SyntaxKind.NamespaceStatement); }
private void ProcessLoop <T>(T loop, Func <T, VisualBasicSyntaxNode> GetControlVariable, Func <ILocalSymbol, bool> isDeclaredInLoop, SyntaxNodeAnalysisContext context) { var controlVar = GetControlVariable(loop); if (!(controlVar is IdentifierNameSyntax)) { return; } var symbol = context.SemanticModel.GetSymbolInfo(controlVar).Symbol as ILocalSymbol; if (symbol == null || !isDeclaredInLoop(symbol) || FieldNameChecker.IsRegexMatch(symbol.Name, Pattern)) { return; } context.ReportDiagnostic(Diagnostic.Create(Rule, controlVar.GetLocation(), Pattern)); }
private void ProcessVariableDeclarator(SyntaxNodeAnalysisContext context) { var declarator = (VariableDeclaratorSyntax)context.Node; if (declarator.Parent is FieldDeclarationSyntax) { return; } foreach (var name in declarator.Names .Where(n => n != null && !FieldNameChecker.IsRegexMatch(n.Identifier.ValueText, Pattern))) { var symbol = context.SemanticModel.GetDeclaredSymbol(name) as ILocalSymbol; if (symbol == null || symbol.IsConst) { continue; } context.ReportDiagnostic(Diagnostic.Create(Rule, name.Identifier.GetLocation(), Pattern)); } }