Пример #1
0
        protected override void Initialize(SonarAnalysisContext context)
        {
            context.RegisterSyntaxNodeActionInNonGenerated(c =>
            {
                if (c.ContainingSymbol.Kind != SymbolKind.NamedType)
                {
                    return;
                }
                var isTestProject = context.IsTestProject(c.Compilation, c.Options);
                CheckTypeName(c, isTestProject);
            },
                                                           SyntaxKind.ClassDeclaration,
                                                           SyntaxKind.InterfaceDeclaration,
                                                           SyntaxKind.StructDeclaration,
                                                           SyntaxKindEx.RecordDeclaration);

            context.RegisterSyntaxNodeActionInNonGenerated(
                c =>
            {
                var identifier = GetDeclarationIdentifier(c.Node);
                CheckMemberName(c.Node, identifier, c);
            },
                SyntaxKind.MethodDeclaration,
                SyntaxKind.PropertyDeclaration,
                SyntaxKindEx.LocalFunctionStatement);
        }
Пример #2
0
        protected void ReadParameters(SonarAnalysisContext context, CompilationAnalysisContext c)
        {
            var settings = PropertiesHelper.GetSettings(c.Options);
            var outPath  = context.ProjectConfiguration(c.Options).OutPath;

            // For backward compatibility with S4MSB <= 5.0
            if (outPath == null && c.Options.AdditionalFiles.FirstOrDefault(IsProjectOutFolderPath) is { } projectOutFolderAdditionalFile)
            {
                outPath = File.ReadAllLines(projectOutFolderAdditionalFile.Path).First();
            }
            if (settings.Any() && !string.IsNullOrEmpty(outPath))
            {
                IgnoreHeaderComments = PropertiesHelper.ReadIgnoreHeaderCommentsProperty(settings, c.Compilation.Language);
                AnalyzeGeneratedCode = PropertiesHelper.ReadAnalyzeGeneratedCodeProperty(settings, c.Compilation.Language);
                OutPath           = Path.Combine(outPath, c.Compilation.Language == LanguageNames.CSharp ? "output-cs" : "output-vbnet");
                IsAnalyzerEnabled = true;
                IsTestProject     = context.IsTestProject(c.Compilation, c.Options);
            }
        }
Пример #3
0
        protected override void Initialize(SonarAnalysisContext context)
        {
            context.RegisterSyntaxNodeAction(c =>
            {
                if (DiagnosticAnalyzerContextHelper.ShouldAnalyze(context, CSharpGeneratedCodeRecognizer.Instance, c.GetSyntaxTree(), c.Compilation, c.Options))
                {
                    var isTestProject = context.IsTestProject(c.Compilation, c.Options);
                    CheckTypeName(c, isTestProject);
                }
            },
                                             SyntaxKind.ClassDeclaration,
                                             SyntaxKind.InterfaceDeclaration,
                                             SyntaxKind.StructDeclaration);

            context.RegisterSyntaxNodeActionInNonGenerated(
                c =>
            {
                var identifier = GetDeclarationIdentifier(c.Node);
                CheckMemberName(c.Node, identifier, c);
            },
                SyntaxKind.MethodDeclaration,
                SyntaxKind.PropertyDeclaration,
                SyntaxKindEx.LocalFunctionStatement);
        }