{"action":"created","comment":{"url":"https://api.github.com/repos/palantir/tslint/pulls/comments/37561401","id":37561401,"diff_hunk":"@@ -0,0 +1,78 @@\n+/*\n+ * Copyright 2015 Palantir Technologies, Inc.\n+ *\n+ * Licensed under the Apache License, Version 2.0 (the \"License\");\n+ * you may not use this file except in compliance with the License.\n+ * You may obtain a copy of the License at\n+ *\n+ *     http://www.apache.org/licenses/LICENSE-2.0\n+ *\n+ * Unless required by applicable law or agreed to in writing, software\n+ * distributed under the License is distributed on an \"AS IS\" BASIS,\n+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n+ * See the License for the specific language governing permissions and\n+ * limitations under the License.\n+ */\n+\n+export class Rule extends Lint.Rules.AbstractRule {\n+    public static FAILURE_STRING = \"assignment in conditional: \";\n+\n+    public apply(sourceFile: ts.SourceFile): Lint.RuleFailure[] {\n+        const walker = new NoConditionalAssignmentWalker(sourceFile, this.getOptions());\n+        return this.applyWithWalker(walker);\n+    }\n+}\n+\n+class NoConditionalAssignmentWalker extends Lint.RuleWalker {\n+    private inConditionalExpression = false;\n+\n+    protected visitIfStatement(node: ts.IfStatement) {\n+        this.checkExpressionForBinaryExpressions(node.expression);\n+        super.visitIfStatement(node);\n+    }\n+\n+    protected visitWhileStatement(node: ts.WhileStatement) {\n+        this.checkExpressionForBinaryExpressions(node.expression);\n+        super.visitWhileStatement(node);\n+    }\n+\n+    protected visitDoStatement(node: ts.DoStatement) {\n+        this.checkExpressionForBinaryExpressions(node.expression);\n+        super.visitWhileStatement(node);\n+    }\n+\n+    protected visitForStatement(node: ts.ForStatement) {\n+        if (node.condition) {\n+            this.checkExpressionForBinaryExpressions(node.condition);\n+        }\n+\n+        super.visitForStatement(node);\n+    }\n+\n+    protected visitBinaryExpression(expression: ts.BinaryExpression) {\n+        if (this.inConditionalExpression) {\n+            this.checkBinaryExpressionForAssignment(expression);\n+        }\n+        super.visitBinaryExpression(expression);\n+    }\n+\n+    private checkExpressionForBinaryExpressions(expression: ts.Expression) {\n+        this.inConditionalExpression = true;\n+        if (expression.kind === ts.SyntaxKind.BinaryExpression) {\n+            this.checkBinaryExpressionForAssignment(<ts.BinaryExpression> expression);\n+        }\n+        this.walkChildren(expression);\n+        this.inConditionalExpression = false;\n+    }\n+\n+    private checkBinaryExpressionForAssignment(expression: ts.BinaryExpression) {\n+        if (this.isAssignmentToken(expression.operatorToken.kind)) {\n+            this.addFailure(this.createFailure(expression.getStart(), expression.getWidth(), Rule.FAILURE_STRING));\n+        }\n+    }\n+\n+    private isAssignmentToken(token: ts.SyntaxKind): boolean {","path":"src/rules/noConditionalAssignmentRule.ts","position":74,"original_position":74,"commit_id":"21799936f53785ffe384be43ed03a6ec7bc83779","original_commit_id":"21799936f53785ffe384be43ed03a6ec7bc83779","user":{"login":"adidahiya","id":723999,"avatar_url":"https://avatars.githubusercontent.com/u/723999?v=3","gravatar_id":"","url":"https://api.github.com/users/adidahiya","html_url":"https://github.com/adidahiya","followers_url":"https://api.github.com/users/adidahiya/followers","following_url":"https://api.github.com/users/adidahiya/following{/other_user}","gists_url":"https://api.github.com/users/adidahiya/gists{/gist_id}","starred_url":"https://api.github.com/users/adidahiya/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/adidahiya/subscriptions","organizations_url":"https://api.github.com/users/adidahiya/orgs","repos_url":"https://api.github.com/users/adidahiya/repos","events_url":"https://api.github.com/users/adidahiya/events{/privacy}","received_events_url":"https://api.github.com/users/adidahiya/received_events","type":"User","site_admin":false},"body":"alternatively, this could be slightly better:\r\n\r\nkeep the arg as `token` and actually take in a token node instead of a `SyntaxKind`. then the body of this function would reference `token.kind`","created_at":"2015-08-20T18:06:15Z","updated_at":"2015-08-20T18:06:15Z","html_url":"https://github.com/palantir/tslint/pull/586#discussion_r37561401","pull_request_url":"https://api.github.com/repos/palantir/tslint/pulls/586","_links":{"self":{"href":"https://api.github.com/repos/palantir/tslint/pulls/comments/37561401"},"html":{"href":"https://github.com/palantir/tslint/pull/586#discussion_r37561401"},"pull_request":{"href":"https://api.github.com/repos/palantir/tslint/pulls/586"}}},"pull_request":{"url":"https://api.github.com/repos/palantir/tslint/pulls/586","id":42872221,"html_url":"https://github.com/palantir/tslint/pull/586","diff_url":"https://github.com/palantir/tslint/pull/586.diff","patch_url":"https://github.com/palantir/tslint/pull/586.patch","issue_url":"https://api.github.com/repos/palantir/tslint/issues/586","number":586,"state":"open","locked":false,"title":"Add no-conditional-assignment rule","user":{"login":"JKillian","id":1400151,"avatar_url":"https://avatars.githubusercontent.com/u/1400151?v=3","gravatar_id":"","url":"https://api.github.com/users/JKillian","html_url":"https://github.com/JKillian","followers_url":"https://api.github.com/users/JKillian/followers","following_url":"https://api.github.com/users/JKillian/following{/other_user}","gists_url":"https://api.github.com/users/JKillian/gists{/gist_id}","starred_url":"https://api.github.com/users/JKillian/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JKillian/subscriptions","organizations_url":"https://api.github.com/users/JKillian/orgs","repos_url":"https://api.github.com/users/JKillian/repos","events_url":"https://api.github.com/users/JKillian/events{/privacy}","received_events_url":"https://api.github.com/users/JKillian/received_events","type":"User","site_admin":false},"body":"Implements feature request #507 ","created_at":"2015-08-19T22:31:15Z","updated_at":"2015-08-20T18:06:15Z","closed_at":null,"merged_at":null,"merge_commit_sha":"33f6ac6c87e8e94e9bf86e83d42c3c4b6320aa0a","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/palantir/tslint/pulls/586/commits","review_comments_url":"https://api.github.com/repos/palantir/tslint/pulls/586/comments","review_comment_url":"https://api.github.com/repos/palantir/tslint/pulls/comments{/number}","comments_url":"https://api.github.com/repos/palantir/tslint/issues/586/comments","statuses_url":"https://api.github.com/repos/palantir/tslint/statuses/21799936f53785ffe384be43ed03a6ec7bc83779","head":{"label":"palantir:noConditionalAssignment","ref":"noConditionalAssignment","sha":"21799936f53785ffe384be43ed03a6ec7bc83779","user":{"login":"palantir","id":303157,"avatar_url":"https://avatars.githubusercontent.com/u/303157?v=3","gravatar_id":"","url":"https://api.github.com/users/palantir","html_url":"https://github.com/palantir","followers_url":"https://api.github.com/users/palantir/followers","following_url":"https://api.github.com/users/palantir/following{/other_user}","gists_url":"https://api.github.com/users/palantir/gists{/gist_id}","starred_url":"https://api.github.com/users/palantir/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/palantir/subscriptions","organizations_url":"https://api.github.com/users/palantir/orgs","repos_url":"https://api.github.com/users/palantir/repos","events_url":"https://api.github.com/users/palantir/events{/privacy}","received_events_url":"https://api.github.com/users/palantir/received_events","type":"Organization","site_admin":false},"repo":{"id":11672345,"name":"tslint","full_name":"palantir/tslint","owner":{"login":"palantir","id":303157,"avatar_url":"https://avatars.githubusercontent.com/u/303157?v=3","gravatar_id":"","url":"https://api.github.com/users/palantir","html_url":"https://github.com/palantir","followers_url":"https://api.github.com/users/palantir/followers","following_url":"https://api.github.com/users/palantir/following{/other_user}","gists_url":"https://api.github.com/users/palantir/gists{/gist_id}","starred_url":"https://api.github.com/users/palantir/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/palantir/subscriptions","organizations_url":"https://api.github.com/users/palantir/orgs","repos_url":"https://api.github.com/users/palantir/repos","events_url":"https://api.github.com/users/palantir/events{/privacy}","received_events_url":"https://api.github.com/users/palantir/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/palantir/tslint","description":"A linter for the TypeScript language.","fork":false,"url":"https://api.github.com/repos/palantir/tslint","forks_url":"https://api.github.com/repos/palantir/tslint/forks","keys_url":"https://api.github.com/repos/palantir/tslint/keys{/key_id}","collaborators_url":"https://api.github.com/repos/palantir/tslint/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/palantir/tslint/teams","hooks_url":"https://api.github.com/repos/palantir/tslint/hooks","issue_events_url":"https://api.github.com/repos/palantir/tslint/issues/events{/number}","events_url":"https://api.github.com/repos/palantir/tslint/events","assignees_url":"https://api.github.com/repos/palantir/tslint/assignees{/user}","branches_url":"https://api.github.com/repos/palantir/tslint/branches{/branch}","tags_url":"https://api.github.com/repos/palantir/tslint/tags","blobs_url":"https://api.github.com/repos/palantir/tslint/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/palantir/tslint/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/palantir/tslint/git/refs{/sha}","trees_url":"https://api.github.com/repos/palantir/tslint/git/trees{/sha}","statuses_url":"https://api.github.com/repos/palantir/tslint/statuses/{sha}","languages_url":"https://api.github.com/repos/palantir/tslint/languages","stargazers_url":"https://api.github.com/repos/palantir/tslint/stargazers","contributors_url":"https://api.github.com/repos/palantir/tslint/contributors","subscribers_url":"https://api.github.com/repos/palantir/tslint/subscribers","subscription_url":"https://api.github.com/repos/palantir/tslint/subscription","commits_url":"https://api.github.com/repos/palantir/tslint/commits{/sha}","git_commits_url":"https://api.github.com/repos/palantir/tslint/git/commits{/sha}","comments_url":"https://api.github.com/repos/palantir/tslint/comments{/number}","issue_comment_url":"https://api.github.com/repos/palantir/tslint/issues/comments{/number}","contents_url":"https://api.github.com/repos/palantir/tslint/contents/{+path}","compare_url":"https://api.github.com/repos/palantir/tslint/compare/{base}...{head}","merges_url":"https://api.github.com/repos/palantir/tslint/merges","archive_url":"https://api.github.com/repos/palantir/tslint/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/palantir/tslint/downloads","issues_url":"https://api.github.com/repos/palantir/tslint/issues{/number}","pulls_url":"https://api.github.com/repos/palantir/tslint/pulls{/number}","milestones_url":"https://api.github.com/repos/palantir/tslint/milestones{/number}","notifications_url":"https://api.github.com/repos/palantir/tslint/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/palantir/tslint/labels{/name}","releases_url":"https://api.github.com/repos/palantir/tslint/releases{/id}","created_at":"2013-07-25T22:19:18Z","updated_at":"2015-08-20T04:09:30Z","pushed_at":"2015-08-20T16:07:54Z","git_url":"git://github.com/palantir/tslint.git","ssh_url":"git@github.com:palantir/tslint.git","clone_url":"https://github.com/palantir/tslint.git","svn_url":"https://github.com/palantir/tslint","homepage":null,"size":12473,"stargazers_count":325,"watchers_count":325,"language":"TypeScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":85,"mirror_url":null,"open_issues_count":95,"forks":85,"open_issues":95,"watchers":325,"default_branch":"master"}},"base":{"label":"palantir:master","ref":"master","sha":"dda71f30520e016556f9ff91d13e6bd74565160f","user":{"login":"palantir","id":303157,"avatar_url":"https://avatars.githubusercontent.com/u/303157?v=3","gravatar_id":"","url":"https://api.github.com/users/palantir","html_url":"https://github.com/palantir","followers_url":"https://api.github.com/users/palantir/followers","following_url":"https://api.github.com/users/palantir/following{/other_user}","gists_url":"https://api.github.com/users/palantir/gists{/gist_id}","starred_url":"https://api.github.com/users/palantir/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/palantir/subscriptions","organizations_url":"https://api.github.com/users/palantir/orgs","repos_url":"https://api.github.com/users/palantir/repos","events_url":"https://api.github.com/users/palantir/events{/privacy}","received_events_url":"https://api.github.com/users/palantir/received_events","type":"Organization","site_admin":false},"repo":{"id":11672345,"name":"tslint","full_name":"palantir/tslint","owner":{"login":"palantir","id":303157,"avatar_url":"https://avatars.githubusercontent.com/u/303157?v=3","gravatar_id":"","url":"https://api.github.com/users/palantir","html_url":"https://github.com/palantir","followers_url":"https://api.github.com/users/palantir/followers","following_url":"https://api.github.com/users/palantir/following{/other_user}","gists_url":"https://api.github.com/users/palantir/gists{/gist_id}","starred_url":"https://api.github.com/users/palantir/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/palantir/subscriptions","organizations_url":"https://api.github.com/users/palantir/orgs","repos_url":"https://api.github.com/users/palantir/repos","events_url":"https://api.github.com/users/palantir/events{/privacy}","received_events_url":"https://api.github.com/users/palantir/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/palantir/tslint","description":"A linter for the TypeScript language.","fork":false,"url":"https://api.github.com/repos/palantir/tslint","forks_url":"https://api.github.com/repos/palantir/tslint/forks","keys_url":"https://api.github.com/repos/palantir/tslint/keys{/key_id}","collaborators_url":"https://api.github.com/repos/palantir/tslint/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/palantir/tslint/teams","hooks_url":"https://api.github.com/repos/palantir/tslint/hooks","issue_events_url":"https://api.github.com/repos/palantir/tslint/issues/events{/number}","events_url":"https://api.github.com/repos/palantir/tslint/events","assignees_url":"https://api.github.com/repos/palantir/tslint/assignees{/user}","branches_url":"https://api.github.com/repos/palantir/tslint/branches{/branch}","tags_url":"https://api.github.com/repos/palantir/tslint/tags","blobs_url":"https://api.github.com/repos/palantir/tslint/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/palantir/tslint/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/palantir/tslint/git/refs{/sha}","trees_url":"https://api.github.com/repos/palantir/tslint/git/trees{/sha}","statuses_url":"https://api.github.com/repos/palantir/tslint/statuses/{sha}","languages_url":"https://api.github.com/repos/palantir/tslint/languages","stargazers_url":"https://api.github.com/repos/palantir/tslint/stargazers","contributors_url":"https://api.github.com/repos/palantir/tslint/contributors","subscribers_url":"https://api.github.com/repos/palantir/tslint/subscribers","subscription_url":"https://api.github.com/repos/palantir/tslint/subscription","commits_url":"https://api.github.com/repos/palantir/tslint/commits{/sha}","git_commits_url":"https://api.github.com/repos/palantir/tslint/git/commits{/sha}","comments_url":"https://api.github.com/repos/palantir/tslint/comments{/number}","issue_comment_url":"https://api.github.com/repos/palantir/tslint/issues/comments{/number}","contents_url":"https://api.github.com/repos/palantir/tslint/contents/{+path}","compare_url":"https://api.github.com/repos/palantir/tslint/compare/{base}...{head}","merges_url":"https://api.github.com/repos/palantir/tslint/merges","archive_url":"https://api.github.com/repos/palantir/tslint/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/palantir/tslint/downloads","issues_url":"https://api.github.com/repos/palantir/tslint/issues{/number}","pulls_url":"https://api.github.com/repos/palantir/tslint/pulls{/number}","milestones_url":"https://api.github.com/repos/palantir/tslint/milestones{/number}","notifications_url":"https://api.github.com/repos/palantir/tslint/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/palantir/tslint/labels{/name}","releases_url":"https://api.github.com/repos/palantir/tslint/releases{/id}","created_at":"2013-07-25T22:19:18Z","updated_at":"2015-08-20T04:09:30Z","pushed_at":"2015-08-20T16:07:54Z","git_url":"git://github.com/palantir/tslint.git","ssh_url":"git@github.com:palantir/tslint.git","clone_url":"https://github.com/palantir/tslint.git","svn_url":"https://github.com/palantir/tslint","homepage":null,"size":12473,"stargazers_count":325,"watchers_count":325,"language":"TypeScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":85,"mirror_url":null,"open_issues_count":95,"forks":85,"open_issues":95,"watchers":325,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/palantir/tslint/pulls/586"},"html":{"href":"https://github.com/palantir/tslint/pull/586"},"issue":{"href":"https://api.github.com/repos/palantir/tslint/issues/586"},"comments":{"href":"https://api.github.com/repos/palantir/tslint/issues/586/comments"},"review_comments":{"href":"https://api.github.com/repos/palantir/tslint/pulls/586/comments"},"review_comment":{"href":"https://api.github.com/repos/palantir/tslint/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/palantir/tslint/pulls/586/commits"},"statuses":{"href":"https://api.github.com/repos/palantir/tslint/statuses/21799936f53785ffe384be43ed03a6ec7bc83779"}}}}