Skip to content

Commit

Permalink
Merge pull request #1219 from vweijsters/fix-SA1514
Browse files Browse the repository at this point in the history
Fixed issue with SA1514
  • Loading branch information
sharwell committed Aug 16, 2015
2 parents 548dacb + effd2a7 commit 8aed469
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -714,6 +714,51 @@ public void TestMethod() { }
await this.VerifyCSharpFixAsync(testCode, fixedCode).ConfigureAwait(false);
}

/// <summary>
/// Verifies that comments before documentation are properly handled, when the comment is preceded by empty lines.
/// </summary>
/// <returns>A <see cref="Task"/> representing the asynchronous unit test.</returns>
[Fact]
public async Task TestDocumenationPrecededByCommentNotReportedForLooseCommentAsync()
{
var testCode = @"namespace TestNamespace
{
using System;
// some comment
/// <summary>
/// some documentation.
/// </summary>
public class TestClass
{
}
}
";
var fixedCode = @"namespace TestNamespace
{
using System;
// some comment
/// <summary>
/// some documentation.
/// </summary>
public class TestClass
{
}
}
";

DiagnosticResult[] expected =
{
this.CSharpDiagnostic().WithLocation(6, 5)
};

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

/// <summary>
/// Verifies that trailing comments before documentation are properly handled.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ private static void HandleDeclaration(SyntaxNodeAnalysisContext context)
var triviaList = TriviaHelper.GetContainingTriviaList(documentationHeader, out documentationHeaderIndex);
var eolCount = 0;
var done = false;
var hasComment = false;
for (var i = documentationHeaderIndex - 1; !done && (i >= 0); i--)
{
switch (triviaList[i].Kind())
Expand All @@ -131,17 +130,9 @@ private static void HandleDeclaration(SyntaxNodeAnalysisContext context)
eolCount++;
done = true;
break;
case SyntaxKind.SingleLineCommentTrivia:
if (triviaList[i].GetLine() != triviaList[i].Token.GetLine())
{
eolCount--;
}

hasComment = true;
break;
default:
done = true;
return;
break;
}
}

Expand All @@ -151,7 +142,7 @@ private static void HandleDeclaration(SyntaxNodeAnalysisContext context)
return;
}

if (!done && !hasComment)
if (!done)
{
var prevToken = documentationHeader.Token.GetPreviousToken();
if (prevToken.IsKind(SyntaxKind.OpenBraceToken))
Expand Down

0 comments on commit 8aed469

Please sign in to comment.