Skip to content

Commit

Permalink
Skip analyzing files with <autogenerated /> in its header
Browse files Browse the repository at this point in the history
We already recognized <auto-generated />. The original StyleCop also recognized <autogenerated />. So this brings us up to parity with that.

Fixes DotNetAnalyzers#833
  • Loading branch information
AArnott committed May 15, 2015
1 parent acb3ffb commit 61c33eb
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -915,6 +915,9 @@ public void SomeMethod() { }
await this.VerifyCSharpDiagnosticAsync(testCodeWithDocumentation, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
}

/// <summary>
/// Verifies that we recognize the auto-generated xml element.
/// </summary>
[Fact]
public async Task TestSkipAutoGeneratedCodeAsync()
{
Expand All @@ -928,6 +931,30 @@ public async Task TestSkipAutoGeneratedCodeAsync()
// </auto-generated>
//------------------------------------------------------------------------------
public class OuterClass
{
public void SomeMethod() { }
}";

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

/// <summary>
/// Verifies that we recognize the autogenerated xml element.
/// </summary>
[Fact]
public async Task TestSkipAutoGeneratedCode2Async()
{
var testCode = @"//------------------------------------------------------------------------------
// <autogenerated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.0
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </autogenerated>
//------------------------------------------------------------------------------
public class OuterClass
{
public void SomeMethod() { }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,10 @@ private static bool HasAutoGeneratedComment(SyntaxTree tree, CancellationToken c
}

var comments = trivia.Where(t => t.IsKind(SyntaxKind.SingleLineCommentTrivia) || t.IsKind(SyntaxKind.MultiLineCommentTrivia));
return comments.Any(t => t.ToString().Contains("<auto-generated"));
return comments.Any(t => {
string s = t.ToString();
return s.Contains("<auto-generated") || s.Contains("<autogenerated");
});
}

/// <summary>
Expand Down

0 comments on commit 61c33eb

Please sign in to comment.