Skip to content

Commit

Permalink
Ignore hard tabs appearing within commented code
Browse files Browse the repository at this point in the history
  • Loading branch information
sharwell committed Sep 18, 2015
1 parent 2926117 commit dfdd191
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -146,19 +146,21 @@ public async Task TestInvalidTabsInCommentsAsync()
"\t\tpublic void Bar()\r\n" +
"\t\t{\r\n" +
"\t\t \t//\tComment\t\t1\r\n" +
" ////\tCommented Code\t\t1\r\n" +
"\t \t\t// Comment 2\r\n" +
"\t\t}\r\n" +
"\t}\r\n";

var fixedTestCode = @" public class Foo
{
public void Bar()
{
// Comment 1
// Comment 2
}
}
";
var fixedTestCode =
" public class Foo\r\n" +
" {\r\n" +
" public void Bar()\r\n" +
" {\r\n" +
" // Comment 1\r\n" +
" ////\tCommented Code\t\t1\r\n" +
" // Comment 2\r\n" +
" }\r\n" +
" }\r\n";

DiagnosticResult[] expected =
{
Expand All @@ -168,9 +170,9 @@ public void Bar()
this.CSharpDiagnostic().WithLocation(4, 1),
this.CSharpDiagnostic().WithLocation(5, 1),
this.CSharpDiagnostic().WithLocation(5, 5),
this.CSharpDiagnostic().WithLocation(6, 1),
this.CSharpDiagnostic().WithLocation(7, 1),
this.CSharpDiagnostic().WithLocation(8, 1),
this.CSharpDiagnostic().WithLocation(9, 1),
};

await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,16 @@ private static void HandleSyntaxTree(SyntaxTreeAnalysisContext context)

private static void HandleWhitespaceTrivia(SyntaxTreeAnalysisContext context, SyntaxTrivia trivia)
{
if (trivia.ToFullString().IndexOf('\t') < 0)
string fullString = trivia.ToFullString();
if (fullString.StartsWith("////"))
{
// This is a line of commented code.
return;
}

if (fullString.IndexOf('\t') < 0)
{
// No hard tabs were found.
return;
}

Expand Down

0 comments on commit dfdd191

Please sign in to comment.