Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix SA1512 blank line reported between single line comment and documentation comment #1149

Merged
merged 2 commits into from
Aug 8, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,73 @@ namespace Foo
await this.VerifyCSharpFixAsync(testCode, fixedTestCode).ConfigureAwait(false);
}

/// <summary>
/// Verifies that the analyzer will properly handle comments followed by single line documentation comments.
/// </summary>
/// <returns>A <see cref="Task"/> representing the asynchronous unit test.</returns>
[Fact]
public async Task TestCommentFollowedBySingleLineDocumenationCommentAsync()
{
var testCode = @"// some comment

/// <summary>Test summary.</summary>
public class TestClass
{
// another comment

/// <summary>Test summary.</summary>
public void TestMethod() { }
}
";

await this.VerifyCSharpDiagnosticAsync(testCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
}

/// <summary>
/// Verifies that the analyzer will properly handle comments followed by multi-line documentation comments.
/// </summary>
/// <returns>A <see cref="Task"/> representing the asynchronous unit test.</returns>
[Fact]
public async Task TestCommentFollowedByMultiLineDocumentationCommentAsync()
{
var testCode = @"// some comment

/** <summary>Test summary.</summary> */
public class TestClass
{
// another comment

/** <summary>Test summary.</summary> */
public void TestMethod() { }
}
";

await this.VerifyCSharpDiagnosticAsync(testCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
}

/// <summary>
/// Verifies that the analyzer will properly handle comments followed by multi-line comments.
/// </summary>
/// <returns>A <see cref="Task"/> representing the asynchronous unit test.</returns>
[Fact]
public async Task TestCommentFollowedByMultiLineCommentAsync()
{
var testCode = @"namespace TestNamespace {
// some comment

/* multi-line comment */
internal class TestClass
{
// another comment

/* another multi-line comment */
}
}
";

await this.VerifyCSharpDiagnosticAsync(testCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
}

/// <inheritdoc/>
protected override IEnumerable<DiagnosticAnalyzer> GetCSharpDiagnosticAnalyzers()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,17 @@ private void HandleSyntaxTreeAnalysis(SyntaxTreeAnalysisContext context, Immutab
}
else
{
if ((triviaIndex < triviaList.Count) && triviaList[triviaIndex].IsKind(SyntaxKind.SingleLineCommentTrivia))
if (triviaIndex < triviaList.Count)
{
// ignore a single blank line in between two single line comments.
continue;
switch (triviaList[triviaIndex].Kind())
{
case SyntaxKind.SingleLineCommentTrivia:
case SyntaxKind.SingleLineDocumentationCommentTrivia:
case SyntaxKind.MultiLineCommentTrivia:
case SyntaxKind.MultiLineDocumentationCommentTrivia:
// ignore a single blank line in between two comments.
continue;
}
}
}

Expand Down