protected override void Initialize(ParameterLoadingAnalysisContext context)
        {
            context.RegisterSyntaxNodeActionInNonGenerated(
                c =>
            {
                var methodDeclaration = (MethodStatementSyntax)c.Node;
                if (!FieldNameChecker.IsRegexMatch(methodDeclaration.Identifier.ValueText, Pattern))
                {
                    c.ReportDiagnostic(Diagnostic.Create(Rule, methodDeclaration.Identifier.GetLocation(),
                                                         "function", methodDeclaration.Identifier.ValueText, Pattern));
                }
            },
                SyntaxKind.FunctionStatement);

            context.RegisterSyntaxNodeActionInNonGenerated(
                c =>
            {
                var methodDeclaration = (MethodStatementSyntax)c.Node;
                if (!FieldNameChecker.IsRegexMatch(methodDeclaration.Identifier.ValueText, Pattern) &&
                    !EventHandlerName.IsEventHandler(methodDeclaration, c.SemanticModel))
                {
                    c.ReportDiagnostic(Diagnostic.Create(Rule, methodDeclaration.Identifier.GetLocation(),
                                                         "procedure", methodDeclaration.Identifier.ValueText, Pattern));
                }
            },
                SyntaxKind.SubStatement);
        }
Esempio n. 2
0
 protected override void Initialize(ParameterLoadingAnalysisContext context)
 {
     context.RegisterSyntaxNodeActionInNonGenerated(
         c =>
     {
         var enumDeclaration = (EnumStatementSyntax)c.Node;
         if (!FieldNameChecker.IsRegexMatch(enumDeclaration.Identifier.ValueText, Pattern))
         {
             c.ReportDiagnostic(Diagnostic.Create(Rule, enumDeclaration.Identifier.GetLocation(), Pattern));
         }
     },
         SyntaxKind.EnumStatement);
 }
 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);
 }
Esempio n. 4
0
        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));
        }
Esempio n. 5
0
        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));
            }
        }