/// <summary>
        /// Analyzes node.
        /// </summary>
        /// <param name="context">The context.</param>
        private static void AnalyzeNode(SyntaxNodeAnalysisContext context)
        {
            FieldDeclarationSyntax node = context.Node as FieldDeclarationSyntax;

            // Only const field.
            if (!node.Modifiers.Any(SyntaxKind.ConstKeyword))
            {
                return;
            }

            if (Configuration.IsEnabledForPublicMembersOnly && PrivateMemberChecker.IsPrivateMember(node))
            {
                return;
            }

            DocumentationCommentTriviaSyntax commentTriviaSyntax = node
                                                                   .GetLeadingTrivia()
                                                                   .Select(o => o.GetStructure())
                                                                   .OfType <DocumentationCommentTriviaSyntax>()
                                                                   .FirstOrDefault();

            if (commentTriviaSyntax != null && CommentHelper.HasComment(commentTriviaSyntax))
            {
                return;
            }

            VariableDeclaratorSyntax field = node.DescendantNodes().OfType <VariableDeclaratorSyntax>().First();

            context.ReportDiagnostic(Diagnostic.Create(Rule, field.GetLocation()));
        }
示例#2
0
        /// <summary>
        /// Analyzes node.
        /// </summary>
        /// <param name="context">The context.</param>
        private static void AnalyzeNode(SyntaxNodeAnalysisContext context)
        {
            FieldDeclarationSyntax node = context.Node as FieldDeclarationSyntax;

            // Only const.
            if (!node.Modifiers.Any(SyntaxKind.ConstKeyword))
            {
                return;
            }

            DocumentationCommentTriviaSyntax commentTriviaSyntax = node
                                                                   .GetLeadingTrivia()
                                                                   .Select(o => o.GetStructure())
                                                                   .OfType <DocumentationCommentTriviaSyntax>()
                                                                   .FirstOrDefault();

            if (commentTriviaSyntax != null)
            {
                bool hasSummary = commentTriviaSyntax
                                  .ChildNodes()
                                  .OfType <XmlElementSyntax>()
                                  .Any(o => o.StartTag.Name.ToString().Equals(DocumentationHeaderHelper.Summary));

                if (hasSummary)
                {
                    return;
                }
            }

            VariableDeclaratorSyntax field = node.DescendantNodes().OfType <VariableDeclaratorSyntax>().First();

            context.ReportDiagnostic(Diagnostic.Create(Rule, field.GetLocation()));
        }
示例#3
0
        private static void ReportDiagnostic(SyntaxNodeAnalysisContext context, VariableDeclaratorSyntax variable, ExpressionSyntax initializerValue)
        {
            var props = new Dictionary <string, string> {
                { "identifier", variable.Identifier.Text }
            }.ToImmutableDictionary();
            var diag = Diagnostic.Create(Rule, variable.GetLocation(), props, initializerValue.ToString());

            context.ReportDiagnostic(diag);
        }
 private static void ReportDiagnostic(SyntaxNodeAnalysisContext context, VariableDeclaratorSyntax variable, ExpressionSyntax initializerValue)
 {
     var diag = Diagnostic.Create(Rule, variable.GetLocation(), variable.Identifier.ValueText, initializerValue.ToString());
     context.ReportDiagnostic(diag);
 }
        private static void ReportDiagnostic(SyntaxNodeAnalysisContext context, VariableDeclaratorSyntax variable, ExpressionSyntax initializerValue)
        {
            var diag = Diagnostic.Create(Rule, variable.GetLocation(), variable.Identifier.ValueText, initializerValue.ToString());

            context.ReportDiagnostic(diag);
        }