private static void HandleDeclaration(SyntaxNodeAnalysisContext context, TypeSyntax returnType) { var predefinedType = returnType as PredefinedTypeSyntax; if (predefinedType != null && predefinedType.Keyword.IsKind(SyntaxKind.VoidKeyword)) { // There is no return value return; } var documentationStructure = context.Node.GetDocumentationCommentTriviaSyntax(); if (documentationStructure == null) { return; } if (documentationStructure.Content.GetFirstXmlElement(XmlCommentHelper.InheritdocXmlTag) != null) { // Don't report if the documentation is inherited. return; } if (documentationStructure.Content.GetFirstXmlElement(XmlCommentHelper.ReturnsXmlTag) == null) { context.ReportDiagnostic(Diagnostic.Create(Descriptor, returnType.GetLocation())); } }
private static void HandleDeclaration(SyntaxNodeAnalysisContext context, TypeSyntax returnType) { var predefinedType = returnType as PredefinedTypeSyntax; if (predefinedType != null && predefinedType.Keyword.IsKind(SyntaxKind.VoidKeyword)) { // There is no return value return; } var documentationStructure = context.Node.GetDocumentationCommentTriviaSyntax(); if (documentationStructure == null) { return; } if (documentationStructure.Content.GetFirstXmlElement(XmlCommentHelper.InheritdocXmlTag) != null) { // Don't report if the documentation is inherited. return; } var relevantXmlElement = documentationStructure.Content.GetFirstXmlElement(XmlCommentHelper.ReturnsXmlTag); if (relevantXmlElement != null) { // A <returns> element was located. return; } relevantXmlElement = documentationStructure.Content.GetFirstXmlElement(XmlCommentHelper.IncludeXmlTag); if (relevantXmlElement != null) { var declaration = context.SemanticModel.GetDeclaredSymbol(context.Node, context.CancellationToken); var rawDocumentation = declaration?.GetDocumentationCommentXml(expandIncludes: true, cancellationToken: context.CancellationToken); XElement completeDocumentation = XElement.Parse(rawDocumentation, LoadOptions.None); if (completeDocumentation.Nodes().OfType<XElement>().Any(element => element.Name == XmlCommentHelper.InheritdocXmlTag)) { // Ignore nodes with an <inheritdoc/> tag in the included XML. return; } if (completeDocumentation.Nodes().OfType<XElement>().Any(element => element.Name == XmlCommentHelper.ReturnsXmlTag)) { // A <returns> element was located. return; } } context.ReportDiagnostic(Diagnostic.Create(Descriptor, returnType.GetLocation())); }