{"action":"created","comment":{"url":"https://api.github.com/repos/SonarSource/sonar-javascript/pulls/comments/48001867","id":48001867,"diff_hunk":"@@ -0,0 +1,195 @@\n+/*\n+ * SonarQube JavaScript Plugin\n+ * Copyright (C) 2011 SonarSource and Eriks Nukis\n+ * sonarqube@googlegroups.com\n+ *\n+ * This program is free software; you can redistribute it and/or\n+ * modify it under the terms of the GNU Lesser General Public\n+ * License as published by the Free Software Foundation; either\n+ * version 3 of the License, or (at your option) any later version.\n+ *\n+ * This program is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n+ * Lesser General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU Lesser General Public\n+ * License along with this program; if not, write to the Free Software\n+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02\n+ */\n+package org.sonar.javascript.checks;\n+\n+import java.util.ArrayDeque;\n+import java.util.Collections;\n+import java.util.Deque;\n+import java.util.HashSet;\n+import java.util.Iterator;\n+import java.util.Set;\n+import org.sonar.api.server.rule.RulesDefinition.SubCharacteristics;\n+import org.sonar.check.Priority;\n+import org.sonar.check.Rule;\n+import org.sonar.javascript.tree.impl.statement.VariableDeclarationTreeImpl;\n+import org.sonar.plugins.javascript.api.symbols.Symbol;\n+import org.sonar.plugins.javascript.api.symbols.Usage;\n+import org.sonar.plugins.javascript.api.tree.Tree;\n+import org.sonar.plugins.javascript.api.tree.Tree.Kind;\n+import org.sonar.plugins.javascript.api.tree.expression.AssignmentExpressionTree;\n+import org.sonar.plugins.javascript.api.tree.expression.ExpressionTree;\n+import org.sonar.plugins.javascript.api.tree.expression.IdentifierTree;\n+import org.sonar.plugins.javascript.api.tree.expression.UnaryExpressionTree;\n+import org.sonar.plugins.javascript.api.tree.statement.ForInStatementTree;\n+import org.sonar.plugins.javascript.api.tree.statement.ForOfStatementTree;\n+import org.sonar.plugins.javascript.api.tree.statement.ForStatementTree;\n+import org.sonar.plugins.javascript.api.tree.statement.IterationStatementTree;\n+import org.sonar.plugins.javascript.api.tree.statement.VariableDeclarationTree;\n+import org.sonar.plugins.javascript.api.visitors.BaseTreeVisitor;\n+import org.sonar.plugins.javascript.api.visitors.IssueLocation;\n+import org.sonar.squidbridge.annotations.ActivatedByDefault;\n+import org.sonar.squidbridge.annotations.SqaleConstantRemediation;\n+import org.sonar.squidbridge.annotations.SqaleSubCharacteristic;\n+\n+@Rule(\n+  key = \"S2310\",\n+  name = \"Loop counters should not be assigned to from within the loop body\",\n+  priority = Priority.MAJOR,\n+  tags = Tags.PITFALL)\n+@ActivatedByDefault\n+@SqaleSubCharacteristic(SubCharacteristics.LOGIC_RELIABILITY)\n+@SqaleConstantRemediation(\"5min\")\n+public class CounterUpdatedInLoopCheck extends BaseTreeVisitor {\n+\n+  private static final String MESSAGE = \"Remove this assignment of \\\"%s\\\".\";\n+\n+  private Deque<Set<IdentifierTree>> writeUsagesOfCounters = new ArrayDeque<>();\n+\n+  private Set<Symbol> currentLoopCounters = null;\n+  private boolean inUpdate = false;\n+\n+  private static final Kind[] INC_DEC_OPERATIONS = {\n+    Kind.PREFIX_DECREMENT,\n+    Kind.PREFIX_INCREMENT,\n+    Kind.POSTFIX_DECREMENT,\n+    Kind.POSTFIX_INCREMENT\n+  };\n+\n+  @Override\n+  public void visitForStatement(ForStatementTree tree) {\n+    scan(tree.init());\n+    scan(tree.condition());\n+\n+    currentLoopCounters = new HashSet<>();\n+    inUpdate = true;\n+    scan(tree.update());\n+    inUpdate = false;\n+\n+    enterLoopBody(currentLoopCounters);\n+    scan(tree.statement());\n+    leaveLoopBody();\n+  }\n+\n+  @Override\n+  public void visitForInStatement(ForInStatementTree tree) {\n+    scan(tree.variableOrExpression());\n+    scan(tree.expression());\n+    visitObjectIterationStatement(tree, tree.variableOrExpression());\n+  }\n+\n+  @Override\n+  public void visitForOfStatement(ForOfStatementTree tree) {\n+    scan(tree.variableOrExpression());\n+    scan(tree.expression());\n+    visitObjectIterationStatement(tree, tree.variableOrExpression());\n+  }\n+\n+  @Override\n+  public void visitIdentifier(IdentifierTree tree) {\n+    Iterator<Set<IdentifierTree>> iterator = writeUsagesOfCounters.descendingIterator();","path":"javascript-checks/src/main/java/org/sonar/javascript/checks/CounterUpdatedInLoopCheck.java","position":null,"original_position":106,"commit_id":"b82aa62d5af53b6a76c53f12886bac1d810d9ceb","original_commit_id":"4fb9a0cb40a17d1467e7e42967dd0d47e5b1f863","user":{"login":"vilchik-elena","id":10108186,"avatar_url":"https://avatars.githubusercontent.com/u/10108186?v=3","gravatar_id":"","url":"https://api.github.com/users/vilchik-elena","html_url":"https://github.com/vilchik-elena","followers_url":"https://api.github.com/users/vilchik-elena/followers","following_url":"https://api.github.com/users/vilchik-elena/following{/other_user}","gists_url":"https://api.github.com/users/vilchik-elena/gists{/gist_id}","starred_url":"https://api.github.com/users/vilchik-elena/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vilchik-elena/subscriptions","organizations_url":"https://api.github.com/users/vilchik-elena/orgs","repos_url":"https://api.github.com/users/vilchik-elena/repos","events_url":"https://api.github.com/users/vilchik-elena/events{/privacy}","received_events_url":"https://api.github.com/users/vilchik-elena/received_events","type":"User","site_admin":false},"body":"@pynicolas indeed, it doesn't matter. Fixed in b82aa62d5af53b6a76c53f12886bac1d810d9ceb","created_at":"2015-12-18T07:55:53Z","updated_at":"2015-12-18T07:55:53Z","html_url":"https://github.com/SonarSource/sonar-javascript/pull/142#discussion_r48001867","pull_request_url":"https://api.github.com/repos/SonarSource/sonar-javascript/pulls/142","_links":{"self":{"href":"https://api.github.com/repos/SonarSource/sonar-javascript/pulls/comments/48001867"},"html":{"href":"https://github.com/SonarSource/sonar-javascript/pull/142#discussion_r48001867"},"pull_request":{"href":"https://api.github.com/repos/SonarSource/sonar-javascript/pulls/142"}}},"pull_request":{"url":"https://api.github.com/repos/SonarSource/sonar-javascript/pulls/142","id":53828716,"html_url":"https://github.com/SonarSource/sonar-javascript/pull/142","diff_url":"https://github.com/SonarSource/sonar-javascript/pull/142.diff","patch_url":"https://github.com/SonarSource/sonar-javascript/pull/142.patch","issue_url":"https://api.github.com/repos/SonarSource/sonar-javascript/issues/142","number":142,"state":"open","locked":false,"title":"SONARJS-119 Rule: Loop counters should not be assigned to from within the loop body","user":{"login":"vilchik-elena","id":10108186,"avatar_url":"https://avatars.githubusercontent.com/u/10108186?v=3","gravatar_id":"","url":"https://api.github.com/users/vilchik-elena","html_url":"https://github.com/vilchik-elena","followers_url":"https://api.github.com/users/vilchik-elena/followers","following_url":"https://api.github.com/users/vilchik-elena/following{/other_user}","gists_url":"https://api.github.com/users/vilchik-elena/gists{/gist_id}","starred_url":"https://api.github.com/users/vilchik-elena/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vilchik-elena/subscriptions","organizations_url":"https://api.github.com/users/vilchik-elena/orgs","repos_url":"https://api.github.com/users/vilchik-elena/repos","events_url":"https://api.github.com/users/vilchik-elena/events{/privacy}","received_events_url":"https://api.github.com/users/vilchik-elena/received_events","type":"User","site_admin":false},"body":"","created_at":"2015-12-16T11:23:14Z","updated_at":"2015-12-18T07:55:53Z","closed_at":null,"merged_at":null,"merge_commit_sha":"40314ec6febae56b628e7f1f193e8e95077a10b9","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/SonarSource/sonar-javascript/pulls/142/commits","review_comments_url":"https://api.github.com/repos/SonarSource/sonar-javascript/pulls/142/comments","review_comment_url":"https://api.github.com/repos/SonarSource/sonar-javascript/pulls/comments{/number}","comments_url":"https://api.github.com/repos/SonarSource/sonar-javascript/issues/142/comments","statuses_url":"https://api.github.com/repos/SonarSource/sonar-javascript/statuses/b82aa62d5af53b6a76c53f12886bac1d810d9ceb","head":{"label":"SonarSource:SONARJS-119","ref":"SONARJS-119","sha":"b82aa62d5af53b6a76c53f12886bac1d810d9ceb","user":{"login":"SonarSource","id":545988,"avatar_url":"https://avatars.githubusercontent.com/u/545988?v=3","gravatar_id":"","url":"https://api.github.com/users/SonarSource","html_url":"https://github.com/SonarSource","followers_url":"https://api.github.com/users/SonarSource/followers","following_url":"https://api.github.com/users/SonarSource/following{/other_user}","gists_url":"https://api.github.com/users/SonarSource/gists{/gist_id}","starred_url":"https://api.github.com/users/SonarSource/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SonarSource/subscriptions","organizations_url":"https://api.github.com/users/SonarSource/orgs","repos_url":"https://api.github.com/users/SonarSource/repos","events_url":"https://api.github.com/users/SonarSource/events{/privacy}","received_events_url":"https://api.github.com/users/SonarSource/received_events","type":"Organization","site_admin":false},"repo":{"id":4335519,"name":"sonar-javascript","full_name":"SonarSource/sonar-javascript","owner":{"login":"SonarSource","id":545988,"avatar_url":"https://avatars.githubusercontent.com/u/545988?v=3","gravatar_id":"","url":"https://api.github.com/users/SonarSource","html_url":"https://github.com/SonarSource","followers_url":"https://api.github.com/users/SonarSource/followers","following_url":"https://api.github.com/users/SonarSource/following{/other_user}","gists_url":"https://api.github.com/users/SonarSource/gists{/gist_id}","starred_url":"https://api.github.com/users/SonarSource/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SonarSource/subscriptions","organizations_url":"https://api.github.com/users/SonarSource/orgs","repos_url":"https://api.github.com/users/SonarSource/repos","events_url":"https://api.github.com/users/SonarSource/events{/privacy}","received_events_url":"https://api.github.com/users/SonarSource/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/SonarSource/sonar-javascript","description":"","fork":false,"url":"https://api.github.com/repos/SonarSource/sonar-javascript","forks_url":"https://api.github.com/repos/SonarSource/sonar-javascript/forks","keys_url":"https://api.github.com/repos/SonarSource/sonar-javascript/keys{/key_id}","collaborators_url":"https://api.github.com/repos/SonarSource/sonar-javascript/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/SonarSource/sonar-javascript/teams","hooks_url":"https://api.github.com/repos/SonarSource/sonar-javascript/hooks","issue_events_url":"https://api.github.com/repos/SonarSource/sonar-javascript/issues/events{/number}","events_url":"https://api.github.com/repos/SonarSource/sonar-javascript/events","assignees_url":"https://api.github.com/repos/SonarSource/sonar-javascript/assignees{/user}","branches_url":"https://api.github.com/repos/SonarSource/sonar-javascript/branches{/branch}","tags_url":"https://api.github.com/repos/SonarSource/sonar-javascript/tags","blobs_url":"https://api.github.com/repos/SonarSource/sonar-javascript/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/SonarSource/sonar-javascript/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/SonarSource/sonar-javascript/git/refs{/sha}","trees_url":"https://api.github.com/repos/SonarSource/sonar-javascript/git/trees{/sha}","statuses_url":"https://api.github.com/repos/SonarSource/sonar-javascript/statuses/{sha}","languages_url":"https://api.github.com/repos/SonarSource/sonar-javascript/languages","stargazers_url":"https://api.github.com/repos/SonarSource/sonar-javascript/stargazers","contributors_url":"https://api.github.com/repos/SonarSource/sonar-javascript/contributors","subscribers_url":"https://api.github.com/repos/SonarSource/sonar-javascript/subscribers","subscription_url":"https://api.github.com/repos/SonarSource/sonar-javascript/subscription","commits_url":"https://api.github.com/repos/SonarSource/sonar-javascript/commits{/sha}","git_commits_url":"https://api.github.com/repos/SonarSource/sonar-javascript/git/commits{/sha}","comments_url":"https://api.github.com/repos/SonarSource/sonar-javascript/comments{/number}","issue_comment_url":"https://api.github.com/repos/SonarSource/sonar-javascript/issues/comments{/number}","contents_url":"https://api.github.com/repos/SonarSource/sonar-javascript/contents/{+path}","compare_url":"https://api.github.com/repos/SonarSource/sonar-javascript/compare/{base}...{head}","merges_url":"https://api.github.com/repos/SonarSource/sonar-javascript/merges","archive_url":"https://api.github.com/repos/SonarSource/sonar-javascript/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/SonarSource/sonar-javascript/downloads","issues_url":"https://api.github.com/repos/SonarSource/sonar-javascript/issues{/number}","pulls_url":"https://api.github.com/repos/SonarSource/sonar-javascript/pulls{/number}","milestones_url":"https://api.github.com/repos/SonarSource/sonar-javascript/milestones{/number}","notifications_url":"https://api.github.com/repos/SonarSource/sonar-javascript/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/SonarSource/sonar-javascript/labels{/name}","releases_url":"https://api.github.com/repos/SonarSource/sonar-javascript/releases{/id}","created_at":"2012-05-15T12:35:38Z","updated_at":"2015-12-15T14:06:45Z","pushed_at":"2015-12-18T07:55:45Z","git_url":"git://github.com/SonarSource/sonar-javascript.git","ssh_url":"git@github.com:SonarSource/sonar-javascript.git","clone_url":"https://github.com/SonarSource/sonar-javascript.git","svn_url":"https://github.com/SonarSource/sonar-javascript","homepage":"http://docs.codehaus.org/display/SONAR/JavaScript+Plugin","size":8220,"stargazers_count":61,"watchers_count":61,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":52,"mirror_url":null,"open_issues_count":3,"forks":52,"open_issues":3,"watchers":61,"default_branch":"master"}},"base":{"label":"SonarSource:master","ref":"master","sha":"0c63c571bd2578078f8cbea6c2807c866787a98f","user":{"login":"SonarSource","id":545988,"avatar_url":"https://avatars.githubusercontent.com/u/545988?v=3","gravatar_id":"","url":"https://api.github.com/users/SonarSource","html_url":"https://github.com/SonarSource","followers_url":"https://api.github.com/users/SonarSource/followers","following_url":"https://api.github.com/users/SonarSource/following{/other_user}","gists_url":"https://api.github.com/users/SonarSource/gists{/gist_id}","starred_url":"https://api.github.com/users/SonarSource/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SonarSource/subscriptions","organizations_url":"https://api.github.com/users/SonarSource/orgs","repos_url":"https://api.github.com/users/SonarSource/repos","events_url":"https://api.github.com/users/SonarSource/events{/privacy}","received_events_url":"https://api.github.com/users/SonarSource/received_events","type":"Organization","site_admin":false},"repo":{"id":4335519,"name":"sonar-javascript","full_name":"SonarSource/sonar-javascript","owner":{"login":"SonarSource","id":545988,"avatar_url":"https://avatars.githubusercontent.com/u/545988?v=3","gravatar_id":"","url":"https://api.github.com/users/SonarSource","html_url":"https://github.com/SonarSource","followers_url":"https://api.github.com/users/SonarSource/followers","following_url":"https://api.github.com/users/SonarSource/following{/other_user}","gists_url":"https://api.github.com/users/SonarSource/gists{/gist_id}","starred_url":"https://api.github.com/users/SonarSource/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SonarSource/subscriptions","organizations_url":"https://api.github.com/users/SonarSource/orgs","repos_url":"https://api.github.com/users/SonarSource/repos","events_url":"https://api.github.com/users/SonarSource/events{/privacy}","received_events_url":"https://api.github.com/users/SonarSource/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/SonarSource/sonar-javascript","description":"","fork":false,"url":"https://api.github.com/repos/SonarSource/sonar-javascript","forks_url":"https://api.github.com/repos/SonarSource/sonar-javascript/forks","keys_url":"https://api.github.com/repos/SonarSource/sonar-javascript/keys{/key_id}","collaborators_url":"https://api.github.com/repos/SonarSource/sonar-javascript/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/SonarSource/sonar-javascript/teams","hooks_url":"https://api.github.com/repos/SonarSource/sonar-javascript/hooks","issue_events_url":"https://api.github.com/repos/SonarSource/sonar-javascript/issues/events{/number}","events_url":"https://api.github.com/repos/SonarSource/sonar-javascript/events","assignees_url":"https://api.github.com/repos/SonarSource/sonar-javascript/assignees{/user}","branches_url":"https://api.github.com/repos/SonarSource/sonar-javascript/branches{/branch}","tags_url":"https://api.github.com/repos/SonarSource/sonar-javascript/tags","blobs_url":"https://api.github.com/repos/SonarSource/sonar-javascript/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/SonarSource/sonar-javascript/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/SonarSource/sonar-javascript/git/refs{/sha}","trees_url":"https://api.github.com/repos/SonarSource/sonar-javascript/git/trees{/sha}","statuses_url":"https://api.github.com/repos/SonarSource/sonar-javascript/statuses/{sha}","languages_url":"https://api.github.com/repos/SonarSource/sonar-javascript/languages","stargazers_url":"https://api.github.com/repos/SonarSource/sonar-javascript/stargazers","contributors_url":"https://api.github.com/repos/SonarSource/sonar-javascript/contributors","subscribers_url":"https://api.github.com/repos/SonarSource/sonar-javascript/subscribers","subscription_url":"https://api.github.com/repos/SonarSource/sonar-javascript/subscription","commits_url":"https://api.github.com/repos/SonarSource/sonar-javascript/commits{/sha}","git_commits_url":"https://api.github.com/repos/SonarSource/sonar-javascript/git/commits{/sha}","comments_url":"https://api.github.com/repos/SonarSource/sonar-javascript/comments{/number}","issue_comment_url":"https://api.github.com/repos/SonarSource/sonar-javascript/issues/comments{/number}","contents_url":"https://api.github.com/repos/SonarSource/sonar-javascript/contents/{+path}","compare_url":"https://api.github.com/repos/SonarSource/sonar-javascript/compare/{base}...{head}","merges_url":"https://api.github.com/repos/SonarSource/sonar-javascript/merges","archive_url":"https://api.github.com/repos/SonarSource/sonar-javascript/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/SonarSource/sonar-javascript/downloads","issues_url":"https://api.github.com/repos/SonarSource/sonar-javascript/issues{/number}","pulls_url":"https://api.github.com/repos/SonarSource/sonar-javascript/pulls{/number}","milestones_url":"https://api.github.com/repos/SonarSource/sonar-javascript/milestones{/number}","notifications_url":"https://api.github.com/repos/SonarSource/sonar-javascript/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/SonarSource/sonar-javascript/labels{/name}","releases_url":"https://api.github.com/repos/SonarSource/sonar-javascript/releases{/id}","created_at":"2012-05-15T12:35:38Z","updated_at":"2015-12-15T14:06:45Z","pushed_at":"2015-12-18T07:55:45Z","git_url":"git://github.com/SonarSource/sonar-javascript.git","ssh_url":"git@github.com:SonarSource/sonar-javascript.git","clone_url":"https://github.com/SonarSource/sonar-javascript.git","svn_url":"https://github.com/SonarSource/sonar-javascript","homepage":"http://docs.codehaus.org/display/SONAR/JavaScript+Plugin","size":8220,"stargazers_count":61,"watchers_count":61,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":52,"mirror_url":null,"open_issues_count":3,"forks":52,"open_issues":3,"watchers":61,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/SonarSource/sonar-javascript/pulls/142"},"html":{"href":"https://github.com/SonarSource/sonar-javascript/pull/142"},"issue":{"href":"https://api.github.com/repos/SonarSource/sonar-javascript/issues/142"},"comments":{"href":"https://api.github.com/repos/SonarSource/sonar-javascript/issues/142/comments"},"review_comments":{"href":"https://api.github.com/repos/SonarSource/sonar-javascript/pulls/142/comments"},"review_comment":{"href":"https://api.github.com/repos/SonarSource/sonar-javascript/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/SonarSource/sonar-javascript/pulls/142/commits"},"statuses":{"href":"https://api.github.com/repos/SonarSource/sonar-javascript/statuses/b82aa62d5af53b6a76c53f12886bac1d810d9ceb"}}}}