protected override void Initialize(ParameterLoadingAnalysisContext context) { context.RegisterSyntaxNodeActionInNonGenerated( c => { var declaration = (InterfaceStatementSyntax)c.Node; if (!NamingHelper.IsRegexMatch(declaration.Identifier.ValueText, Pattern)) { c.ReportDiagnosticWhenActive(Diagnostic.Create(rule, declaration.Identifier.GetLocation(), Pattern)); } }, SyntaxKind.InterfaceStatement); }
protected override void Initialize(ParameterLoadingAnalysisContext context) { context.RegisterSyntaxNodeActionInNonGenerated( c => { var typeParameter = (TypeParameterSyntax)c.Node; if (!NamingHelper.IsRegexMatch(typeParameter.Identifier.ValueText, Pattern)) { c.ReportDiagnostic(Diagnostic.Create(rule, typeParameter.Identifier.GetLocation(), typeParameter.Identifier.ValueText, Pattern)); } }, SyntaxKind.TypeParameter); }
protected override void Initialize(ParameterLoadingAnalysisContext context) { context.RegisterSyntaxNodeActionInNonGenerated( c => { var parameterDeclaration = (ParameterSyntax)c.Node; if (parameterDeclaration.Identifier != null && !NamingHelper.IsRegexMatch(parameterDeclaration.Identifier.Identifier.ValueText, Pattern)) { c.ReportDiagnostic(Diagnostic.Create(Rule, parameterDeclaration.Identifier.Identifier.GetLocation(), Pattern)); } }, SyntaxKind.Parameter); }
protected override void Initialize(ParameterLoadingAnalysisContext context) { context.RegisterSyntaxNodeActionInNonGenerated( c => { var declaration = (NamespaceStatementSyntax)c.Node; var declarationName = declaration.Name?.ToString(); if (declarationName != null && !NamingHelper.IsRegexMatch(declarationName, Pattern)) { c.ReportDiagnosticWhenActive(Diagnostic.Create(rule, declaration.Name.GetLocation(), Pattern)); } }, SyntaxKind.NamespaceStatement); }
protected override void Initialize(ParameterLoadingAnalysisContext context) { context.RegisterSyntaxNodeActionInNonGenerated( c => { var methodDeclaration = (MethodStatementSyntax)c.Node; if (!NamingHelper.IsRegexMatch(methodDeclaration.Identifier.ValueText, Pattern) && IsEventHandler(methodDeclaration, c.SemanticModel)) { c.ReportDiagnosticWhenActive(Diagnostic.Create(rule, methodDeclaration.Identifier.GetLocation(), methodDeclaration.Identifier.ValueText, Pattern)); } }, SyntaxKind.SubStatement); }
protected sealed override void Initialize(ParameterLoadingAnalysisContext context) { context.RegisterSyntaxNodeActionInNonGenerated( c => { var fieldDeclaration = (FieldDeclarationSyntax)c.Node; foreach (var name in fieldDeclaration.Declarators.SelectMany(v => v.Names).WhereNotNull()) { if (c.SemanticModel.GetDeclaredSymbol(name) is IFieldSymbol symbol && IsCandidateSymbol(symbol) && !NamingHelper.IsRegexMatch(symbol.Name, Pattern)) { c.ReportDiagnosticWhenActive(Diagnostic.Create(SupportedDiagnostics[0], name.GetLocation(), symbol.Name, Pattern)); } } }, SyntaxKind.FieldDeclaration); }
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; } if (!(context.SemanticModel.GetSymbolInfo(controlVar).Symbol is ILocalSymbol symbol) || !isDeclaredInLoop(symbol) || NamingHelper.IsRegexMatch(symbol.Name, Pattern)) { return; } context.ReportDiagnosticWhenActive(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 && !NamingHelper.IsRegexMatch(n.Identifier.ValueText, Pattern))) { if (!(context.SemanticModel.GetDeclaredSymbol(name) is ILocalSymbol symbol) || symbol.IsConst) { continue; } context.ReportDiagnosticWhenActive(Diagnostic.Create(rule, name.Identifier.GetLocation(), Pattern)); } }