private static void HandleSyntaxTreeAxtion(SyntaxTreeAnalysisContext context, Compilation compilation)
        {
            var root = context.Tree.GetRoot(context.CancellationToken);
            var settings = context.GetStyleCopSettings();

            // don't process empty files
            if (root.FullSpan.IsEmpty)
            {
                return;
            }

            if (settings.DocumentationRules.XmlHeader)
            {
                var fileHeader = FileHeaderHelpers.ParseXmlFileHeader(root);
                if (fileHeader.IsMissing)
                {
                    context.ReportDiagnostic(Diagnostic.Create(SA1633DescriptorMissing, fileHeader.GetLocation(context.Tree)));
                    return;
                }

                if (fileHeader.IsMalformed)
                {
                    context.ReportDiagnostic(Diagnostic.Create(SA1633DescriptorMalformed, fileHeader.GetLocation(context.Tree)));
                    return;
                }

                if (!compilation.IsAnalyzerSuppressed(SA1634Identifier))
                {
                    CheckCopyrightHeader(context, compilation, settings, fileHeader);
                }

                if (!compilation.IsAnalyzerSuppressed(SA1639Identifier))
                {
                    CheckSummaryHeader(context, compilation, fileHeader);
                }
            }
            else
            {
                var fileHeader = FileHeaderHelpers.ParseFileHeader(root);
                if (fileHeader.IsMissing)
                {
                    context.ReportDiagnostic(Diagnostic.Create(SA1633DescriptorMissing, fileHeader.GetLocation(context.Tree)));
                    return;
                }

                if (!compilation.IsAnalyzerSuppressed(SA1635Identifier))
                {
                    if (string.IsNullOrWhiteSpace(fileHeader.CopyrightText))
                    {
                        context.ReportDiagnostic(Diagnostic.Create(SA1635Descriptor, fileHeader.GetLocation(context.Tree)));
                        return;
                    }

                    if (compilation.IsAnalyzerSuppressed(SA1636Identifier))
                    {
                        return;
                    }

                    // make sure that both \n and \r\n are accepted from the settings.
                    var reformattedCopyrightText = settings.DocumentationRules.CopyrightText.Replace("\r\n", "\n").Replace("\n", Environment.NewLine);
                    if (string.CompareOrdinal(fileHeader.CopyrightText, reformattedCopyrightText) != 0)
                    {
                        context.ReportDiagnostic(Diagnostic.Create(SA1636Descriptor, fileHeader.GetLocation(context.Tree)));
                    }
                }
            }
        }
        private static void HandleSyntaxTreeAction(SyntaxTreeAnalysisContext context, Compilation compilation)
        {
            var root = context.Tree.GetRoot(context.CancellationToken);
            var settings = context.GetStyleCopSettings();

            // don't process empty files
            if (root.FullSpan.IsEmpty)
            {
                return;
            }

            if (settings.DocumentationRules.XmlHeader)
            {
                var fileHeader = FileHeaderHelpers.ParseXmlFileHeader(root);
                if (fileHeader.IsMissing)
                {
                    context.ReportDiagnostic(Diagnostic.Create(SA1633DescriptorMissing, fileHeader.GetLocation(context.Tree)));
                    return;
                }

                if (fileHeader.IsMalformed)
                {
                    context.ReportDiagnostic(Diagnostic.Create(SA1633DescriptorMalformed, fileHeader.GetLocation(context.Tree)));
                    return;
                }

                if (!compilation.IsAnalyzerSuppressed(SA1634Identifier))
                {
                    CheckCopyrightHeader(context, compilation, settings, fileHeader);
                }

                if (!compilation.IsAnalyzerSuppressed(SA1639Identifier))
                {
                    CheckSummaryHeader(context, compilation, fileHeader);
                }
            }
            else
            {
                var fileHeader = FileHeaderHelpers.ParseFileHeader(root);
                if (fileHeader.IsMissing)
                {
                    context.ReportDiagnostic(Diagnostic.Create(SA1633DescriptorMissing, fileHeader.GetLocation(context.Tree)));
                    return;
                }

                if (!compilation.IsAnalyzerSuppressed(SA1635Identifier))
                {
                    if (string.IsNullOrWhiteSpace(fileHeader.CopyrightText))
                    {
                        context.ReportDiagnostic(Diagnostic.Create(SA1635Descriptor, fileHeader.GetLocation(context.Tree)));
                        return;
                    }

                    if (compilation.IsAnalyzerSuppressed(SA1636Identifier))
                    {
                        return;
                    }

                    if (!CompareCopyrightText(fileHeader.CopyrightText, settings))
                    {
                        context.ReportDiagnostic(Diagnostic.Create(SA1636Descriptor, fileHeader.GetLocation(context.Tree)));
                        return;
                    }
                }
            }
        }
        private static void HandleSyntaxTreeAxtion(SyntaxTreeAnalysisContext context, Compilation compilation)
        {
            var root     = context.Tree.GetRoot(context.CancellationToken);
            var settings = context.GetStyleCopSettings();

            // don't process empty files
            if (root.FullSpan.IsEmpty)
            {
                return;
            }

            if (settings.DocumentationRules.XmlHeader)
            {
                var fileHeader = FileHeaderHelpers.ParseXmlFileHeader(root);
                if (fileHeader.IsMissing)
                {
                    context.ReportDiagnostic(Diagnostic.Create(SA1633DescriptorMissing, fileHeader.GetLocation(context.Tree)));
                    return;
                }

                if (fileHeader.IsMalformed)
                {
                    context.ReportDiagnostic(Diagnostic.Create(SA1633DescriptorMalformed, fileHeader.GetLocation(context.Tree)));
                    return;
                }

                if (!compilation.IsAnalyzerSuppressed(SA1634Identifier))
                {
                    CheckCopyrightHeader(context, compilation, settings, fileHeader);
                }

                if (!compilation.IsAnalyzerSuppressed(SA1639Identifier))
                {
                    CheckSummaryHeader(context, compilation, fileHeader);
                }
            }
            else
            {
                var fileHeader = FileHeaderHelpers.ParseFileHeader(root);
                if (fileHeader.IsMissing)
                {
                    context.ReportDiagnostic(Diagnostic.Create(SA1633DescriptorMissing, fileHeader.GetLocation(context.Tree)));
                    return;
                }

                if (!compilation.IsAnalyzerSuppressed(SA1635Identifier))
                {
                    if (string.IsNullOrWhiteSpace(fileHeader.CopyrightText))
                    {
                        context.ReportDiagnostic(Diagnostic.Create(SA1635Descriptor, fileHeader.GetLocation(context.Tree)));
                        return;
                    }

                    if (compilation.IsAnalyzerSuppressed(SA1636Identifier))
                    {
                        return;
                    }

                    // make sure that both \n and \r\n are accepted from the settings.
                    var reformattedCopyrightText = settings.DocumentationRules.CopyrightText.Replace("\r\n", "\n").Replace("\n", Environment.NewLine);
                    if (string.CompareOrdinal(fileHeader.CopyrightText, reformattedCopyrightText) != 0)
                    {
                        context.ReportDiagnostic(Diagnostic.Create(SA1636Descriptor, fileHeader.GetLocation(context.Tree)));
                    }
                }
            }
        }
        private static void HandleSyntaxTreeAction(SyntaxTreeAnalysisContext context, Compilation compilation)
        {
            var root     = context.Tree.GetRoot(context.CancellationToken);
            var settings = context.GetStyleCopSettings();

            // don't process empty files
            if (root.FullSpan.IsEmpty)
            {
                return;
            }

            if (settings.DocumentationRules.XmlHeader)
            {
                var fileHeader = FileHeaderHelpers.ParseXmlFileHeader(root);
                if (fileHeader.IsMissing)
                {
                    context.ReportDiagnostic(Diagnostic.Create(SA1633DescriptorMissing, fileHeader.GetLocation(context.Tree)));
                    return;
                }

                if (fileHeader.IsMalformed)
                {
                    context.ReportDiagnostic(Diagnostic.Create(SA1633DescriptorMalformed, fileHeader.GetLocation(context.Tree)));
                    return;
                }

                if (!compilation.IsAnalyzerSuppressed(SA1634Identifier))
                {
                    CheckCopyrightHeader(context, compilation, settings, fileHeader);
                }

                if (!compilation.IsAnalyzerSuppressed(SA1639Identifier))
                {
                    CheckSummaryHeader(context, compilation, fileHeader);
                }
            }
            else
            {
                var fileHeader = FileHeaderHelpers.ParseFileHeader(root);
                if (fileHeader.IsMissing)
                {
                    context.ReportDiagnostic(Diagnostic.Create(SA1633DescriptorMissing, fileHeader.GetLocation(context.Tree)));
                    return;
                }

                if (!compilation.IsAnalyzerSuppressed(SA1635Identifier))
                {
                    if (string.IsNullOrWhiteSpace(fileHeader.CopyrightText))
                    {
                        context.ReportDiagnostic(Diagnostic.Create(SA1635Descriptor, fileHeader.GetLocation(context.Tree)));
                        return;
                    }

                    if (compilation.IsAnalyzerSuppressed(SA1636Identifier))
                    {
                        return;
                    }

                    if (!CompareCopyrightText(fileHeader.CopyrightText, settings))
                    {
                        context.ReportDiagnostic(Diagnostic.Create(SA1636Descriptor, fileHeader.GetLocation(context.Tree)));
                        return;
                    }
                }
            }
        }
Ejemplo n.º 5
0
 internal static bool IsFileExcludedFromAnalysis(SyntaxTreeAnalysisContext context)
 {
     return(IsFileExcludedFromAnalysis(context.GetStyleCopSettings(context.CancellationToken), context.Options.GetSettingsFolder(), context.Tree));
 }