{"action":"created","comment":{"url":"https://api.github.com/repos/DotNetAnalyzers/StyleCopAnalyzers/pulls/comments/28846003","id":28846003,"diff_hunk":"@@ -0,0 +1,97 @@\n+﻿// This file originally obtained from \n+// https://raw.githubusercontent.com/code-cracker/code-cracker/08c1a01337964924eeed12be8b14c8ce8ec6b626/src/Common/CodeCracker.Common/Extensions/GeneratedCodeAnalysisExtensions.cs\n+// It is subject to the Apache License 2.0\n+// This file has been modified since obtaining it from its original source.\n+\n+namespace StyleCop.Analyzers\n+{\n+    using System.Linq;\n+    using System.Runtime.CompilerServices;\n+    using System.Text.RegularExpressions;\n+    using System.Threading;\n+    using Microsoft.CodeAnalysis;\n+    using Microsoft.CodeAnalysis.CSharp;\n+    using Microsoft.CodeAnalysis.CSharp.Syntax;\n+    using Microsoft.CodeAnalysis.Diagnostics;\n+\n+    internal static class GeneratedCodeAnalysisExtensions\n+    {\n+        /// <summary>\n+        /// A cache of the result of computing whether a document has an auto-generated header.\n+        /// </summary>\n+        /// <remarks>\n+        /// This allows many analyzers that run on every token in the file to avoid checking\n+        /// the same state in the document repeatedly.\n+        /// </remarks>\n+        private static readonly ConditionalWeakTable<SyntaxTree, StrongBox<bool?>> GeneratedHeaderPresentCheck = new ConditionalWeakTable<SyntaxTree, StrongBox<bool?>>();\n+\n+        internal static bool IsGenerated(this SyntaxNodeAnalysisContext context, CancellationToken cancellationToken) => (context.Node.SyntaxTree?.IsGenerated(cancellationToken) ?? false) || (context.Node?.IsGenerated() ?? false);\n+\n+        internal static bool IsGenerated(this SyntaxTreeAnalysisContext context, CancellationToken cancellationToken) => context.Tree?.IsGenerated(cancellationToken) ?? false;\n+\n+        internal static bool IsGenerated(this SymbolAnalysisContext context, CancellationToken cancellationToken)\n+        {\n+            if (context.Symbol == null) return false;\n+            foreach (var syntaxReference in context.Symbol.DeclaringSyntaxReferences)\n+            {\n+                if (syntaxReference.SyntaxTree.IsGenerated(cancellationToken)) return true;\n+                var root = syntaxReference.SyntaxTree.GetRoot(cancellationToken);\n+                var node = root?.FindNode(syntaxReference.Span);\n+                if (node.IsGenerated()) return true;\n+            }\n+            return false;\n+        }\n+\n+        internal static bool IsGenerated(this SyntaxNode node) => node.HasAttributeOnAncestorOrSelf(\"DebuggerNonUserCode\", \"GeneratedCode\");\n+\n+        internal static bool IsGenerated(this SyntaxTree tree, CancellationToken cancellationToken) => (tree.FilePath?.IsOnGeneratedFile() ?? false) || tree.HasAutoGeneratedComment(cancellationToken);\n+\n+        internal static bool HasAutoGeneratedComment(this SyntaxTree tree, CancellationToken cancellationToken)\n+        {\n+            StrongBox<bool?> cachedResult = GeneratedHeaderPresentCheck.GetOrCreateValue(tree);\n+            if (cachedResult.Value.HasValue)\n+            {\n+                return cachedResult.Value.Value;\n+            }\n+\n+            bool autoGenerated = HasAutoGeneratedCommentNoCache(tree, cancellationToken);\n+\n+            // Update the strongbox's value with our computed result.\n+            // This doesn't change the strongbox reference, and its presence in the\n+            // ConditionalWeakTable is already assured, so we're updating in-place.\n+            // In the event of a race condition with another thread that set the value,\n+            // we'll just be re-setting it to the same value.\n+            cachedResult.Value = autoGenerated;\n+\n+            return autoGenerated;\n+        }\n+\n+        private static bool HasAutoGeneratedCommentNoCache(SyntaxTree tree, CancellationToken cancellationToken)\n+        {\n+            var root = tree.GetRoot(cancellationToken);\n+\n+            if (root == null) return false;\n+            var firstToken = root.GetFirstToken();\n+            SyntaxTriviaList trivia;\n+            if (firstToken == default(SyntaxToken))\n+            {\n+                var token = ((CompilationUnitSyntax)root).EndOfFileToken;\n+                if (!token.HasLeadingTrivia) return false;\n+                trivia = token.LeadingTrivia;\n+            }\n+            else\n+            {\n+                if (!firstToken.HasLeadingTrivia) return false;\n+                trivia = firstToken.LeadingTrivia;\n+            }\n+\n+            var commentLines = trivia.Where(t => t.IsKind(SyntaxKind.SingleLineCommentTrivia)).Take(2).ToList();\n+            if (commentLines.Count != 2) return false;\n+            return commentLines[1].ToString() == \"// <auto-generated>\";","path":"StyleCop.Analyzers/StyleCop.Analyzers/GeneratedCodeAnalysisExtensions.cs","position":90,"original_position":90,"commit_id":"3a2fabf13193547b8c925ee827095e8d4104cc2c","original_commit_id":"3a2fabf13193547b8c925ee827095e8d4104cc2c","user":{"login":"sharwell","id":1408396,"avatar_url":"https://avatars.githubusercontent.com/u/1408396?v=3","gravatar_id":"","url":"https://api.github.com/users/sharwell","html_url":"https://github.com/sharwell","followers_url":"https://api.github.com/users/sharwell/followers","following_url":"https://api.github.com/users/sharwell/following{/other_user}","gists_url":"https://api.github.com/users/sharwell/gists{/gist_id}","starred_url":"https://api.github.com/users/sharwell/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sharwell/subscriptions","organizations_url":"https://api.github.com/users/sharwell/orgs","repos_url":"https://api.github.com/users/sharwell/repos","events_url":"https://api.github.com/users/sharwell/events{/privacy}","received_events_url":"https://api.github.com/users/sharwell/received_events","type":"User","site_admin":false},"body":"This may be \"too strict\", in the sense that it fails to exclude files that people assume would be excluded (e.g. due to spacing differences). Of particular concern is the example of generated code given in the [documentation for SA1633](http://stylecop.com/docs/SA1633.html) would not be considered auto-generated according to this implementation (both for being on the first line, and for being a self-closing XML element instead of the one shown here).","created_at":"2015-04-22T05:39:34Z","updated_at":"2015-04-22T05:39:34Z","html_url":"https://github.com/DotNetAnalyzers/StyleCopAnalyzers/pull/670#discussion_r28846003","pull_request_url":"https://api.github.com/repos/DotNetAnalyzers/StyleCopAnalyzers/pulls/670","_links":{"self":{"href":"https://api.github.com/repos/DotNetAnalyzers/StyleCopAnalyzers/pulls/comments/28846003"},"html":{"href":"https://github.com/DotNetAnalyzers/StyleCopAnalyzers/pull/670#discussion_r28846003"},"pull_request":{"href":"https://api.github.com/repos/DotNetAnalyzers/StyleCopAnalyzers/pulls/670"}}},"pull_request":{"url":"https://api.github.com/repos/DotNetAnalyzers/StyleCopAnalyzers/pulls/670","id":33723440,"html_url":"https://github.com/DotNetAnalyzers/StyleCopAnalyzers/pull/670","diff_url":"https://github.com/DotNetAnalyzers/StyleCopAnalyzers/pull/670.diff","patch_url":"https://github.com/DotNetAnalyzers/StyleCopAnalyzers/pull/670.patch","issue_url":"https://api.github.com/repos/DotNetAnalyzers/StyleCopAnalyzers/issues/670","number":670,"state":"open","locked":false,"title":"Skip running StyleCop rules on generated files and elements","user":{"login":"AArnott","id":3548,"avatar_url":"https://avatars.githubusercontent.com/u/3548?v=3","gravatar_id":"","url":"https://api.github.com/users/AArnott","html_url":"https://github.com/AArnott","followers_url":"https://api.github.com/users/AArnott/followers","following_url":"https://api.github.com/users/AArnott/following{/other_user}","gists_url":"https://api.github.com/users/AArnott/gists{/gist_id}","starred_url":"https://api.github.com/users/AArnott/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/AArnott/subscriptions","organizations_url":"https://api.github.com/users/AArnott/orgs","repos_url":"https://api.github.com/users/AArnott/repos","events_url":"https://api.github.com/users/AArnott/events{/privacy}","received_events_url":"https://api.github.com/users/AArnott/received_events","type":"User","site_admin":false},"body":"Fixes #555","created_at":"2015-04-21T02:09:04Z","updated_at":"2015-04-22T05:39:34Z","closed_at":null,"merged_at":null,"merge_commit_sha":"c0d762507462e13dc9a813772f468c7e314bf156","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/DotNetAnalyzers/StyleCopAnalyzers/pulls/670/commits","review_comments_url":"https://api.github.com/repos/DotNetAnalyzers/StyleCopAnalyzers/pulls/670/comments","review_comment_url":"https://api.github.com/repos/DotNetAnalyzers/StyleCopAnalyzers/pulls/comments{/number}","comments_url":"https://api.github.com/repos/DotNetAnalyzers/StyleCopAnalyzers/issues/670/comments","statuses_url":"https://api.github.com/repos/DotNetAnalyzers/StyleCopAnalyzers/statuses/3a2fabf13193547b8c925ee827095e8d4104cc2c","head":{"label":"AArnott:fix555","ref":"fix555","sha":"3a2fabf13193547b8c925ee827095e8d4104cc2c","user":{"login":"AArnott","id":3548,"avatar_url":"https://avatars.githubusercontent.com/u/3548?v=3","gravatar_id":"","url":"https://api.github.com/users/AArnott","html_url":"https://github.com/AArnott","followers_url":"https://api.github.com/users/AArnott/followers","following_url":"https://api.github.com/users/AArnott/following{/other_user}","gists_url":"https://api.github.com/users/AArnott/gists{/gist_id}","starred_url":"https://api.github.com/users/AArnott/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/AArnott/subscriptions","organizations_url":"https://api.github.com/users/AArnott/orgs","repos_url":"https://api.github.com/users/AArnott/repos","events_url":"https://api.github.com/users/AArnott/events{/privacy}","received_events_url":"https://api.github.com/users/AArnott/received_events","type":"User","site_admin":false},"repo":{"id":34295221,"name":"StyleCopAnalyzers","full_name":"AArnott/StyleCopAnalyzers","owner":{"login":"AArnott","id":3548,"avatar_url":"https://avatars.githubusercontent.com/u/3548?v=3","gravatar_id":"","url":"https://api.github.com/users/AArnott","html_url":"https://github.com/AArnott","followers_url":"https://api.github.com/users/AArnott/followers","following_url":"https://api.github.com/users/AArnott/following{/other_user}","gists_url":"https://api.github.com/users/AArnott/gists{/gist_id}","starred_url":"https://api.github.com/users/AArnott/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/AArnott/subscriptions","organizations_url":"https://api.github.com/users/AArnott/orgs","repos_url":"https://api.github.com/users/AArnott/repos","events_url":"https://api.github.com/users/AArnott/events{/privacy}","received_events_url":"https://api.github.com/users/AArnott/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/AArnott/StyleCopAnalyzers","description":"An implementation of StyleCop rules using the .NET Compiler Platform","fork":true,"url":"https://api.github.com/repos/AArnott/StyleCopAnalyzers","forks_url":"https://api.github.com/repos/AArnott/StyleCopAnalyzers/forks","keys_url":"https://api.github.com/repos/AArnott/StyleCopAnalyzers/keys{/key_id}","collaborators_url":"https://api.github.com/repos/AArnott/StyleCopAnalyzers/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/AArnott/StyleCopAnalyzers/teams","hooks_url":"https://api.github.com/repos/AArnott/StyleCopAnalyzers/hooks","issue_events_url":"https://api.github.com/repos/AArnott/StyleCopAnalyzers/issues/events{/number}","events_url":"https://api.github.com/repos/AArnott/StyleCopAnalyzers/events","assignees_url":"https://api.github.com/repos/AArnott/StyleCopAnalyzers/assignees{/user}","branches_url":"https://api.github.com/repos/AArnott/StyleCopAnalyzers/branches{/branch}","tags_url":"https://api.github.com/repos/AArnott/StyleCopAnalyzers/tags","blobs_url":"https://api.github.com/repos/AArnott/StyleCopAnalyzers/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/AArnott/StyleCopAnalyzers/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/AArnott/StyleCopAnalyzers/git/refs{/sha}","trees_url":"https://api.github.com/repos/AArnott/StyleCopAnalyzers/git/trees{/sha}","statuses_url":"https://api.github.com/repos/AArnott/StyleCopAnalyzers/statuses/{sha}","languages_url":"https://api.github.com/repos/AArnott/StyleCopAnalyzers/languages","stargazers_url":"https://api.github.com/repos/AArnott/StyleCopAnalyzers/stargazers","contributors_url":"https://api.github.com/repos/AArnott/StyleCopAnalyzers/contributors","subscribers_url":"https://api.github.com/repos/AArnott/StyleCopAnalyzers/subscribers","subscription_url":"https://api.github.com/repos/AArnott/StyleCopAnalyzers/subscription","commits_url":"https://api.github.com/repos/AArnott/StyleCopAnalyzers/commits{/sha}","git_commits_url":"https://api.github.com/repos/AArnott/StyleCopAnalyzers/git/commits{/sha}","comments_url":"https://api.github.com/repos/AArnott/StyleCopAnalyzers/comments{/number}","issue_comment_url":"https://api.github.com/repos/AArnott/StyleCopAnalyzers/issues/comments{/number}","contents_url":"https://api.github.com/repos/AArnott/StyleCopAnalyzers/contents/{+path}","compare_url":"https://api.github.com/repos/AArnott/StyleCopAnalyzers/compare/{base}...{head}","merges_url":"https://api.github.com/repos/AArnott/StyleCopAnalyzers/merges","archive_url":"https://api.github.com/repos/AArnott/StyleCopAnalyzers/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/AArnott/StyleCopAnalyzers/downloads","issues_url":"https://api.github.com/repos/AArnott/StyleCopAnalyzers/issues{/number}","pulls_url":"https://api.github.com/repos/AArnott/StyleCopAnalyzers/pulls{/number}","milestones_url":"https://api.github.com/repos/AArnott/StyleCopAnalyzers/milestones{/number}","notifications_url":"https://api.github.com/repos/AArnott/StyleCopAnalyzers/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/AArnott/StyleCopAnalyzers/labels{/name}","releases_url":"https://api.github.com/repos/AArnott/StyleCopAnalyzers/releases{/id}","created_at":"2015-04-21T00:53:44Z","updated_at":"2015-04-22T02:15:29Z","pushed_at":"2015-04-22T04:10:09Z","git_url":"git://github.com/AArnott/StyleCopAnalyzers.git","ssh_url":"git@github.com:AArnott/StyleCopAnalyzers.git","clone_url":"https://github.com/AArnott/StyleCopAnalyzers.git","svn_url":"https://github.com/AArnott/StyleCopAnalyzers","homepage":null,"size":5589,"stargazers_count":0,"watchers_count":0,"language":"C#","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"DotNetAnalyzers:master","ref":"master","sha":"a30e6f6adddebe24bd5100029ee551d9e35ff2c9","user":{"login":"DotNetAnalyzers","id":9735576,"avatar_url":"https://avatars.githubusercontent.com/u/9735576?v=3","gravatar_id":"","url":"https://api.github.com/users/DotNetAnalyzers","html_url":"https://github.com/DotNetAnalyzers","followers_url":"https://api.github.com/users/DotNetAnalyzers/followers","following_url":"https://api.github.com/users/DotNetAnalyzers/following{/other_user}","gists_url":"https://api.github.com/users/DotNetAnalyzers/gists{/gist_id}","starred_url":"https://api.github.com/users/DotNetAnalyzers/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/DotNetAnalyzers/subscriptions","organizations_url":"https://api.github.com/users/DotNetAnalyzers/orgs","repos_url":"https://api.github.com/users/DotNetAnalyzers/repos","events_url":"https://api.github.com/users/DotNetAnalyzers/events{/privacy}","received_events_url":"https://api.github.com/users/DotNetAnalyzers/received_events","type":"Organization","site_admin":false},"repo":{"id":26768275,"name":"StyleCopAnalyzers","full_name":"DotNetAnalyzers/StyleCopAnalyzers","owner":{"login":"DotNetAnalyzers","id":9735576,"avatar_url":"https://avatars.githubusercontent.com/u/9735576?v=3","gravatar_id":"","url":"https://api.github.com/users/DotNetAnalyzers","html_url":"https://github.com/DotNetAnalyzers","followers_url":"https://api.github.com/users/DotNetAnalyzers/followers","following_url":"https://api.github.com/users/DotNetAnalyzers/following{/other_user}","gists_url":"https://api.github.com/users/DotNetAnalyzers/gists{/gist_id}","starred_url":"https://api.github.com/users/DotNetAnalyzers/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/DotNetAnalyzers/subscriptions","organizations_url":"https://api.github.com/users/DotNetAnalyzers/orgs","repos_url":"https://api.github.com/users/DotNetAnalyzers/repos","events_url":"https://api.github.com/users/DotNetAnalyzers/events{/privacy}","received_events_url":"https://api.github.com/users/DotNetAnalyzers/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/DotNetAnalyzers/StyleCopAnalyzers","description":"An implementation of StyleCop rules using the .NET Compiler Platform","fork":false,"url":"https://api.github.com/repos/DotNetAnalyzers/StyleCopAnalyzers","forks_url":"https://api.github.com/repos/DotNetAnalyzers/StyleCopAnalyzers/forks","keys_url":"https://api.github.com/repos/DotNetAnalyzers/StyleCopAnalyzers/keys{/key_id}","collaborators_url":"https://api.github.com/repos/DotNetAnalyzers/StyleCopAnalyzers/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/DotNetAnalyzers/StyleCopAnalyzers/teams","hooks_url":"https://api.github.com/repos/DotNetAnalyzers/StyleCopAnalyzers/hooks","issue_events_url":"https://api.github.com/repos/DotNetAnalyzers/StyleCopAnalyzers/issues/events{/number}","events_url":"https://api.github.com/repos/DotNetAnalyzers/StyleCopAnalyzers/events","assignees_url":"https://api.github.com/repos/DotNetAnalyzers/StyleCopAnalyzers/assignees{/user}","branches_url":"https://api.github.com/repos/DotNetAnalyzers/StyleCopAnalyzers/branches{/branch}","tags_url":"https://api.github.com/repos/DotNetAnalyzers/StyleCopAnalyzers/tags","blobs_url":"https://api.github.com/repos/DotNetAnalyzers/StyleCopAnalyzers/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/DotNetAnalyzers/StyleCopAnalyzers/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/DotNetAnalyzers/StyleCopAnalyzers/git/refs{/sha}","trees_url":"https://api.github.com/repos/DotNetAnalyzers/StyleCopAnalyzers/git/trees{/sha}","statuses_url":"https://api.github.com/repos/DotNetAnalyzers/StyleCopAnalyzers/statuses/{sha}","languages_url":"https://api.github.com/repos/DotNetAnalyzers/StyleCopAnalyzers/languages","stargazers_url":"https://api.github.com/repos/DotNetAnalyzers/StyleCopAnalyzers/stargazers","contributors_url":"https://api.github.com/repos/DotNetAnalyzers/StyleCopAnalyzers/contributors","subscribers_url":"https://api.github.com/repos/DotNetAnalyzers/StyleCopAnalyzers/subscribers","subscription_url":"https://api.github.com/repos/DotNetAnalyzers/StyleCopAnalyzers/subscription","commits_url":"https://api.github.com/repos/DotNetAnalyzers/StyleCopAnalyzers/commits{/sha}","git_commits_url":"https://api.github.com/repos/DotNetAnalyzers/StyleCopAnalyzers/git/commits{/sha}","comments_url":"https://api.github.com/repos/DotNetAnalyzers/StyleCopAnalyzers/comments{/number}","issue_comment_url":"https://api.github.com/repos/DotNetAnalyzers/StyleCopAnalyzers/issues/comments{/number}","contents_url":"https://api.github.com/repos/DotNetAnalyzers/StyleCopAnalyzers/contents/{+path}","compare_url":"https://api.github.com/repos/DotNetAnalyzers/StyleCopAnalyzers/compare/{base}...{head}","merges_url":"https://api.github.com/repos/DotNetAnalyzers/StyleCopAnalyzers/merges","archive_url":"https://api.github.com/repos/DotNetAnalyzers/StyleCopAnalyzers/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/DotNetAnalyzers/StyleCopAnalyzers/downloads","issues_url":"https://api.github.com/repos/DotNetAnalyzers/StyleCopAnalyzers/issues{/number}","pulls_url":"https://api.github.com/repos/DotNetAnalyzers/StyleCopAnalyzers/pulls{/number}","milestones_url":"https://api.github.com/repos/DotNetAnalyzers/StyleCopAnalyzers/milestones{/number}","notifications_url":"https://api.github.com/repos/DotNetAnalyzers/StyleCopAnalyzers/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/DotNetAnalyzers/StyleCopAnalyzers/labels{/name}","releases_url":"https://api.github.com/repos/DotNetAnalyzers/StyleCopAnalyzers/releases{/id}","created_at":"2014-11-17T17:29:54Z","updated_at":"2015-04-21T17:29:01Z","pushed_at":"2015-04-22T04:10:09Z","git_url":"git://github.com/DotNetAnalyzers/StyleCopAnalyzers.git","ssh_url":"git@github.com:DotNetAnalyzers/StyleCopAnalyzers.git","clone_url":"https://github.com/DotNetAnalyzers/StyleCopAnalyzers.git","svn_url":"https://github.com/DotNetAnalyzers/StyleCopAnalyzers","homepage":null,"size":5589,"stargazers_count":70,"watchers_count":70,"language":"C#","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":19,"mirror_url":null,"open_issues_count":208,"forks":19,"open_issues":208,"watchers":70,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/DotNetAnalyzers/StyleCopAnalyzers/pulls/670"},"html":{"href":"https://github.com/DotNetAnalyzers/StyleCopAnalyzers/pull/670"},"issue":{"href":"https://api.github.com/repos/DotNetAnalyzers/StyleCopAnalyzers/issues/670"},"comments":{"href":"https://api.github.com/repos/DotNetAnalyzers/StyleCopAnalyzers/issues/670/comments"},"review_comments":{"href":"https://api.github.com/repos/DotNetAnalyzers/StyleCopAnalyzers/pulls/670/comments"},"review_comment":{"href":"https://api.github.com/repos/DotNetAnalyzers/StyleCopAnalyzers/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/DotNetAnalyzers/StyleCopAnalyzers/pulls/670/commits"},"statuses":{"href":"https://api.github.com/repos/DotNetAnalyzers/StyleCopAnalyzers/statuses/3a2fabf13193547b8c925ee827095e8d4104cc2c"}}}}