private static void CheckSummaryHeader(SyntaxTreeAnalysisContext context, Compilation compilation, XmlFileHeader fileHeader) { var summaryElement = fileHeader.GetElement("summary"); if (summaryElement == null) { context.ReportDiagnostic(Diagnostic.Create(SA1639Descriptor, fileHeader.GetLocation(context.Tree))); return; } if (string.IsNullOrWhiteSpace(summaryElement.Value)) { var location = fileHeader.GetElementLocation(context.Tree, summaryElement); context.ReportDiagnostic(Diagnostic.Create(SA1639Descriptor, location)); } }
private static void CheckCompanyName(SyntaxTreeAnalysisContext context, Compilation compilation, XmlFileHeader fileHeader, XElement copyrightElement, StyleCopSettings settings) { var companyName = copyrightElement.Attribute("company")?.Value; if (string.IsNullOrWhiteSpace(companyName)) { var location = fileHeader.GetElementLocation(context.Tree, copyrightElement); context.ReportDiagnostic(Diagnostic.Create(SA1640Descriptor, location)); return; } if (compilation.IsAnalyzerSuppressed(SA1641Identifier)) { return; } if (string.CompareOrdinal(companyName, settings.DocumentationRules.CompanyName) != 0) { var location = fileHeader.GetElementLocation(context.Tree, copyrightElement); context.ReportDiagnostic(Diagnostic.Create(SA1641Descriptor, location)); } }
private static void CheckFile(SyntaxTreeAnalysisContext context, Compilation compilation, XmlFileHeader fileHeader, XElement copyrightElement, StyleCopSettings settings) { var fileAttribute = copyrightElement.Attribute("file"); if (fileAttribute == null) { var location = fileHeader.GetElementLocation(context.Tree, copyrightElement); context.ReportDiagnostic(Diagnostic.Create(SA1637Descriptor, location)); return; } if (compilation.IsAnalyzerSuppressed(SA1638Identifier)) { return; } var fileName = Path.GetFileName(context.Tree.FilePath); if (string.CompareOrdinal(fileAttribute.Value, fileName) != 0) { var location = fileHeader.GetElementLocation(context.Tree, copyrightElement); context.ReportDiagnostic(Diagnostic.Create(SA1638Descriptor, location)); } }
private static void CheckCopyrightText(SyntaxTreeAnalysisContext context, Compilation compilation, XmlFileHeader fileHeader, XElement copyrightElement, StyleCopSettings settings) { var copyrightText = copyrightElement.Value; if (string.IsNullOrWhiteSpace(copyrightText)) { var location = fileHeader.GetElementLocation(context.Tree, copyrightElement); context.ReportDiagnostic(Diagnostic.Create(SA1635Descriptor, location)); return; } if (compilation.IsAnalyzerSuppressed(SA1636Identifier)) { return; } if (string.Equals(settings.DocumentationRules.CopyrightText, DocumentationSettings.DefaultCopyrightText, StringComparison.OrdinalIgnoreCase)) { // The copyright text is meaningless until the company name is configured by the user. return; } if (string.CompareOrdinal(copyrightText.Trim(' ', '\r', '\n'), settings.DocumentationRules.CopyrightText) != 0) { var location = fileHeader.GetElementLocation(context.Tree, copyrightElement); context.ReportDiagnostic(Diagnostic.Create(SA1636Descriptor, location)); } }
private static void CheckCompanyName(SyntaxTreeAnalysisContext context, DocumentationSettings documentationSettings, Compilation compilation, XmlFileHeader fileHeader, XElement copyrightElement) { var companyName = copyrightElement.Attribute("company")?.Value; if (string.IsNullOrWhiteSpace(companyName)) { var location = fileHeader.GetElementLocation(context.Tree, copyrightElement); context.ReportDiagnostic(Diagnostic.Create(SA1640Descriptor, location)); return; } if (compilation.IsAnalyzerSuppressed(SA1641Identifier)) { return; } if (string.Equals(documentationSettings.CompanyName, DocumentationSettings.DefaultCompanyName, StringComparison.OrdinalIgnoreCase)) { // The company name is meaningless until configured by the user. return; } if (string.CompareOrdinal(companyName, documentationSettings.CompanyName) != 0) { var location = fileHeader.GetElementLocation(context.Tree, copyrightElement); context.ReportDiagnostic(Diagnostic.Create(SA1641Descriptor, location)); } }
private static void CheckCopyrightText(SyntaxTreeAnalysisContext context, DocumentationSettings documentationSettings, Compilation compilation, XmlFileHeader fileHeader, XElement copyrightElement) { var copyrightText = copyrightElement.Value; if (string.IsNullOrWhiteSpace(copyrightText)) { var location = fileHeader.GetElementLocation(context.Tree, copyrightElement); context.ReportDiagnostic(Diagnostic.Create(SA1635Descriptor, location)); return; } if (compilation.IsAnalyzerSuppressed(SA1636Identifier)) { return; } var settingsCopyrightText = documentationSettings.CopyrightText; if (string.Equals(settingsCopyrightText, DocumentationSettings.DefaultCopyrightText, StringComparison.OrdinalIgnoreCase)) { // The copyright text is meaningless until the company name is configured by the user. return; } // trim any leading / trailing new line or whitespace characters (those are a result of the XML formatting) if (!CompareCopyrightText(documentationSettings, copyrightText.Trim('\r', '\n', ' ', '\t'))) { var location = fileHeader.GetElementLocation(context.Tree, copyrightElement); context.ReportDiagnostic(Diagnostic.Create(SA1636Descriptor, location)); } }