{"action":"created","comment":{"url":"https://api.github.com/repos/dotnet/codeformatter/pulls/comments/35948175","id":35948175,"diff_hunk":"@@ -0,0 +1,114 @@\n+﻿// Copyright (c) Microsoft. All rights reserved.\n+// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n+\n+using System;\n+using System.Collections.Immutable;\n+using System.Diagnostics;\n+using System.Linq;\n+using System.Threading;\n+using System.Threading.Tasks;\n+\n+using Microsoft.CodeAnalysis;\n+using Microsoft.CodeAnalysis.CodeActions;\n+using Microsoft.CodeAnalysis.CodeFixes;\n+using Microsoft.CodeAnalysis.CSharp.Syntax;\n+using Microsoft.CodeAnalysis.Simplification;\n+using Microsoft.CodeAnalysis.Text;\n+using Microsoft.CodeAnalysis.CSharp;\n+using Microsoft.CodeAnalysis.Editing;\n+\n+namespace Microsoft.DotNet.CodeFormatter.Analyzers\n+{\n+    [ExportCodeFixProvider(LanguageNames.CSharp)]\n+    public class ExplicitVariableTypeFixer : CodeFixProvider\n+    {\n+        public override ImmutableArray<string> FixableDiagnosticIds\n+            => ImmutableArray.Create(ExplicitVariableTypeAnalyzer.DiagnosticId);\n+\n+        public override FixAllProvider GetFixAllProvider()\n+        {\n+            return WellKnownFixAllProviders.BatchFixer;\n+        }\n+\n+        public override async Task RegisterCodeFixesAsync(CodeFixContext context)\n+        {\n+            CancellationToken cancellationToken = context.CancellationToken;\n+            SyntaxNode root = await context.Document.GetSyntaxRootAsync(cancellationToken).ConfigureAwait(false);\n+            SemanticModel model = await context.Document.GetSemanticModelAsync(cancellationToken).ConfigureAwait(false);\n+            Diagnostic diagnostic = context.Diagnostics.First();\n+            TextSpan diagnosticSpan = diagnostic.Location.SourceSpan;\n+\n+            SyntaxNode typeSyntaxNode = null;\n+            ILocalSymbol varSymbol = null;\n+            switch (GetRuleType(diagnostic))\n+            {\n+                case RuleType.RuleVariableDeclaration:\n+                    var variableDeclarationNode = root.\n+                        FindNode(diagnosticSpan).\n+                        FirstAncestorOrSelf<VariableDeclarationSyntax>();\n+                    Debug.Assert(variableDeclarationNode != null);\n+                    typeSyntaxNode = variableDeclarationNode.Type;\n+                    // Implicit typed variables cannot have multiple declartors","path":"src/Microsoft.DotNet.CodeFormatter.Analyzers/ExplicitVariableTypeFixer.cs","position":51,"original_position":51,"commit_id":"fa9d08e0c4a87454e1cbf17b76f1ae4d9a32dec2","original_commit_id":"fa9d08e0c4a87454e1cbf17b76f1ae4d9a32dec2","user":{"login":"genlu","id":788783,"avatar_url":"https://avatars.githubusercontent.com/u/788783?v=3","gravatar_id":"","url":"https://api.github.com/users/genlu","html_url":"https://github.com/genlu","followers_url":"https://api.github.com/users/genlu/followers","following_url":"https://api.github.com/users/genlu/following{/other_user}","gists_url":"https://api.github.com/users/genlu/gists{/gist_id}","starred_url":"https://api.github.com/users/genlu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/genlu/subscriptions","organizations_url":"https://api.github.com/users/genlu/orgs","repos_url":"https://api.github.com/users/genlu/repos","events_url":"https://api.github.com/users/genlu/events{/privacy}","received_events_url":"https://api.github.com/users/genlu/received_events","type":"User","site_admin":false},"body":"Fixed.","created_at":"2015-07-31T05:53:56Z","updated_at":"2015-07-31T05:53:56Z","html_url":"https://github.com/dotnet/codeformatter/pull/155#discussion_r35948175","pull_request_url":"https://api.github.com/repos/dotnet/codeformatter/pulls/155","_links":{"self":{"href":"https://api.github.com/repos/dotnet/codeformatter/pulls/comments/35948175"},"html":{"href":"https://github.com/dotnet/codeformatter/pull/155#discussion_r35948175"},"pull_request":{"href":"https://api.github.com/repos/dotnet/codeformatter/pulls/155"}}},"pull_request":{"url":"https://api.github.com/repos/dotnet/codeformatter/pulls/155","id":41051346,"html_url":"https://github.com/dotnet/codeformatter/pull/155","diff_url":"https://github.com/dotnet/codeformatter/pull/155.diff","patch_url":"https://github.com/dotnet/codeformatter/pull/155.patch","issue_url":"https://api.github.com/repos/dotnet/codeformatter/issues/155","number":155,"state":"open","locked":false,"title":"Add ExplicitVariableTypeAnalyzer and ExplicitVariableTypeFixer","user":{"login":"genlu","id":788783,"avatar_url":"https://avatars.githubusercontent.com/u/788783?v=3","gravatar_id":"","url":"https://api.github.com/users/genlu","html_url":"https://github.com/genlu","followers_url":"https://api.github.com/users/genlu/followers","following_url":"https://api.github.com/users/genlu/following{/other_user}","gists_url":"https://api.github.com/users/genlu/gists{/gist_id}","starred_url":"https://api.github.com/users/genlu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/genlu/subscriptions","organizations_url":"https://api.github.com/users/genlu/orgs","repos_url":"https://api.github.com/users/genlu/repos","events_url":"https://api.github.com/users/genlu/events{/privacy}","received_events_url":"https://api.github.com/users/genlu/received_events","type":"User","site_admin":false},"body":"- `ExplicitVariableTypeAnalyzer` reports a diagnostic when keyword 'var' is used in variable declaration where it could be replaced by an explicit type.\r\n- `ExplicitVariableTypeFixer` replaces the usage of 'var' reported by `ExplicitVariableTypeAnalyzer` with an explicit type.\r\n- `ExplicitVariableTypeAnalyzer `won't fire a warning when it is obvious what the type is (this is what in .NET C# coding style). \r\n    - Here's the complete list of such scenarios (declared type is \"obvious\"):\r\n        - `LiteralExpressionSyntax`: `var foo = 10;`\r\n        - `CastExpressionSyntax`: `var x = (Foo)foo;`\r\n        - `ObjectCreationExpressionSyntax`: `var foo = new Foo();`\r\n        - `ArrayCreationExpressionSyntax`: `var x = new bool[] { true, false };`\r\n        - `BinaryExpressionSyntax` and `Kind` is `SyntaxKind.AsExpression`: `var x = foo as Bar;`\r\n    - Here's an incomplete list of scenarios the analyzer won't fire (declared type is considered non-obvious):\r\n        - `var x = Foo();`\r\n        - `var y = new[] { 1, 2, 3 }; //implicit array creation`\r\n        - `var z = foo;  // foo is another variable`\r\n\r\n@lgolding @jaredpar @Priya91 @michaelcfanning @srivatsn \r\n\r\n","created_at":"2015-07-28T19:38:01Z","updated_at":"2015-07-31T05:53:56Z","closed_at":null,"merged_at":null,"merge_commit_sha":"d6200e4cd34318a879a0bd9c585a2462f0761713","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/dotnet/codeformatter/pulls/155/commits","review_comments_url":"https://api.github.com/repos/dotnet/codeformatter/pulls/155/comments","review_comment_url":"https://api.github.com/repos/dotnet/codeformatter/pulls/comments{/number}","comments_url":"https://api.github.com/repos/dotnet/codeformatter/issues/155/comments","statuses_url":"https://api.github.com/repos/dotnet/codeformatter/statuses/fa9d08e0c4a87454e1cbf17b76f1ae4d9a32dec2","head":{"label":"genlu:anfixAddExplicitVariableTypeAnalyzer","ref":"anfixAddExplicitVariableTypeAnalyzer","sha":"fa9d08e0c4a87454e1cbf17b76f1ae4d9a32dec2","user":{"login":"genlu","id":788783,"avatar_url":"https://avatars.githubusercontent.com/u/788783?v=3","gravatar_id":"","url":"https://api.github.com/users/genlu","html_url":"https://github.com/genlu","followers_url":"https://api.github.com/users/genlu/followers","following_url":"https://api.github.com/users/genlu/following{/other_user}","gists_url":"https://api.github.com/users/genlu/gists{/gist_id}","starred_url":"https://api.github.com/users/genlu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/genlu/subscriptions","organizations_url":"https://api.github.com/users/genlu/orgs","repos_url":"https://api.github.com/users/genlu/repos","events_url":"https://api.github.com/users/genlu/events{/privacy}","received_events_url":"https://api.github.com/users/genlu/received_events","type":"User","site_admin":false},"repo":{"id":39422431,"name":"codeformatter","full_name":"genlu/codeformatter","owner":{"login":"genlu","id":788783,"avatar_url":"https://avatars.githubusercontent.com/u/788783?v=3","gravatar_id":"","url":"https://api.github.com/users/genlu","html_url":"https://github.com/genlu","followers_url":"https://api.github.com/users/genlu/followers","following_url":"https://api.github.com/users/genlu/following{/other_user}","gists_url":"https://api.github.com/users/genlu/gists{/gist_id}","starred_url":"https://api.github.com/users/genlu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/genlu/subscriptions","organizations_url":"https://api.github.com/users/genlu/orgs","repos_url":"https://api.github.com/users/genlu/repos","events_url":"https://api.github.com/users/genlu/events{/privacy}","received_events_url":"https://api.github.com/users/genlu/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/genlu/codeformatter","description":"Tool that uses Roslyn to automatically rewrite the source to follow our coding styles","fork":true,"url":"https://api.github.com/repos/genlu/codeformatter","forks_url":"https://api.github.com/repos/genlu/codeformatter/forks","keys_url":"https://api.github.com/repos/genlu/codeformatter/keys{/key_id}","collaborators_url":"https://api.github.com/repos/genlu/codeformatter/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/genlu/codeformatter/teams","hooks_url":"https://api.github.com/repos/genlu/codeformatter/hooks","issue_events_url":"https://api.github.com/repos/genlu/codeformatter/issues/events{/number}","events_url":"https://api.github.com/repos/genlu/codeformatter/events","assignees_url":"https://api.github.com/repos/genlu/codeformatter/assignees{/user}","branches_url":"https://api.github.com/repos/genlu/codeformatter/branches{/branch}","tags_url":"https://api.github.com/repos/genlu/codeformatter/tags","blobs_url":"https://api.github.com/repos/genlu/codeformatter/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/genlu/codeformatter/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/genlu/codeformatter/git/refs{/sha}","trees_url":"https://api.github.com/repos/genlu/codeformatter/git/trees{/sha}","statuses_url":"https://api.github.com/repos/genlu/codeformatter/statuses/{sha}","languages_url":"https://api.github.com/repos/genlu/codeformatter/languages","stargazers_url":"https://api.github.com/repos/genlu/codeformatter/stargazers","contributors_url":"https://api.github.com/repos/genlu/codeformatter/contributors","subscribers_url":"https://api.github.com/repos/genlu/codeformatter/subscribers","subscription_url":"https://api.github.com/repos/genlu/codeformatter/subscription","commits_url":"https://api.github.com/repos/genlu/codeformatter/commits{/sha}","git_commits_url":"https://api.github.com/repos/genlu/codeformatter/git/commits{/sha}","comments_url":"https://api.github.com/repos/genlu/codeformatter/comments{/number}","issue_comment_url":"https://api.github.com/repos/genlu/codeformatter/issues/comments{/number}","contents_url":"https://api.github.com/repos/genlu/codeformatter/contents/{+path}","compare_url":"https://api.github.com/repos/genlu/codeformatter/compare/{base}...{head}","merges_url":"https://api.github.com/repos/genlu/codeformatter/merges","archive_url":"https://api.github.com/repos/genlu/codeformatter/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/genlu/codeformatter/downloads","issues_url":"https://api.github.com/repos/genlu/codeformatter/issues{/number}","pulls_url":"https://api.github.com/repos/genlu/codeformatter/pulls{/number}","milestones_url":"https://api.github.com/repos/genlu/codeformatter/milestones{/number}","notifications_url":"https://api.github.com/repos/genlu/codeformatter/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/genlu/codeformatter/labels{/name}","releases_url":"https://api.github.com/repos/genlu/codeformatter/releases{/id}","created_at":"2015-07-21T03:42:40Z","updated_at":"2015-07-21T03:42:42Z","pushed_at":"2015-07-30T21:57:55Z","git_url":"git://github.com/genlu/codeformatter.git","ssh_url":"git@github.com:genlu/codeformatter.git","clone_url":"https://github.com/genlu/codeformatter.git","svn_url":"https://github.com/genlu/codeformatter","homepage":"","size":802,"stargazers_count":0,"watchers_count":0,"language":"C#","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"base":{"label":"dotnet:anfix","ref":"anfix","sha":"4d4a721db4adec61b61574c1123ff5c5cc5a878d","user":{"login":"dotnet","id":9141961,"avatar_url":"https://avatars.githubusercontent.com/u/9141961?v=3","gravatar_id":"","url":"https://api.github.com/users/dotnet","html_url":"https://github.com/dotnet","followers_url":"https://api.github.com/users/dotnet/followers","following_url":"https://api.github.com/users/dotnet/following{/other_user}","gists_url":"https://api.github.com/users/dotnet/gists{/gist_id}","starred_url":"https://api.github.com/users/dotnet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dotnet/subscriptions","organizations_url":"https://api.github.com/users/dotnet/orgs","repos_url":"https://api.github.com/users/dotnet/repos","events_url":"https://api.github.com/users/dotnet/events{/privacy}","received_events_url":"https://api.github.com/users/dotnet/received_events","type":"Organization","site_admin":false},"repo":{"id":28896487,"name":"codeformatter","full_name":"dotnet/codeformatter","owner":{"login":"dotnet","id":9141961,"avatar_url":"https://avatars.githubusercontent.com/u/9141961?v=3","gravatar_id":"","url":"https://api.github.com/users/dotnet","html_url":"https://github.com/dotnet","followers_url":"https://api.github.com/users/dotnet/followers","following_url":"https://api.github.com/users/dotnet/following{/other_user}","gists_url":"https://api.github.com/users/dotnet/gists{/gist_id}","starred_url":"https://api.github.com/users/dotnet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dotnet/subscriptions","organizations_url":"https://api.github.com/users/dotnet/orgs","repos_url":"https://api.github.com/users/dotnet/repos","events_url":"https://api.github.com/users/dotnet/events{/privacy}","received_events_url":"https://api.github.com/users/dotnet/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/dotnet/codeformatter","description":"Tool that uses Roslyn to automatically rewrite the source to follow our coding styles","fork":false,"url":"https://api.github.com/repos/dotnet/codeformatter","forks_url":"https://api.github.com/repos/dotnet/codeformatter/forks","keys_url":"https://api.github.com/repos/dotnet/codeformatter/keys{/key_id}","collaborators_url":"https://api.github.com/repos/dotnet/codeformatter/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/dotnet/codeformatter/teams","hooks_url":"https://api.github.com/repos/dotnet/codeformatter/hooks","issue_events_url":"https://api.github.com/repos/dotnet/codeformatter/issues/events{/number}","events_url":"https://api.github.com/repos/dotnet/codeformatter/events","assignees_url":"https://api.github.com/repos/dotnet/codeformatter/assignees{/user}","branches_url":"https://api.github.com/repos/dotnet/codeformatter/branches{/branch}","tags_url":"https://api.github.com/repos/dotnet/codeformatter/tags","blobs_url":"https://api.github.com/repos/dotnet/codeformatter/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/dotnet/codeformatter/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/dotnet/codeformatter/git/refs{/sha}","trees_url":"https://api.github.com/repos/dotnet/codeformatter/git/trees{/sha}","statuses_url":"https://api.github.com/repos/dotnet/codeformatter/statuses/{sha}","languages_url":"https://api.github.com/repos/dotnet/codeformatter/languages","stargazers_url":"https://api.github.com/repos/dotnet/codeformatter/stargazers","contributors_url":"https://api.github.com/repos/dotnet/codeformatter/contributors","subscribers_url":"https://api.github.com/repos/dotnet/codeformatter/subscribers","subscription_url":"https://api.github.com/repos/dotnet/codeformatter/subscription","commits_url":"https://api.github.com/repos/dotnet/codeformatter/commits{/sha}","git_commits_url":"https://api.github.com/repos/dotnet/codeformatter/git/commits{/sha}","comments_url":"https://api.github.com/repos/dotnet/codeformatter/comments{/number}","issue_comment_url":"https://api.github.com/repos/dotnet/codeformatter/issues/comments{/number}","contents_url":"https://api.github.com/repos/dotnet/codeformatter/contents/{+path}","compare_url":"https://api.github.com/repos/dotnet/codeformatter/compare/{base}...{head}","merges_url":"https://api.github.com/repos/dotnet/codeformatter/merges","archive_url":"https://api.github.com/repos/dotnet/codeformatter/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/dotnet/codeformatter/downloads","issues_url":"https://api.github.com/repos/dotnet/codeformatter/issues{/number}","pulls_url":"https://api.github.com/repos/dotnet/codeformatter/pulls{/number}","milestones_url":"https://api.github.com/repos/dotnet/codeformatter/milestones{/number}","notifications_url":"https://api.github.com/repos/dotnet/codeformatter/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/dotnet/codeformatter/labels{/name}","releases_url":"https://api.github.com/repos/dotnet/codeformatter/releases{/id}","created_at":"2015-01-07T03:28:44Z","updated_at":"2015-07-28T14:45:11Z","pushed_at":"2015-07-31T01:16:08Z","git_url":"git://github.com/dotnet/codeformatter.git","ssh_url":"git@github.com:dotnet/codeformatter.git","clone_url":"https://github.com/dotnet/codeformatter.git","svn_url":"https://github.com/dotnet/codeformatter","homepage":"","size":1827,"stargazers_count":425,"watchers_count":425,"language":"C#","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":79,"mirror_url":null,"open_issues_count":54,"forks":79,"open_issues":54,"watchers":425,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/dotnet/codeformatter/pulls/155"},"html":{"href":"https://github.com/dotnet/codeformatter/pull/155"},"issue":{"href":"https://api.github.com/repos/dotnet/codeformatter/issues/155"},"comments":{"href":"https://api.github.com/repos/dotnet/codeformatter/issues/155/comments"},"review_comments":{"href":"https://api.github.com/repos/dotnet/codeformatter/pulls/155/comments"},"review_comment":{"href":"https://api.github.com/repos/dotnet/codeformatter/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/dotnet/codeformatter/pulls/155/commits"},"statuses":{"href":"https://api.github.com/repos/dotnet/codeformatter/statuses/fa9d08e0c4a87454e1cbf17b76f1ae4d9a32dec2"}}}}