private static void ProcessComments(SyntaxNodeAnalysisContext context, List <SyntaxTrivia> comments, Location objectLocation, string objectName) { const int maxNumberOfLinesForComments = 5; var singleLineComments = comments.Where(a => a.IsKind(SyntaxKind.SingleLineCommentTrivia)).ToList(); var multiLineComments = comments.Where(a => a.IsKind(SyntaxKind.MultiLineCommentTrivia)).ToList(); if (singleLineComments.Count > 0 && multiLineComments.Count > 0) { DiagnosticsManager.CreateCommentsTooLongDiagnostic(context, objectLocation, Rule, $"{objectName} has both multiline and single line comments. Please use only one type of comments."); } else if (singleLineComments.Count > maxNumberOfLinesForComments) { DiagnosticsManager.CreateCommentsTooLongDiagnostic(context, objectLocation, Rule, $"{objectName} has more than {maxNumberOfLinesForComments} lines comments. Please use no more than {maxNumberOfLinesForComments} lines of comments."); } else if (multiLineComments.Count > 1) { DiagnosticsManager.CreateCommentsTooLongDiagnostic(context, objectLocation, Rule, $"{objectName} has multiple MultiLines comments. Please use no more than 1 MultiLines of comments."); } else if (multiLineComments.Count == 1) { var numberOfLines = RegexManager.NumberOfLines(multiLineComments[0].ToFullString()); if (numberOfLines > maxNumberOfLinesForComments) { DiagnosticsManager.CreateCommentsTooLongDiagnostic(context, objectLocation, Rule, $"{objectName} has more than {maxNumberOfLinesForComments} lines comments. Please use no more than {maxNumberOfLinesForComments} lines of comments."); } } }
private static void ProcessDocumentationComments(SyntaxNodeAnalysisContext context, Location declarationLocation, string declarationName, int threshold) { var docummentation = CommentsManager.ExtractDocumentationComment(context.Node); if (docummentation != null) { var numberOfLines = RegexManager.NumberOfLines(docummentation.Content.ToFullString()); if (numberOfLines > threshold) { DiagnosticsManager.CreateCommentsTooLongDiagnostic(context, declarationLocation, Rule, declarationName, threshold); } } }
public void ReturnTheCorrectNumberOfLinesForTheInputString(string inputString, int expectedRowCount) { var lineCount = regexManager.NumberOfLines(inputString); lineCount.Should().Be(expectedRowCount); }