{"action":"created","comment":{"url":"https://api.github.com/repos/nzakas/eslint-plugin-typescript/pulls/comments/183799983","pull_request_review_id":114867548,"id":183799983,"diff_hunk":"@@ -0,0 +1,187 @@\n+/**\n+ * @fileoverview Disallows explicit type declarations for inferrable types\n+ * @author James Garbutt <https://github.com/43081j>\n+ */\n+\n+\"use strict\";\n+\n+const util = require(\"../util\");\n+\n+//------------------------------------------------------------------------------\n+// Rule Definition\n+//------------------------------------------------------------------------------\n+\n+module.exports = {\n+    meta: {\n+        docs: {\n+            description:\n+                \"Disallows explicit type declarations for variables or parameters initialized to a number, string, or boolean.\",\n+            extraDescription: [util.tslintRule(\"no-inferrable-types\")],\n+            category: \"TypeScript\",\n+            url:\n+                \"https://github.com/nzakas/eslint-plugin-typescript/blob/master/docs/rules/no-inferrable-types.md\"\n+        },\n+        fixable: \"code\",\n+        schema: [\n+            {\n+                type: \"object\",\n+                properties: {\n+                    ignoreParameters: {\n+                        type: \"boolean\"\n+                    },\n+                    ignoreProperties: {\n+                        type: \"boolean\"\n+                    }\n+                },\n+                additionalProperties: false\n+            }\n+        ]\n+    },\n+\n+    create(context) {\n+        const ignoreParameters = context.options[0]\n+            ? context.options[0].ignoreParameters\n+            : false;\n+        const ignoreProperties = context.options[0]\n+            ? context.options[0].ignoreProperties\n+            : false;\n+\n+        /**\n+         * Returns whether a node has an inferrable value or not\n+         * @param {ASTNode} node the node to check\n+         * @param {ASTNode} init the initializer\n+         * @returns {boolean} whether the node has an inferrable type\n+         */\n+        function isInferrable(node, init) {\n+            if (node.type !== \"TSTypeAnnotation\" || !node.typeAnnotation) {\n+                return false;\n+            }\n+\n+            if (!init) {\n+                return false;\n+            }\n+\n+            const annotation = node.typeAnnotation;\n+\n+            if (annotation.type === \"TSStringKeyword\") {\n+                return (\n+                    (init.type === \"Literal\" &&\n+                        typeof init.value === \"string\") ||\n+                    (init.type === \"TemplateElement\" &&\n+                        (!init.expressions || init.expressions.length === 0))\n+                );\n+            }\n+\n+            if (annotation.type === \"TSBooleanKeyword\") {\n+                return init.type === \"Literal\";\n+            }\n+\n+            if (annotation.type === \"TSNumberKeyword\") {\n+                // Infinity is special\n+                if (\n+                    (init.type === \"UnaryExpression\" &&\n+                        init.operator === \"-\" &&\n+                        init.argument.type === \"Identifier\" &&\n+                        init.argument.name === \"Infinity\") ||\n+                    (init.type === \"Identifier\" && init.name === \"Infinity\")\n+                ) {\n+                    return true;\n+                }\n+\n+                return (\n+                    init.type === \"Literal\" && typeof init.value === \"number\"\n+                );\n+            }\n+\n+            return false;\n+        }\n+\n+        /**\n+         * Reports an inferrable type declaration, if any\n+         * @param {ASTNode} node the node being visited\n+         * @param {ASTNode} typeNode the type annotation node\n+         * @param {ASTNode} initNode the initializer node\n+         * @returns {void}\n+         */\n+        function reportInferrableType(node, typeNode, initNode) {\n+            if (!typeNode || !initNode || !typeNode.typeAnnotation) {\n+                return;\n+            }\n+\n+            if (!isInferrable(typeNode, initNode)) {\n+                return;\n+            }\n+\n+            const typeMap = {\n+                TSBooleanKeyword: \"boolean\",\n+                TSNumberKeyword: \"number\",\n+                TSStringKeyword: \"string\"\n+            };\n+\n+            const type = typeMap[typeNode.typeAnnotation.type];\n+\n+            context.report({\n+                node,\n+                message: `Type ${type} trivially inferred from a ${type} literal, remove type annotation`,\n+                fix: fixer => fixer.remove(typeNode)\n+            });\n+        }\n+\n+        /**\n+         * Visits variables\n+         * @param {ASTNode} node the node to be visited\n+         * @returns {void}\n+         */\n+        function inferrableVariableVisitor(node) {\n+            if (!node.id) {\n+                return;\n+            }\n+            reportInferrableType(node, node.id.typeAnnotation, node.init);\n+        }\n+\n+        /**\n+         * Visits parameters\n+         * @param {ASTNode} node the node to be visited\n+         * @returns {void}\n+         */\n+        function inferrableParameterVisitor(node) {\n+            if (ignoreParameters || !node.params) {\n+                return;\n+            }\n+            node.params\n+                .filter(\n+                    param =>\n+                        param.type === \"AssignmentPattern\" &&\n+                        param.left &&\n+                        param.right\n+                )\n+                .forEach(param => {\n+                    reportInferrableType(\n+                        param,\n+                        param.left.typeAnnotation,\n+                        param.right\n+                    );\n+                });\n+        }\n+\n+        /**\n+         * Visits properties\n+         * @param {ASTNode} node the node to be visited\n+         * @returns {void}\n+         */\n+        function inferrablePropertyVisitor(node) {\n+            if (ignoreProperties || node.readonly) {","path":"lib/rules/no-inferrable-types.js","position":173,"original_position":173,"commit_id":"f9594f9097eb44b704992585db30ace350a0fbd7","original_commit_id":"f9594f9097eb44b704992585db30ace350a0fbd7","user":{"login":"JamesHenry","id":900523,"avatar_url":"https://avatars1.githubusercontent.com/u/900523?v=4","gravatar_id":"","url":"https://api.github.com/users/JamesHenry","html_url":"https://github.com/JamesHenry","followers_url":"https://api.github.com/users/JamesHenry/followers","following_url":"https://api.github.com/users/JamesHenry/following{/other_user}","gists_url":"https://api.github.com/users/JamesHenry/gists{/gist_id}","starred_url":"https://api.github.com/users/JamesHenry/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JamesHenry/subscriptions","organizations_url":"https://api.github.com/users/JamesHenry/orgs","repos_url":"https://api.github.com/users/JamesHenry/repos","events_url":"https://api.github.com/users/JamesHenry/events{/privacy}","received_events_url":"https://api.github.com/users/JamesHenry/received_events","type":"User","site_admin":false},"body":"How come `readonly` is being given special treatment here? It is not mentioned in your docs","created_at":"2018-04-24T16:33:02Z","updated_at":"2018-04-24T16:33:21Z","html_url":"https://github.com/nzakas/eslint-plugin-typescript/pull/124#discussion_r183799983","pull_request_url":"https://api.github.com/repos/nzakas/eslint-plugin-typescript/pulls/124","author_association":"COLLABORATOR","_links":{"self":{"href":"https://api.github.com/repos/nzakas/eslint-plugin-typescript/pulls/comments/183799983"},"html":{"href":"https://github.com/nzakas/eslint-plugin-typescript/pull/124#discussion_r183799983"},"pull_request":{"href":"https://api.github.com/repos/nzakas/eslint-plugin-typescript/pulls/124"}}},"pull_request":{"url":"https://api.github.com/repos/nzakas/eslint-plugin-typescript/pulls/124","id":177582656,"html_url":"https://github.com/nzakas/eslint-plugin-typescript/pull/124","diff_url":"https://github.com/nzakas/eslint-plugin-typescript/pull/124.diff","patch_url":"https://github.com/nzakas/eslint-plugin-typescript/pull/124.patch","issue_url":"https://api.github.com/repos/nzakas/eslint-plugin-typescript/issues/124","number":124,"state":"open","locked":false,"title":"add no-inferrable-types rule","user":{"login":"43081j","id":5677153,"avatar_url":"https://avatars1.githubusercontent.com/u/5677153?v=4","gravatar_id":"","url":"https://api.github.com/users/43081j","html_url":"https://github.com/43081j","followers_url":"https://api.github.com/users/43081j/followers","following_url":"https://api.github.com/users/43081j/following{/other_user}","gists_url":"https://api.github.com/users/43081j/gists{/gist_id}","starred_url":"https://api.github.com/users/43081j/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/43081j/subscriptions","organizations_url":"https://api.github.com/users/43081j/orgs","repos_url":"https://api.github.com/users/43081j/repos","events_url":"https://api.github.com/users/43081j/events{/privacy}","received_events_url":"https://api.github.com/users/43081j/received_events","type":"User","site_admin":false},"body":"Related to #5.\r\n\r\nSeems all fine, but I only discovered this repo today (and eslint's internals) so do let me know if anything's wrong or could be written better.","created_at":"2018-03-26T22:15:16Z","updated_at":"2018-04-24T16:33:21Z","closed_at":null,"merged_at":null,"merge_commit_sha":"a6c9c6d9d79b0c4af0ee54cbd31383f3741a483b","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/nzakas/eslint-plugin-typescript/pulls/124/commits","review_comments_url":"https://api.github.com/repos/nzakas/eslint-plugin-typescript/pulls/124/comments","review_comment_url":"https://api.github.com/repos/nzakas/eslint-plugin-typescript/pulls/comments{/number}","comments_url":"https://api.github.com/repos/nzakas/eslint-plugin-typescript/issues/124/comments","statuses_url":"https://api.github.com/repos/nzakas/eslint-plugin-typescript/statuses/f9594f9097eb44b704992585db30ace350a0fbd7","head":{"label":"43081j:no-inferrable-types","ref":"no-inferrable-types","sha":"f9594f9097eb44b704992585db30ace350a0fbd7","user":{"login":"43081j","id":5677153,"avatar_url":"https://avatars1.githubusercontent.com/u/5677153?v=4","gravatar_id":"","url":"https://api.github.com/users/43081j","html_url":"https://github.com/43081j","followers_url":"https://api.github.com/users/43081j/followers","following_url":"https://api.github.com/users/43081j/following{/other_user}","gists_url":"https://api.github.com/users/43081j/gists{/gist_id}","starred_url":"https://api.github.com/users/43081j/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/43081j/subscriptions","organizations_url":"https://api.github.com/users/43081j/orgs","repos_url":"https://api.github.com/users/43081j/repos","events_url":"https://api.github.com/users/43081j/events{/privacy}","received_events_url":"https://api.github.com/users/43081j/received_events","type":"User","site_admin":false},"repo":{"id":126894149,"name":"eslint-plugin-typescript","full_name":"43081j/eslint-plugin-typescript","owner":{"login":"43081j","id":5677153,"avatar_url":"https://avatars1.githubusercontent.com/u/5677153?v=4","gravatar_id":"","url":"https://api.github.com/users/43081j","html_url":"https://github.com/43081j","followers_url":"https://api.github.com/users/43081j/followers","following_url":"https://api.github.com/users/43081j/following{/other_user}","gists_url":"https://api.github.com/users/43081j/gists{/gist_id}","starred_url":"https://api.github.com/users/43081j/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/43081j/subscriptions","organizations_url":"https://api.github.com/users/43081j/orgs","repos_url":"https://api.github.com/users/43081j/repos","events_url":"https://api.github.com/users/43081j/events{/privacy}","received_events_url":"https://api.github.com/users/43081j/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/43081j/eslint-plugin-typescript","description":"TypeScript plugin for ESLint","fork":true,"url":"https://api.github.com/repos/43081j/eslint-plugin-typescript","forks_url":"https://api.github.com/repos/43081j/eslint-plugin-typescript/forks","keys_url":"https://api.github.com/repos/43081j/eslint-plugin-typescript/keys{/key_id}","collaborators_url":"https://api.github.com/repos/43081j/eslint-plugin-typescript/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/43081j/eslint-plugin-typescript/teams","hooks_url":"https://api.github.com/repos/43081j/eslint-plugin-typescript/hooks","issue_events_url":"https://api.github.com/repos/43081j/eslint-plugin-typescript/issues/events{/number}","events_url":"https://api.github.com/repos/43081j/eslint-plugin-typescript/events","assignees_url":"https://api.github.com/repos/43081j/eslint-plugin-typescript/assignees{/user}","branches_url":"https://api.github.com/repos/43081j/eslint-plugin-typescript/branches{/branch}","tags_url":"https://api.github.com/repos/43081j/eslint-plugin-typescript/tags","blobs_url":"https://api.github.com/repos/43081j/eslint-plugin-typescript/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/43081j/eslint-plugin-typescript/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/43081j/eslint-plugin-typescript/git/refs{/sha}","trees_url":"https://api.github.com/repos/43081j/eslint-plugin-typescript/git/trees{/sha}","statuses_url":"https://api.github.com/repos/43081j/eslint-plugin-typescript/statuses/{sha}","languages_url":"https://api.github.com/repos/43081j/eslint-plugin-typescript/languages","stargazers_url":"https://api.github.com/repos/43081j/eslint-plugin-typescript/stargazers","contributors_url":"https://api.github.com/repos/43081j/eslint-plugin-typescript/contributors","subscribers_url":"https://api.github.com/repos/43081j/eslint-plugin-typescript/subscribers","subscription_url":"https://api.github.com/repos/43081j/eslint-plugin-typescript/subscription","commits_url":"https://api.github.com/repos/43081j/eslint-plugin-typescript/commits{/sha}","git_commits_url":"https://api.github.com/repos/43081j/eslint-plugin-typescript/git/commits{/sha}","comments_url":"https://api.github.com/repos/43081j/eslint-plugin-typescript/comments{/number}","issue_comment_url":"https://api.github.com/repos/43081j/eslint-plugin-typescript/issues/comments{/number}","contents_url":"https://api.github.com/repos/43081j/eslint-plugin-typescript/contents/{+path}","compare_url":"https://api.github.com/repos/43081j/eslint-plugin-typescript/compare/{base}...{head}","merges_url":"https://api.github.com/repos/43081j/eslint-plugin-typescript/merges","archive_url":"https://api.github.com/repos/43081j/eslint-plugin-typescript/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/43081j/eslint-plugin-typescript/downloads","issues_url":"https://api.github.com/repos/43081j/eslint-plugin-typescript/issues{/number}","pulls_url":"https://api.github.com/repos/43081j/eslint-plugin-typescript/pulls{/number}","milestones_url":"https://api.github.com/repos/43081j/eslint-plugin-typescript/milestones{/number}","notifications_url":"https://api.github.com/repos/43081j/eslint-plugin-typescript/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/43081j/eslint-plugin-typescript/labels{/name}","releases_url":"https://api.github.com/repos/43081j/eslint-plugin-typescript/releases{/id}","deployments_url":"https://api.github.com/repos/43081j/eslint-plugin-typescript/deployments","created_at":"2018-03-26T21:49:06Z","updated_at":"2018-03-26T21:49:08Z","pushed_at":"2018-04-02T09:58:23Z","git_url":"git://github.com/43081j/eslint-plugin-typescript.git","ssh_url":"git@github.com:43081j/eslint-plugin-typescript.git","clone_url":"https://github.com/43081j/eslint-plugin-typescript.git","svn_url":"https://github.com/43081j/eslint-plugin-typescript","homepage":null,"size":201,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":0,"license":{"key":"mit","name":"MIT License","spdx_id":"MIT","url":"https://api.github.com/licenses/mit"},"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"nzakas:master","ref":"master","sha":"4409013ed953bd6d868bec7447fbe72fddae2258","user":{"login":"nzakas","id":38546,"avatar_url":"https://avatars3.githubusercontent.com/u/38546?v=4","gravatar_id":"","url":"https://api.github.com/users/nzakas","html_url":"https://github.com/nzakas","followers_url":"https://api.github.com/users/nzakas/followers","following_url":"https://api.github.com/users/nzakas/following{/other_user}","gists_url":"https://api.github.com/users/nzakas/gists{/gist_id}","starred_url":"https://api.github.com/users/nzakas/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nzakas/subscriptions","organizations_url":"https://api.github.com/users/nzakas/orgs","repos_url":"https://api.github.com/users/nzakas/repos","events_url":"https://api.github.com/users/nzakas/events{/privacy}","received_events_url":"https://api.github.com/users/nzakas/received_events","type":"User","site_admin":false},"repo":{"id":66300346,"name":"eslint-plugin-typescript","full_name":"nzakas/eslint-plugin-typescript","owner":{"login":"nzakas","id":38546,"avatar_url":"https://avatars3.githubusercontent.com/u/38546?v=4","gravatar_id":"","url":"https://api.github.com/users/nzakas","html_url":"https://github.com/nzakas","followers_url":"https://api.github.com/users/nzakas/followers","following_url":"https://api.github.com/users/nzakas/following{/other_user}","gists_url":"https://api.github.com/users/nzakas/gists{/gist_id}","starred_url":"https://api.github.com/users/nzakas/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nzakas/subscriptions","organizations_url":"https://api.github.com/users/nzakas/orgs","repos_url":"https://api.github.com/users/nzakas/repos","events_url":"https://api.github.com/users/nzakas/events{/privacy}","received_events_url":"https://api.github.com/users/nzakas/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/nzakas/eslint-plugin-typescript","description":"TypeScript plugin for ESLint","fork":false,"url":"https://api.github.com/repos/nzakas/eslint-plugin-typescript","forks_url":"https://api.github.com/repos/nzakas/eslint-plugin-typescript/forks","keys_url":"https://api.github.com/repos/nzakas/eslint-plugin-typescript/keys{/key_id}","collaborators_url":"https://api.github.com/repos/nzakas/eslint-plugin-typescript/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/nzakas/eslint-plugin-typescript/teams","hooks_url":"https://api.github.com/repos/nzakas/eslint-plugin-typescript/hooks","issue_events_url":"https://api.github.com/repos/nzakas/eslint-plugin-typescript/issues/events{/number}","events_url":"https://api.github.com/repos/nzakas/eslint-plugin-typescript/events","assignees_url":"https://api.github.com/repos/nzakas/eslint-plugin-typescript/assignees{/user}","branches_url":"https://api.github.com/repos/nzakas/eslint-plugin-typescript/branches{/branch}","tags_url":"https://api.github.com/repos/nzakas/eslint-plugin-typescript/tags","blobs_url":"https://api.github.com/repos/nzakas/eslint-plugin-typescript/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/nzakas/eslint-plugin-typescript/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/nzakas/eslint-plugin-typescript/git/refs{/sha}","trees_url":"https://api.github.com/repos/nzakas/eslint-plugin-typescript/git/trees{/sha}","statuses_url":"https://api.github.com/repos/nzakas/eslint-plugin-typescript/statuses/{sha}","languages_url":"https://api.github.com/repos/nzakas/eslint-plugin-typescript/languages","stargazers_url":"https://api.github.com/repos/nzakas/eslint-plugin-typescript/stargazers","contributors_url":"https://api.github.com/repos/nzakas/eslint-plugin-typescript/contributors","subscribers_url":"https://api.github.com/repos/nzakas/eslint-plugin-typescript/subscribers","subscription_url":"https://api.github.com/repos/nzakas/eslint-plugin-typescript/subscription","commits_url":"https://api.github.com/repos/nzakas/eslint-plugin-typescript/commits{/sha}","git_commits_url":"https://api.github.com/repos/nzakas/eslint-plugin-typescript/git/commits{/sha}","comments_url":"https://api.github.com/repos/nzakas/eslint-plugin-typescript/comments{/number}","issue_comment_url":"https://api.github.com/repos/nzakas/eslint-plugin-typescript/issues/comments{/number}","contents_url":"https://api.github.com/repos/nzakas/eslint-plugin-typescript/contents/{+path}","compare_url":"https://api.github.com/repos/nzakas/eslint-plugin-typescript/compare/{base}...{head}","merges_url":"https://api.github.com/repos/nzakas/eslint-plugin-typescript/merges","archive_url":"https://api.github.com/repos/nzakas/eslint-plugin-typescript/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/nzakas/eslint-plugin-typescript/downloads","issues_url":"https://api.github.com/repos/nzakas/eslint-plugin-typescript/issues{/number}","pulls_url":"https://api.github.com/repos/nzakas/eslint-plugin-typescript/pulls{/number}","milestones_url":"https://api.github.com/repos/nzakas/eslint-plugin-typescript/milestones{/number}","notifications_url":"https://api.github.com/repos/nzakas/eslint-plugin-typescript/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/nzakas/eslint-plugin-typescript/labels{/name}","releases_url":"https://api.github.com/repos/nzakas/eslint-plugin-typescript/releases{/id}","deployments_url":"https://api.github.com/repos/nzakas/eslint-plugin-typescript/deployments","created_at":"2016-08-22T19:05:14Z","updated_at":"2018-04-21T12:42:02Z","pushed_at":"2018-04-02T09:58:24Z","git_url":"git://github.com/nzakas/eslint-plugin-typescript.git","ssh_url":"git@github.com:nzakas/eslint-plugin-typescript.git","clone_url":"https://github.com/nzakas/eslint-plugin-typescript.git","svn_url":"https://github.com/nzakas/eslint-plugin-typescript","homepage":null,"size":192,"stargazers_count":126,"watchers_count":126,"language":"JavaScript","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":26,"mirror_url":null,"archived":false,"open_issues_count":24,"license":{"key":"other","name":"Other","spdx_id":null,"url":null},"forks":26,"open_issues":24,"watchers":126,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/nzakas/eslint-plugin-typescript/pulls/124"},"html":{"href":"https://github.com/nzakas/eslint-plugin-typescript/pull/124"},"issue":{"href":"https://api.github.com/repos/nzakas/eslint-plugin-typescript/issues/124"},"comments":{"href":"https://api.github.com/repos/nzakas/eslint-plugin-typescript/issues/124/comments"},"review_comments":{"href":"https://api.github.com/repos/nzakas/eslint-plugin-typescript/pulls/124/comments"},"review_comment":{"href":"https://api.github.com/repos/nzakas/eslint-plugin-typescript/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/nzakas/eslint-plugin-typescript/pulls/124/commits"},"statuses":{"href":"https://api.github.com/repos/nzakas/eslint-plugin-typescript/statuses/f9594f9097eb44b704992585db30ace350a0fbd7"}},"author_association":"NONE"}}
{"actor":{"display_login":"JamesHenry"}}