{"action":"created","comment":{"url":"https://api.github.com/repos/rubocop-hq/rubocop/pulls/comments/219689034","pull_request_review_id":157929443,"id":219689034,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDIxOTY4OTAzNA==","diff_hunk":"@@ -99,14 +99,39 @@ def incorrect_style_detected(node)\n \n         def autocorrect_to_each(node)\n           item, enumerable = deconstruct_for(node)\n-          loc_begin = node.loc.begin\n-          end_pos = loc_begin ? loc_begin.end_pos : enumerable.loc.end.end_pos\n+\n+          end_pos = end_position(node, enumerable)\n+\n           replacement_range = replacement_range(node, end_pos)\n-          correction = \"#{enumerable.source}.each do |#{item.source}|\"\n \n+          enum_source = enumerable_source(enumerable)\n+\n+          correction = \"#{enum_source}.each do |#{item.source}|\"\n           ->(corrector) { corrector.replace(replacement_range, correction) }\n         end\n \n+        def end_position(node, enumerable)\n+          if node.do?\n+            node.loc.begin.end_pos\n+          elsif enumerable.begin_type?\n+            enumerable.loc.end.end_pos\n+          else\n+            enumerable.loc.expression.end.end_pos\n+          end\n+        end\n+\n+        def enumerable_source(enumerable)\n+          return \"(#{enumerable.source})\" if wrap_into_parentheses?(enumerable)\n+\n+          enumerable.source\n+        end\n+\n+        def wrap_into_parentheses?(enumerable)\n+          !enumerable.begin_type? &&","path":"lib/rubocop/cop/style/for.rb","position":35,"original_position":35,"commit_id":"50655db26007d3349426e0ca404ad60655ee7e5e","original_commit_id":"50655db26007d3349426e0ca404ad60655ee7e5e","user":{"login":"lukasz-wojcik","id":971820,"node_id":"MDQ6VXNlcjk3MTgyMA==","avatar_url":"https://avatars2.githubusercontent.com/u/971820?v=4","gravatar_id":"","url":"https://api.github.com/users/lukasz-wojcik","html_url":"https://github.com/lukasz-wojcik","followers_url":"https://api.github.com/users/lukasz-wojcik/followers","following_url":"https://api.github.com/users/lukasz-wojcik/following{/other_user}","gists_url":"https://api.github.com/users/lukasz-wojcik/gists{/gist_id}","starred_url":"https://api.github.com/users/lukasz-wojcik/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lukasz-wojcik/subscriptions","organizations_url":"https://api.github.com/users/lukasz-wojcik/orgs","repos_url":"https://api.github.com/users/lukasz-wojcik/repos","events_url":"https://api.github.com/users/lukasz-wojcik/events{/privacy}","received_events_url":"https://api.github.com/users/lukasz-wojcik/received_events","type":"User","site_admin":false},"body":"This is needed for the case:\r\n```\r\nfor n in 1...value\r\n....\r\n```\r\n\r\nwhen range is not enclosed in parenthesis the `begin_type?`  check returns false. Then we know that autocorrect must wrap the enumerable.source into `( ... )`. Otherwise it would generate invalid code:\r\n`1...value.each`","created_at":"2018-09-23T05:48:08Z","updated_at":"2018-09-23T05:48:08Z","html_url":"https://github.com/rubocop-hq/rubocop/pull/6320#discussion_r219689034","pull_request_url":"https://api.github.com/repos/rubocop-hq/rubocop/pulls/6320","author_association":"NONE","_links":{"self":{"href":"https://api.github.com/repos/rubocop-hq/rubocop/pulls/comments/219689034"},"html":{"href":"https://github.com/rubocop-hq/rubocop/pull/6320#discussion_r219689034"},"pull_request":{"href":"https://api.github.com/repos/rubocop-hq/rubocop/pulls/6320"}},"in_reply_to_id":219674373},"pull_request":{"url":"https://api.github.com/repos/rubocop-hq/rubocop/pulls/6320","id":217445262,"node_id":"MDExOlB1bGxSZXF1ZXN0MjE3NDQ1MjYy","html_url":"https://github.com/rubocop-hq/rubocop/pull/6320","diff_url":"https://github.com/rubocop-hq/rubocop/pull/6320.diff","patch_url":"https://github.com/rubocop-hq/rubocop/pull/6320.patch","issue_url":"https://api.github.com/repos/rubocop-hq/rubocop/issues/6320","number":6320,"state":"open","locked":false,"title":"[Fix #6316] Fix auto-correct for `Style/For` cop","user":{"login":"lukasz-wojcik","id":971820,"node_id":"MDQ6VXNlcjk3MTgyMA==","avatar_url":"https://avatars2.githubusercontent.com/u/971820?v=4","gravatar_id":"","url":"https://api.github.com/users/lukasz-wojcik","html_url":"https://github.com/lukasz-wojcik","followers_url":"https://api.github.com/users/lukasz-wojcik/followers","following_url":"https://api.github.com/users/lukasz-wojcik/following{/other_user}","gists_url":"https://api.github.com/users/lukasz-wojcik/gists{/gist_id}","starred_url":"https://api.github.com/users/lukasz-wojcik/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lukasz-wojcik/subscriptions","organizations_url":"https://api.github.com/users/lukasz-wojcik/orgs","repos_url":"https://api.github.com/users/lukasz-wojcik/repos","events_url":"https://api.github.com/users/lukasz-wojcik/events{/privacy}","received_events_url":"https://api.github.com/users/lukasz-wojcik/received_events","type":"User","site_admin":false},"body":"Fixes #6316 \r\n\r\nIt also makes sure that when the range is provided with or  without an enclosing parenthesis the resulting auto correction to `each` will generate a valid code. \r\n\r\n-----------------\r\n\r\nBefore submitting the PR make sure the following are checked:\r\n\r\n* [x] Wrote [good commit messages][1].\r\n* [x] Commit message starts with `[Fix #issue-number]` (if the related issue exists).\r\n* [x] Feature branch is up-to-date with `master` (if not - rebase it).\r\n* [x] Squashed related commits together.\r\n* [x] Added tests.\r\n* [x] Added an entry to the [Changelog](../blob/master/CHANGELOG.md) if the new code introduces user-observable changes. See [changelog entry format](../blob/master/CONTRIBUTING.md#changelog-entry-format).\r\n* [x] The PR relates to *only* one subject with a clear title\r\n  and description in grammatically correct, complete sentences.\r\n* [x] Run `rake default`. It executes all tests and RuboCop for itself, and generates the documentation.\r\n\r\n[1]: http://chris.beams.io/posts/git-commit/\r\n","created_at":"2018-09-22T08:00:25Z","updated_at":"2018-09-23T05:48:08Z","closed_at":null,"merged_at":null,"merge_commit_sha":"f3fde73996cac056599db7f8af0688b60047aa36","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/rubocop-hq/rubocop/pulls/6320/commits","review_comments_url":"https://api.github.com/repos/rubocop-hq/rubocop/pulls/6320/comments","review_comment_url":"https://api.github.com/repos/rubocop-hq/rubocop/pulls/comments{/number}","comments_url":"https://api.github.com/repos/rubocop-hq/rubocop/issues/6320/comments","statuses_url":"https://api.github.com/repos/rubocop-hq/rubocop/statuses/50655db26007d3349426e0ca404ad60655ee7e5e","head":{"label":"lukasz-wojcik:fix-for-style-cop-with-range","ref":"fix-for-style-cop-with-range","sha":"50655db26007d3349426e0ca404ad60655ee7e5e","user":{"login":"lukasz-wojcik","id":971820,"node_id":"MDQ6VXNlcjk3MTgyMA==","avatar_url":"https://avatars2.githubusercontent.com/u/971820?v=4","gravatar_id":"","url":"https://api.github.com/users/lukasz-wojcik","html_url":"https://github.com/lukasz-wojcik","followers_url":"https://api.github.com/users/lukasz-wojcik/followers","following_url":"https://api.github.com/users/lukasz-wojcik/following{/other_user}","gists_url":"https://api.github.com/users/lukasz-wojcik/gists{/gist_id}","starred_url":"https://api.github.com/users/lukasz-wojcik/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lukasz-wojcik/subscriptions","organizations_url":"https://api.github.com/users/lukasz-wojcik/orgs","repos_url":"https://api.github.com/users/lukasz-wojcik/repos","events_url":"https://api.github.com/users/lukasz-wojcik/events{/privacy}","received_events_url":"https://api.github.com/users/lukasz-wojcik/received_events","type":"User","site_admin":false},"repo":{"id":149852455,"node_id":"MDEwOlJlcG9zaXRvcnkxNDk4NTI0NTU=","name":"rubocop","full_name":"lukasz-wojcik/rubocop","private":false,"owner":{"login":"lukasz-wojcik","id":971820,"node_id":"MDQ6VXNlcjk3MTgyMA==","avatar_url":"https://avatars2.githubusercontent.com/u/971820?v=4","gravatar_id":"","url":"https://api.github.com/users/lukasz-wojcik","html_url":"https://github.com/lukasz-wojcik","followers_url":"https://api.github.com/users/lukasz-wojcik/followers","following_url":"https://api.github.com/users/lukasz-wojcik/following{/other_user}","gists_url":"https://api.github.com/users/lukasz-wojcik/gists{/gist_id}","starred_url":"https://api.github.com/users/lukasz-wojcik/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lukasz-wojcik/subscriptions","organizations_url":"https://api.github.com/users/lukasz-wojcik/orgs","repos_url":"https://api.github.com/users/lukasz-wojcik/repos","events_url":"https://api.github.com/users/lukasz-wojcik/events{/privacy}","received_events_url":"https://api.github.com/users/lukasz-wojcik/received_events","type":"User","site_admin":false},"html_url":"https://github.com/lukasz-wojcik/rubocop","description":"A Ruby static code analyzer and formatter, based on the community Ruby style guide.","fork":true,"url":"https://api.github.com/repos/lukasz-wojcik/rubocop","forks_url":"https://api.github.com/repos/lukasz-wojcik/rubocop/forks","keys_url":"https://api.github.com/repos/lukasz-wojcik/rubocop/keys{/key_id}","collaborators_url":"https://api.github.com/repos/lukasz-wojcik/rubocop/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/lukasz-wojcik/rubocop/teams","hooks_url":"https://api.github.com/repos/lukasz-wojcik/rubocop/hooks","issue_events_url":"https://api.github.com/repos/lukasz-wojcik/rubocop/issues/events{/number}","events_url":"https://api.github.com/repos/lukasz-wojcik/rubocop/events","assignees_url":"https://api.github.com/repos/lukasz-wojcik/rubocop/assignees{/user}","branches_url":"https://api.github.com/repos/lukasz-wojcik/rubocop/branches{/branch}","tags_url":"https://api.github.com/repos/lukasz-wojcik/rubocop/tags","blobs_url":"https://api.github.com/repos/lukasz-wojcik/rubocop/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/lukasz-wojcik/rubocop/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/lukasz-wojcik/rubocop/git/refs{/sha}","trees_url":"https://api.github.com/repos/lukasz-wojcik/rubocop/git/trees{/sha}","statuses_url":"https://api.github.com/repos/lukasz-wojcik/rubocop/statuses/{sha}","languages_url":"https://api.github.com/repos/lukasz-wojcik/rubocop/languages","stargazers_url":"https://api.github.com/repos/lukasz-wojcik/rubocop/stargazers","contributors_url":"https://api.github.com/repos/lukasz-wojcik/rubocop/contributors","subscribers_url":"https://api.github.com/repos/lukasz-wojcik/rubocop/subscribers","subscription_url":"https://api.github.com/repos/lukasz-wojcik/rubocop/subscription","commits_url":"https://api.github.com/repos/lukasz-wojcik/rubocop/commits{/sha}","git_commits_url":"https://api.github.com/repos/lukasz-wojcik/rubocop/git/commits{/sha}","comments_url":"https://api.github.com/repos/lukasz-wojcik/rubocop/comments{/number}","issue_comment_url":"https://api.github.com/repos/lukasz-wojcik/rubocop/issues/comments{/number}","contents_url":"https://api.github.com/repos/lukasz-wojcik/rubocop/contents/{+path}","compare_url":"https://api.github.com/repos/lukasz-wojcik/rubocop/compare/{base}...{head}","merges_url":"https://api.github.com/repos/lukasz-wojcik/rubocop/merges","archive_url":"https://api.github.com/repos/lukasz-wojcik/rubocop/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/lukasz-wojcik/rubocop/downloads","issues_url":"https://api.github.com/repos/lukasz-wojcik/rubocop/issues{/number}","pulls_url":"https://api.github.com/repos/lukasz-wojcik/rubocop/pulls{/number}","milestones_url":"https://api.github.com/repos/lukasz-wojcik/rubocop/milestones{/number}","notifications_url":"https://api.github.com/repos/lukasz-wojcik/rubocop/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/lukasz-wojcik/rubocop/labels{/name}","releases_url":"https://api.github.com/repos/lukasz-wojcik/rubocop/releases{/id}","deployments_url":"https://api.github.com/repos/lukasz-wojcik/rubocop/deployments","created_at":"2018-09-22T06:38:49Z","updated_at":"2018-09-22T06:38:54Z","pushed_at":"2018-09-22T07:50:53Z","git_url":"git://github.com/lukasz-wojcik/rubocop.git","ssh_url":"git@github.com:lukasz-wojcik/rubocop.git","clone_url":"https://github.com/lukasz-wojcik/rubocop.git","svn_url":"https://github.com/lukasz-wojcik/rubocop","homepage":"http://docs.rubocop.org","size":23264,"stargazers_count":0,"watchers_count":0,"language":"Ruby","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":"mit","name":"MIT License","spdx_id":"MIT","url":"https://api.github.com/licenses/mit","node_id":"MDc6TGljZW5zZTEz"},"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"rubocop-hq:master","ref":"master","sha":"52003486cb50a0a738356fc1e97e8356bd30d65a","user":{"login":"rubocop-hq","id":39672756,"node_id":"MDEyOk9yZ2FuaXphdGlvbjM5NjcyNzU2","avatar_url":"https://avatars3.githubusercontent.com/u/39672756?v=4","gravatar_id":"","url":"https://api.github.com/users/rubocop-hq","html_url":"https://github.com/rubocop-hq","followers_url":"https://api.github.com/users/rubocop-hq/followers","following_url":"https://api.github.com/users/rubocop-hq/following{/other_user}","gists_url":"https://api.github.com/users/rubocop-hq/gists{/gist_id}","starred_url":"https://api.github.com/users/rubocop-hq/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rubocop-hq/subscriptions","organizations_url":"https://api.github.com/users/rubocop-hq/orgs","repos_url":"https://api.github.com/users/rubocop-hq/repos","events_url":"https://api.github.com/users/rubocop-hq/events{/privacy}","received_events_url":"https://api.github.com/users/rubocop-hq/received_events","type":"Organization","site_admin":false},"repo":{"id":4095287,"node_id":"MDEwOlJlcG9zaXRvcnk0MDk1Mjg3","name":"rubocop","full_name":"rubocop-hq/rubocop","private":false,"owner":{"login":"rubocop-hq","id":39672756,"node_id":"MDEyOk9yZ2FuaXphdGlvbjM5NjcyNzU2","avatar_url":"https://avatars3.githubusercontent.com/u/39672756?v=4","gravatar_id":"","url":"https://api.github.com/users/rubocop-hq","html_url":"https://github.com/rubocop-hq","followers_url":"https://api.github.com/users/rubocop-hq/followers","following_url":"https://api.github.com/users/rubocop-hq/following{/other_user}","gists_url":"https://api.github.com/users/rubocop-hq/gists{/gist_id}","starred_url":"https://api.github.com/users/rubocop-hq/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rubocop-hq/subscriptions","organizations_url":"https://api.github.com/users/rubocop-hq/orgs","repos_url":"https://api.github.com/users/rubocop-hq/repos","events_url":"https://api.github.com/users/rubocop-hq/events{/privacy}","received_events_url":"https://api.github.com/users/rubocop-hq/received_events","type":"Organization","site_admin":false},"html_url":"https://github.com/rubocop-hq/rubocop","description":"A Ruby static code analyzer and formatter, based on the community Ruby style guide.","fork":false,"url":"https://api.github.com/repos/rubocop-hq/rubocop","forks_url":"https://api.github.com/repos/rubocop-hq/rubocop/forks","keys_url":"https://api.github.com/repos/rubocop-hq/rubocop/keys{/key_id}","collaborators_url":"https://api.github.com/repos/rubocop-hq/rubocop/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/rubocop-hq/rubocop/teams","hooks_url":"https://api.github.com/repos/rubocop-hq/rubocop/hooks","issue_events_url":"https://api.github.com/repos/rubocop-hq/rubocop/issues/events{/number}","events_url":"https://api.github.com/repos/rubocop-hq/rubocop/events","assignees_url":"https://api.github.com/repos/rubocop-hq/rubocop/assignees{/user}","branches_url":"https://api.github.com/repos/rubocop-hq/rubocop/branches{/branch}","tags_url":"https://api.github.com/repos/rubocop-hq/rubocop/tags","blobs_url":"https://api.github.com/repos/rubocop-hq/rubocop/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/rubocop-hq/rubocop/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/rubocop-hq/rubocop/git/refs{/sha}","trees_url":"https://api.github.com/repos/rubocop-hq/rubocop/git/trees{/sha}","statuses_url":"https://api.github.com/repos/rubocop-hq/rubocop/statuses/{sha}","languages_url":"https://api.github.com/repos/rubocop-hq/rubocop/languages","stargazers_url":"https://api.github.com/repos/rubocop-hq/rubocop/stargazers","contributors_url":"https://api.github.com/repos/rubocop-hq/rubocop/contributors","subscribers_url":"https://api.github.com/repos/rubocop-hq/rubocop/subscribers","subscription_url":"https://api.github.com/repos/rubocop-hq/rubocop/subscription","commits_url":"https://api.github.com/repos/rubocop-hq/rubocop/commits{/sha}","git_commits_url":"https://api.github.com/repos/rubocop-hq/rubocop/git/commits{/sha}","comments_url":"https://api.github.com/repos/rubocop-hq/rubocop/comments{/number}","issue_comment_url":"https://api.github.com/repos/rubocop-hq/rubocop/issues/comments{/number}","contents_url":"https://api.github.com/repos/rubocop-hq/rubocop/contents/{+path}","compare_url":"https://api.github.com/repos/rubocop-hq/rubocop/compare/{base}...{head}","merges_url":"https://api.github.com/repos/rubocop-hq/rubocop/merges","archive_url":"https://api.github.com/repos/rubocop-hq/rubocop/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/rubocop-hq/rubocop/downloads","issues_url":"https://api.github.com/repos/rubocop-hq/rubocop/issues{/number}","pulls_url":"https://api.github.com/repos/rubocop-hq/rubocop/pulls{/number}","milestones_url":"https://api.github.com/repos/rubocop-hq/rubocop/milestones{/number}","notifications_url":"https://api.github.com/repos/rubocop-hq/rubocop/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/rubocop-hq/rubocop/labels{/name}","releases_url":"https://api.github.com/repos/rubocop-hq/rubocop/releases{/id}","deployments_url":"https://api.github.com/repos/rubocop-hq/rubocop/deployments","created_at":"2012-04-21T10:09:58Z","updated_at":"2018-09-22T22:00:04Z","pushed_at":"2018-09-22T08:00:26Z","git_url":"git://github.com/rubocop-hq/rubocop.git","ssh_url":"git@github.com:rubocop-hq/rubocop.git","clone_url":"https://github.com/rubocop-hq/rubocop.git","svn_url":"https://github.com/rubocop-hq/rubocop","homepage":"http://docs.rubocop.org","size":23257,"stargazers_count":9392,"watchers_count":9392,"language":"Ruby","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":1895,"mirror_url":null,"archived":false,"open_issues_count":196,"license":{"key":"mit","name":"MIT License","spdx_id":"MIT","url":"https://api.github.com/licenses/mit","node_id":"MDc6TGljZW5zZTEz"},"forks":1895,"open_issues":196,"watchers":9392,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/rubocop-hq/rubocop/pulls/6320"},"html":{"href":"https://github.com/rubocop-hq/rubocop/pull/6320"},"issue":{"href":"https://api.github.com/repos/rubocop-hq/rubocop/issues/6320"},"comments":{"href":"https://api.github.com/repos/rubocop-hq/rubocop/issues/6320/comments"},"review_comments":{"href":"https://api.github.com/repos/rubocop-hq/rubocop/pulls/6320/comments"},"review_comment":{"href":"https://api.github.com/repos/rubocop-hq/rubocop/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/rubocop-hq/rubocop/pulls/6320/commits"},"statuses":{"href":"https://api.github.com/repos/rubocop-hq/rubocop/statuses/50655db26007d3349426e0ca404ad60655ee7e5e"}},"author_association":"NONE"}}
{"actor":{"display_login":"lukasz-wojcik"}}