diff --git a/analyzers/src/SonarAnalyzer.Common/Rules/CommentsShouldNotBeEmptyBase.cs b/analyzers/src/SonarAnalyzer.Common/Rules/CommentsShouldNotBeEmptyBase.cs index 2acea99fd14..b423874dc4c 100644 --- a/analyzers/src/SonarAnalyzer.Common/Rules/CommentsShouldNotBeEmptyBase.cs +++ b/analyzers/src/SonarAnalyzer.Common/Rules/CommentsShouldNotBeEmptyBase.cs @@ -62,10 +62,9 @@ private void CheckTrivia(SonarSyntaxTreeReportingContext context, IEnumerable trivia.Any() && trivia.All(x => string.IsNullOrWhiteSpace(GetCommentText(x))))) { - var start = partition.First().GetLocation().SourceSpan.Start; - var end = partition.Last().GetLocation().SourceSpan.End; - var location = Location.Create(context.Tree, TextSpan.FromBounds(start, end)); - context.ReportIssue(Diagnostic.Create(Rule, location)); + var location = partition.First().GetLocation(); + var secondary = partition.Skip(1).Select(x => x.GetLocation()); + context.ReportIssue(Diagnostic.Create(Rule, location, secondary)); } } diff --git a/analyzers/tests/SonarAnalyzer.UnitTest/TestCases/CommentsShouldNotBeEmpty.cs b/analyzers/tests/SonarAnalyzer.UnitTest/TestCases/CommentsShouldNotBeEmpty.cs index 095eb9350f8..1b5df0c4f73 100644 --- a/analyzers/tests/SonarAnalyzer.UnitTest/TestCases/CommentsShouldNotBeEmpty.cs +++ b/analyzers/tests/SonarAnalyzer.UnitTest/TestCases/CommentsShouldNotBeEmpty.cs @@ -10,7 +10,7 @@ public class SingleLine // // Noncompliant@-2 (a lot of whitespace before) - // + // // Noncompliant@-2 (a lot of whitespace after) @@ -75,6 +75,8 @@ public class SingleLine // // /// text // Noncompliant@-4 + // Secondary@-4 + // Secondary@-4 // // @@ -83,6 +85,8 @@ public class SingleLine // * text */ // Noncompliant@-6 + // Secondary@-6 + // Secondary@-6 // // @@ -91,10 +95,14 @@ public class SingleLine // * text */ // Noncompliant@-6 + // Secondary@-6 + // Secondary@-6 void Method() { - // Noncompliant@+2 + // Noncompliant@+4 + // Secondary@+4 + // Secondary@+4 // // @@ -106,6 +114,8 @@ void Method() // Noncompliant@-5 // Noncompliant@-5 + // Secondary@-5 + // Secondary@-5 // // @@ -136,7 +146,7 @@ public class SingleLineDocumentation /// /// // Noncompliant@-1 (a lot of whitespace before) - /// + /// // Noncompliant@-1 (a lot of whitespace after) /// @@ -188,7 +198,7 @@ public class MultiLine /* */ /* */ // Noncompliant@-1 (a lot of whitespace inside) - /**/ + /**/ // Noncompliant@-1 (a lot of whitespace after) // Noncompliant@+1 @@ -286,7 +296,7 @@ public class MultiLineDocumentation /** */ /** */ // Noncompliant@-1 (a lot of whitespace inside) - /***/ + /***/ // Noncompliant@-1 (a lot of whitespace after) // Noncompliant@+1 @@ -381,7 +391,9 @@ hey there /// -// Noncompliant@+2 +// Noncompliant@+4 +// Secondary@+4 +// Secondary@+4 // // diff --git a/analyzers/tests/SonarAnalyzer.UnitTest/TestCases/CommentsShouldNotBeEmpty.vb b/analyzers/tests/SonarAnalyzer.UnitTest/TestCases/CommentsShouldNotBeEmpty.vb index 8d5000fd227..272f3cb2422 100644 --- a/analyzers/tests/SonarAnalyzer.UnitTest/TestCases/CommentsShouldNotBeEmpty.vb +++ b/analyzers/tests/SonarAnalyzer.UnitTest/TestCases/CommentsShouldNotBeEmpty.vb @@ -14,7 +14,7 @@ Dim b = 42 ''' Ipsem Lorum Dim c = 42 ''' - ' + ' ' Noncompliant@-2 (whitespace) @@ -29,13 +29,17 @@ ' ' - ' Noncompliant@+2 ' ' ' ' + ' Noncompliant@-5 + ' Secondary@-5 + ' Secondary@-5 + ' Secondary@-5 + ' Noncompliant@+2 ' @@ -45,6 +49,8 @@ ' ' Noncompliant@-4 + ' Secondary@-4 + ' Secondary@-4 ' * ' Ipsem Lorum @@ -80,10 +86,12 @@ ' ''' Ipsem Lorum ' Noncompliant@-4 + ' Secondary@-4 + ' Secondary@-4 End Sub Public Sub DocumentationComment() - ''' + ''' ' Noncompliant@-1 (whitespace) ''' * @@ -133,12 +141,15 @@ End Class ''' -' Noncompliant@+2 ' ' ' +' Noncompliant@-4 +' Secondary@-4 +' Secondary@-4 + ' Noncompliant@+1 ''' '''