{"action":"created","comment":{"url":"https://api.github.com/repos/pmd/pmd/pulls/comments/243182194","pull_request_review_id":186880379,"id":243182194,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDI0MzE4MjE5NA==","diff_hunk":"@@ -0,0 +1,477 @@\n+<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n+<test-data\n+        xmlns=\"http://pmd.sourceforge.net/rule-tests\"\n+        xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n+        xsi:schemaLocation=\"http://pmd.sourceforge.net/rule-tests http://pmd.sourceforge.net/rule-tests_1_0_0.xsd\">\n+    <test-code>\n+        <description>violation: reassigned 'for' loop variable</description>\n+        <expected-problems>1</expected-problems>\n+        <expected-linenumbers>5</expected-linenumbers>\n+        <code><![CDATA[","path":"pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/bestpractices/xml/AvoidReassigningLoopVariables.xml","position":10,"original_position":10,"commit_id":"894ac5bca8c0136e52bddddc64540539e2524926","original_commit_id":"894ac5bca8c0136e52bddddc64540539e2524926","user":{"login":"adangel","id":1573684,"node_id":"MDQ6VXNlcjE1NzM2ODQ=","avatar_url":"https://avatars2.githubusercontent.com/u/1573684?v=4","gravatar_id":"","url":"https://api.github.com/users/adangel","html_url":"https://github.com/adangel","followers_url":"https://api.github.com/users/adangel/followers","following_url":"https://api.github.com/users/adangel/following{/other_user}","gists_url":"https://api.github.com/users/adangel/gists{/gist_id}","starred_url":"https://api.github.com/users/adangel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/adangel/subscriptions","organizations_url":"https://api.github.com/users/adangel/orgs","repos_url":"https://api.github.com/users/adangel/repos","events_url":"https://api.github.com/users/adangel/events{/privacy}","received_events_url":"https://api.github.com/users/adangel/received_events","type":"User","site_admin":false},"body":"To verify, that the message is produced correctly and the loop's variable name is used, you can add also an assert for the message:\r\n\r\n```xml\r\n<expected-messages>\r\n  <message>Avoid reassigning the loop control variable 'i'</message>\r\n</expected-messages>\r\n```\r\n\r\nI think, it's enough, if this is checked for once test case - we don't need to verify this for all.","created_at":"2018-12-20T08:03:02Z","updated_at":"2018-12-20T08:11:23Z","html_url":"https://github.com/pmd/pmd/pull/1530#discussion_r243182194","pull_request_url":"https://api.github.com/repos/pmd/pmd/pulls/1530","author_association":"MEMBER","_links":{"self":{"href":"https://api.github.com/repos/pmd/pmd/pulls/comments/243182194"},"html":{"href":"https://github.com/pmd/pmd/pull/1530#discussion_r243182194"},"pull_request":{"href":"https://api.github.com/repos/pmd/pmd/pulls/1530"}}},"pull_request":{"url":"https://api.github.com/repos/pmd/pmd/pulls/1530","id":239308121,"node_id":"MDExOlB1bGxSZXF1ZXN0MjM5MzA4MTIx","html_url":"https://github.com/pmd/pmd/pull/1530","diff_url":"https://github.com/pmd/pmd/pull/1530.diff","patch_url":"https://github.com/pmd/pmd/pull/1530.patch","issue_url":"https://api.github.com/repos/pmd/pmd/issues/1530","number":1530,"state":"open","locked":false,"title":"[java] New rule: AvoidReassigningLoopVariables","user":{"login":"kris-scheibe","id":20039785,"node_id":"MDQ6VXNlcjIwMDM5Nzg1","avatar_url":"https://avatars2.githubusercontent.com/u/20039785?v=4","gravatar_id":"","url":"https://api.github.com/users/kris-scheibe","html_url":"https://github.com/kris-scheibe","followers_url":"https://api.github.com/users/kris-scheibe/followers","following_url":"https://api.github.com/users/kris-scheibe/following{/other_user}","gists_url":"https://api.github.com/users/kris-scheibe/gists{/gist_id}","starred_url":"https://api.github.com/users/kris-scheibe/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kris-scheibe/subscriptions","organizations_url":"https://api.github.com/users/kris-scheibe/orgs","repos_url":"https://api.github.com/users/kris-scheibe/repos","events_url":"https://api.github.com/users/kris-scheibe/events{/privacy}","received_events_url":"https://api.github.com/users/kris-scheibe/received_events","type":"User","site_admin":false},"body":"This implements the new AvoidReassigningLoopVariables rule proposed in #1518\r\n- the rule checks for and foreach loops\r\n- \"for\" loops: configuration to completely allow/deny changing the variable in the loop body or allow only incrementing/decrementing the variable\r\n- \"foreach\" loops: configuration to completely allow/deny changing the variable in the loop body or allow changing it in the first statement\r\n- test-cases to verify the allow, deny, and intermediate configuration options\r\n\r\n**Rationale for the intermediate configuration options:**\r\n\r\nIncrementing or decrementing a \"for\" loop variable is fairly common, e.g. when skipping/re-reading elements. Setting the variable directly is either a bug or an indicator that the loop is overly complicated. This ensures that the loop variable in general runs through the range of values as given in the header.\r\n\r\nChanging the value of the \"foreach\" loop variable is usually done to clean up the values in the collection. This could also be done by changing/copying the values into a new collection or using a stream().map().forEach() construct; doing it inline is simply more efficient. Changing the variable later in the loop body can be confusing as it isn't immediately visible which part of the loop uses the original value and which part uses the changed value.","created_at":"2018-12-17T22:42:25Z","updated_at":"2018-12-20T08:11:23Z","closed_at":null,"merged_at":null,"merge_commit_sha":"7ebf635085f0421d301992463965dfa69397b018","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[{"id":484475155,"node_id":"MDU6TGFiZWw0ODQ0NzUxNTU=","url":"https://api.github.com/repos/pmd/pmd/labels/a:new-rule","name":"a:new-rule","color":"c2e0c6","default":false}],"milestone":{"url":"https://api.github.com/repos/pmd/pmd/milestones/28","html_url":"https://github.com/pmd/pmd/milestone/28","labels_url":"https://api.github.com/repos/pmd/pmd/milestones/28/labels","id":3882437,"node_id":"MDk6TWlsZXN0b25lMzg4MjQzNw==","number":28,"title":"6.11.0","description":"","creator":{"login":"adangel","id":1573684,"node_id":"MDQ6VXNlcjE1NzM2ODQ=","avatar_url":"https://avatars2.githubusercontent.com/u/1573684?v=4","gravatar_id":"","url":"https://api.github.com/users/adangel","html_url":"https://github.com/adangel","followers_url":"https://api.github.com/users/adangel/followers","following_url":"https://api.github.com/users/adangel/following{/other_user}","gists_url":"https://api.github.com/users/adangel/gists{/gist_id}","starred_url":"https://api.github.com/users/adangel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/adangel/subscriptions","organizations_url":"https://api.github.com/users/adangel/orgs","repos_url":"https://api.github.com/users/adangel/repos","events_url":"https://api.github.com/users/adangel/events{/privacy}","received_events_url":"https://api.github.com/users/adangel/received_events","type":"User","site_admin":false},"open_issues":6,"closed_issues":11,"state":"open","created_at":"2018-12-08T19:16:24Z","updated_at":"2018-12-20T07:29:16Z","due_on":null,"closed_at":null},"commits_url":"https://api.github.com/repos/pmd/pmd/pulls/1530/commits","review_comments_url":"https://api.github.com/repos/pmd/pmd/pulls/1530/comments","review_comment_url":"https://api.github.com/repos/pmd/pmd/pulls/comments{/number}","comments_url":"https://api.github.com/repos/pmd/pmd/issues/1530/comments","statuses_url":"https://api.github.com/repos/pmd/pmd/statuses/894ac5bca8c0136e52bddddc64540539e2524926","head":{"label":"kris-scheibe:feature/AvoidReassigningLoopVariables","ref":"feature/AvoidReassigningLoopVariables","sha":"894ac5bca8c0136e52bddddc64540539e2524926","user":{"login":"kris-scheibe","id":20039785,"node_id":"MDQ6VXNlcjIwMDM5Nzg1","avatar_url":"https://avatars2.githubusercontent.com/u/20039785?v=4","gravatar_id":"","url":"https://api.github.com/users/kris-scheibe","html_url":"https://github.com/kris-scheibe","followers_url":"https://api.github.com/users/kris-scheibe/followers","following_url":"https://api.github.com/users/kris-scheibe/following{/other_user}","gists_url":"https://api.github.com/users/kris-scheibe/gists{/gist_id}","starred_url":"https://api.github.com/users/kris-scheibe/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kris-scheibe/subscriptions","organizations_url":"https://api.github.com/users/kris-scheibe/orgs","repos_url":"https://api.github.com/users/kris-scheibe/repos","events_url":"https://api.github.com/users/kris-scheibe/events{/privacy}","received_events_url":"https://api.github.com/users/kris-scheibe/received_events","type":"User","site_admin":false},"repo":{"id":148153834,"node_id":"MDEwOlJlcG9zaXRvcnkxNDgxNTM4MzQ=","name":"pmd","full_name":"kris-scheibe/pmd","private":false,"owner":{"login":"kris-scheibe","id":20039785,"node_id":"MDQ6VXNlcjIwMDM5Nzg1","avatar_url":"https://avatars2.githubusercontent.com/u/20039785?v=4","gravatar_id":"","url":"https://api.github.com/users/kris-scheibe","html_url":"https://github.com/kris-scheibe","followers_url":"https://api.github.com/users/kris-scheibe/followers","following_url":"https://api.github.com/users/kris-scheibe/following{/other_user}","gists_url":"https://api.github.com/users/kris-scheibe/gists{/gist_id}","starred_url":"https://api.github.com/users/kris-scheibe/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kris-scheibe/subscriptions","organizations_url":"https://api.github.com/users/kris-scheibe/orgs","repos_url":"https://api.github.com/users/kris-scheibe/repos","events_url":"https://api.github.com/users/kris-scheibe/events{/privacy}","received_events_url":"https://api.github.com/users/kris-scheibe/received_events","type":"User","site_admin":false},"html_url":"https://github.com/kris-scheibe/pmd","description":"An extensible cross-language static code analyzer.","fork":true,"url":"https://api.github.com/repos/kris-scheibe/pmd","forks_url":"https://api.github.com/repos/kris-scheibe/pmd/forks","keys_url":"https://api.github.com/repos/kris-scheibe/pmd/keys{/key_id}","collaborators_url":"https://api.github.com/repos/kris-scheibe/pmd/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/kris-scheibe/pmd/teams","hooks_url":"https://api.github.com/repos/kris-scheibe/pmd/hooks","issue_events_url":"https://api.github.com/repos/kris-scheibe/pmd/issues/events{/number}","events_url":"https://api.github.com/repos/kris-scheibe/pmd/events","assignees_url":"https://api.github.com/repos/kris-scheibe/pmd/assignees{/user}","branches_url":"https://api.github.com/repos/kris-scheibe/pmd/branches{/branch}","tags_url":"https://api.github.com/repos/kris-scheibe/pmd/tags","blobs_url":"https://api.github.com/repos/kris-scheibe/pmd/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/kris-scheibe/pmd/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/kris-scheibe/pmd/git/refs{/sha}","trees_url":"https://api.github.com/repos/kris-scheibe/pmd/git/trees{/sha}","statuses_url":"https://api.github.com/repos/kris-scheibe/pmd/statuses/{sha}","languages_url":"https://api.github.com/repos/kris-scheibe/pmd/languages","stargazers_url":"https://api.github.com/repos/kris-scheibe/pmd/stargazers","contributors_url":"https://api.github.com/repos/kris-scheibe/pmd/contributors","subscribers_url":"https://api.github.com/repos/kris-scheibe/pmd/subscribers","subscription_url":"https://api.github.com/repos/kris-scheibe/pmd/subscription","commits_url":"https://api.github.com/repos/kris-scheibe/pmd/commits{/sha}","git_commits_url":"https://api.github.com/repos/kris-scheibe/pmd/git/commits{/sha}","comments_url":"https://api.github.com/repos/kris-scheibe/pmd/comments{/number}","issue_comment_url":"https://api.github.com/repos/kris-scheibe/pmd/issues/comments{/number}","contents_url":"https://api.github.com/repos/kris-scheibe/pmd/contents/{+path}","compare_url":"https://api.github.com/repos/kris-scheibe/pmd/compare/{base}...{head}","merges_url":"https://api.github.com/repos/kris-scheibe/pmd/merges","archive_url":"https://api.github.com/repos/kris-scheibe/pmd/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/kris-scheibe/pmd/downloads","issues_url":"https://api.github.com/repos/kris-scheibe/pmd/issues{/number}","pulls_url":"https://api.github.com/repos/kris-scheibe/pmd/pulls{/number}","milestones_url":"https://api.github.com/repos/kris-scheibe/pmd/milestones{/number}","notifications_url":"https://api.github.com/repos/kris-scheibe/pmd/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/kris-scheibe/pmd/labels{/name}","releases_url":"https://api.github.com/repos/kris-scheibe/pmd/releases{/id}","deployments_url":"https://api.github.com/repos/kris-scheibe/pmd/deployments","created_at":"2018-09-10T12:44:54Z","updated_at":"2018-12-09T11:25:17Z","pushed_at":"2018-12-19T23:15:49Z","git_url":"git://github.com/kris-scheibe/pmd.git","ssh_url":"git@github.com:kris-scheibe/pmd.git","clone_url":"https://github.com/kris-scheibe/pmd.git","svn_url":"https://github.com/kris-scheibe/pmd","homepage":"https://pmd.github.io","size":249630,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":0,"license":{"key":"other","name":"Other","spdx_id":"NOASSERTION","url":null,"node_id":"MDc6TGljZW5zZTA="},"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"pmd:master","ref":"master","sha":"e079d0c2e9105e150eb4c6e2391ed75a72c5ddde","user":{"login":"pmd","id":1958157,"node_id":"MDEyOk9yZ2FuaXphdGlvbjE5NTgxNTc=","avatar_url":"https://avatars0.githubusercontent.com/u/1958157?v=4","gravatar_id":"","url":"https://api.github.com/users/pmd","html_url":"https://github.com/pmd","followers_url":"https://api.github.com/users/pmd/followers","following_url":"https://api.github.com/users/pmd/following{/other_user}","gists_url":"https://api.github.com/users/pmd/gists{/gist_id}","starred_url":"https://api.github.com/users/pmd/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pmd/subscriptions","organizations_url":"https://api.github.com/users/pmd/orgs","repos_url":"https://api.github.com/users/pmd/repos","events_url":"https://api.github.com/users/pmd/events{/privacy}","received_events_url":"https://api.github.com/users/pmd/received_events","type":"Organization","site_admin":false},"repo":{"id":4992906,"node_id":"MDEwOlJlcG9zaXRvcnk0OTkyOTA2","name":"pmd","full_name":"pmd/pmd","private":false,"owner":{"login":"pmd","id":1958157,"node_id":"MDEyOk9yZ2FuaXphdGlvbjE5NTgxNTc=","avatar_url":"https://avatars0.githubusercontent.com/u/1958157?v=4","gravatar_id":"","url":"https://api.github.com/users/pmd","html_url":"https://github.com/pmd","followers_url":"https://api.github.com/users/pmd/followers","following_url":"https://api.github.com/users/pmd/following{/other_user}","gists_url":"https://api.github.com/users/pmd/gists{/gist_id}","starred_url":"https://api.github.com/users/pmd/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pmd/subscriptions","organizations_url":"https://api.github.com/users/pmd/orgs","repos_url":"https://api.github.com/users/pmd/repos","events_url":"https://api.github.com/users/pmd/events{/privacy}","received_events_url":"https://api.github.com/users/pmd/received_events","type":"Organization","site_admin":false},"html_url":"https://github.com/pmd/pmd","description":"An extensible multilanguage static code analyzer.","fork":false,"url":"https://api.github.com/repos/pmd/pmd","forks_url":"https://api.github.com/repos/pmd/pmd/forks","keys_url":"https://api.github.com/repos/pmd/pmd/keys{/key_id}","collaborators_url":"https://api.github.com/repos/pmd/pmd/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/pmd/pmd/teams","hooks_url":"https://api.github.com/repos/pmd/pmd/hooks","issue_events_url":"https://api.github.com/repos/pmd/pmd/issues/events{/number}","events_url":"https://api.github.com/repos/pmd/pmd/events","assignees_url":"https://api.github.com/repos/pmd/pmd/assignees{/user}","branches_url":"https://api.github.com/repos/pmd/pmd/branches{/branch}","tags_url":"https://api.github.com/repos/pmd/pmd/tags","blobs_url":"https://api.github.com/repos/pmd/pmd/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/pmd/pmd/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/pmd/pmd/git/refs{/sha}","trees_url":"https://api.github.com/repos/pmd/pmd/git/trees{/sha}","statuses_url":"https://api.github.com/repos/pmd/pmd/statuses/{sha}","languages_url":"https://api.github.com/repos/pmd/pmd/languages","stargazers_url":"https://api.github.com/repos/pmd/pmd/stargazers","contributors_url":"https://api.github.com/repos/pmd/pmd/contributors","subscribers_url":"https://api.github.com/repos/pmd/pmd/subscribers","subscription_url":"https://api.github.com/repos/pmd/pmd/subscription","commits_url":"https://api.github.com/repos/pmd/pmd/commits{/sha}","git_commits_url":"https://api.github.com/repos/pmd/pmd/git/commits{/sha}","comments_url":"https://api.github.com/repos/pmd/pmd/comments{/number}","issue_comment_url":"https://api.github.com/repos/pmd/pmd/issues/comments{/number}","contents_url":"https://api.github.com/repos/pmd/pmd/contents/{+path}","compare_url":"https://api.github.com/repos/pmd/pmd/compare/{base}...{head}","merges_url":"https://api.github.com/repos/pmd/pmd/merges","archive_url":"https://api.github.com/repos/pmd/pmd/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/pmd/pmd/downloads","issues_url":"https://api.github.com/repos/pmd/pmd/issues{/number}","pulls_url":"https://api.github.com/repos/pmd/pmd/pulls{/number}","milestones_url":"https://api.github.com/repos/pmd/pmd/milestones{/number}","notifications_url":"https://api.github.com/repos/pmd/pmd/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/pmd/pmd/labels{/name}","releases_url":"https://api.github.com/repos/pmd/pmd/releases{/id}","deployments_url":"https://api.github.com/repos/pmd/pmd/deployments","created_at":"2012-07-11T18:03:00Z","updated_at":"2018-12-20T07:39:15Z","pushed_at":"2018-12-19T23:15:51Z","git_url":"git://github.com/pmd/pmd.git","ssh_url":"git@github.com:pmd/pmd.git","clone_url":"https://github.com/pmd/pmd.git","svn_url":"https://github.com/pmd/pmd","homepage":"https://pmd.github.io","size":255689,"stargazers_count":1969,"watchers_count":1969,"language":"Java","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":686,"mirror_url":null,"archived":false,"open_issues_count":213,"license":{"key":"other","name":"Other","spdx_id":"NOASSERTION","url":null,"node_id":"MDc6TGljZW5zZTA="},"forks":686,"open_issues":213,"watchers":1969,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/pmd/pmd/pulls/1530"},"html":{"href":"https://github.com/pmd/pmd/pull/1530"},"issue":{"href":"https://api.github.com/repos/pmd/pmd/issues/1530"},"comments":{"href":"https://api.github.com/repos/pmd/pmd/issues/1530/comments"},"review_comments":{"href":"https://api.github.com/repos/pmd/pmd/pulls/1530/comments"},"review_comment":{"href":"https://api.github.com/repos/pmd/pmd/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/pmd/pmd/pulls/1530/commits"},"statuses":{"href":"https://api.github.com/repos/pmd/pmd/statuses/894ac5bca8c0136e52bddddc64540539e2524926"}},"author_association":"CONTRIBUTOR"}}
{"actor":{"display_login":"adangel"}}