{"action":"created","comment":{"url":"https://api.github.com/repos/codeclimate/codeclimate-rubocop/pulls/comments/40830782","id":40830782,"diff_hunk":"@@ -0,0 +1,72 @@\n+require \"rubocop\"\n+require \"active_support\"\n+require \"active_support/core_ext\"\n+require \"cc/engine/category_parser\"\n+\n+module CC\n+  module Engine\n+    class ViolationHash\n+      def initialize(violation, local_path)\n+        @violation = violation\n+        @local_path = local_path\n+      end\n+\n+      def to_json\n+        result = {\n+          type: \"Issue\",\n+          check_name: \"Rubocop/#{violation.cop_name}\",\n+          description: violation.message,\n+          categories: [category(violation.cop_name)],\n+          remediation_points: 50_000,\n+          location: {\n+            path: local_path,\n+            positions: violation_positions(violation.location),\n+          },\n+        }\n+        body = content_body(violation.cop_name)\n+        result.merge!(content: { body: body }) if body.present?\n+        result.to_json\n+      end\n+\n+      private\n+\n+      attr_reader :violation, :local_path\n+\n+      def category(cop_name)\n+        CategoryParser.new(cop_name).category\n+      end\n+\n+      def violation_positions(location)\n+        if location.is_a?(RuboCop::Cop::Lint::Syntax::PseudoSourceRange)\n+          first_line = location.line\n+          last_line = location.line\n+          first_column = location.column\n+          last_column = location.column\n+        else\n+          first_line = location.first_line\n+          last_line = location.last_line\n+          first_column = location.column\n+          last_column = location.last_column\n+        end\n+\n+        {\n+          begin: {\n+            column: first_column + 1, # columns are 0-based in Parser\n+            line: first_line,\n+          },\n+          end: {\n+            column: last_column + 1,\n+            line: last_line,\n+          }\n+        }\n+      end\n+\n+      def content_body(cop_name)\n+        path = File.expand_path(\n+          \"../../../../config/contents/#{cop_name.underscore}.md\", __FILE__","path":"lib/cc/engine/violation_hash.rb","position":66,"original_position":66,"commit_id":"5e0dd2a3fe5c53e32fad3ea7027b3106961930fe","original_commit_id":"5e0dd2a3fe5c53e32fad3ea7027b3106961930fe","user":{"login":"BlakeWilliams","id":342554,"avatar_url":"https://avatars.githubusercontent.com/u/342554?v=3","gravatar_id":"","url":"https://api.github.com/users/BlakeWilliams","html_url":"https://github.com/BlakeWilliams","followers_url":"https://api.github.com/users/BlakeWilliams/followers","following_url":"https://api.github.com/users/BlakeWilliams/following{/other_user}","gists_url":"https://api.github.com/users/BlakeWilliams/gists{/gist_id}","starred_url":"https://api.github.com/users/BlakeWilliams/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/BlakeWilliams/subscriptions","organizations_url":"https://api.github.com/users/BlakeWilliams/orgs","repos_url":"https://api.github.com/users/BlakeWilliams/repos","events_url":"https://api.github.com/users/BlakeWilliams/events{/privacy}","received_events_url":"https://api.github.com/users/BlakeWilliams/received_events","type":"User","site_admin":false},"body":"Thoughts on making `\"../../../../config/contents/` a constant at the top of the file?","created_at":"2015-09-30T18:21:38Z","updated_at":"2015-09-30T18:21:38Z","html_url":"https://github.com/codeclimate/codeclimate-rubocop/pull/23#discussion_r40830782","pull_request_url":"https://api.github.com/repos/codeclimate/codeclimate-rubocop/pulls/23","_links":{"self":{"href":"https://api.github.com/repos/codeclimate/codeclimate-rubocop/pulls/comments/40830782"},"html":{"href":"https://github.com/codeclimate/codeclimate-rubocop/pull/23#discussion_r40830782"},"pull_request":{"href":"https://api.github.com/repos/codeclimate/codeclimate-rubocop/pulls/23"}}},"pull_request":{"url":"https://api.github.com/repos/codeclimate/codeclimate-rubocop/pulls/23","id":46083218,"html_url":"https://github.com/codeclimate/codeclimate-rubocop/pull/23","diff_url":"https://github.com/codeclimate/codeclimate-rubocop/pull/23.diff","patch_url":"https://github.com/codeclimate/codeclimate-rubocop/pull/23.patch","issue_url":"https://api.github.com/repos/codeclimate/codeclimate-rubocop/issues/23","number":23,"state":"open","locked":false,"title":"Extract `ViolationHash` class","user":{"login":"andyw8","id":13400,"avatar_url":"https://avatars.githubusercontent.com/u/13400?v=3","gravatar_id":"","url":"https://api.github.com/users/andyw8","html_url":"https://github.com/andyw8","followers_url":"https://api.github.com/users/andyw8/followers","following_url":"https://api.github.com/users/andyw8/following{/other_user}","gists_url":"https://api.github.com/users/andyw8/gists{/gist_id}","starred_url":"https://api.github.com/users/andyw8/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/andyw8/subscriptions","organizations_url":"https://api.github.com/users/andyw8/orgs","repos_url":"https://api.github.com/users/andyw8/repos","events_url":"https://api.github.com/users/andyw8/events{/privacy}","received_events_url":"https://api.github.com/users/andyw8/received_events","type":"User","site_admin":false},"body":"I've been studying the RuboCop engine as I work on an engine for Reek.\r\n\r\nThere's a lot happening in `rubocop.rb`, with many mixed levels of\r\nabstraction. It seems that extracting out the responsibility of\r\nbuilding the violation hash would make things easier to understand and\r\nmaintain.\r\n\r\nI've not yet updated the tests to reflect the new structure. I'll await\r\nfeedback on this proposal first.","created_at":"2015-09-26T15:01:01Z","updated_at":"2015-09-30T18:21:38Z","closed_at":null,"merged_at":null,"merge_commit_sha":"a1ff881baa552c6f3eed3512707e0c5b1d2069d3","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/codeclimate/codeclimate-rubocop/pulls/23/commits","review_comments_url":"https://api.github.com/repos/codeclimate/codeclimate-rubocop/pulls/23/comments","review_comment_url":"https://api.github.com/repos/codeclimate/codeclimate-rubocop/pulls/comments{/number}","comments_url":"https://api.github.com/repos/codeclimate/codeclimate-rubocop/issues/23/comments","statuses_url":"https://api.github.com/repos/codeclimate/codeclimate-rubocop/statuses/5e0dd2a3fe5c53e32fad3ea7027b3106961930fe","head":{"label":"andyw8:extract-violation-hash-class","ref":"extract-violation-hash-class","sha":"5e0dd2a3fe5c53e32fad3ea7027b3106961930fe","user":{"login":"andyw8","id":13400,"avatar_url":"https://avatars.githubusercontent.com/u/13400?v=3","gravatar_id":"","url":"https://api.github.com/users/andyw8","html_url":"https://github.com/andyw8","followers_url":"https://api.github.com/users/andyw8/followers","following_url":"https://api.github.com/users/andyw8/following{/other_user}","gists_url":"https://api.github.com/users/andyw8/gists{/gist_id}","starred_url":"https://api.github.com/users/andyw8/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/andyw8/subscriptions","organizations_url":"https://api.github.com/users/andyw8/orgs","repos_url":"https://api.github.com/users/andyw8/repos","events_url":"https://api.github.com/users/andyw8/events{/privacy}","received_events_url":"https://api.github.com/users/andyw8/received_events","type":"User","site_admin":false},"repo":{"id":42893122,"name":"codeclimate-rubocop","full_name":"andyw8/codeclimate-rubocop","owner":{"login":"andyw8","id":13400,"avatar_url":"https://avatars.githubusercontent.com/u/13400?v=3","gravatar_id":"","url":"https://api.github.com/users/andyw8","html_url":"https://github.com/andyw8","followers_url":"https://api.github.com/users/andyw8/followers","following_url":"https://api.github.com/users/andyw8/following{/other_user}","gists_url":"https://api.github.com/users/andyw8/gists{/gist_id}","starred_url":"https://api.github.com/users/andyw8/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/andyw8/subscriptions","organizations_url":"https://api.github.com/users/andyw8/orgs","repos_url":"https://api.github.com/users/andyw8/repos","events_url":"https://api.github.com/users/andyw8/events{/privacy}","received_events_url":"https://api.github.com/users/andyw8/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/andyw8/codeclimate-rubocop","description":"Code Climate Engine for Rubocop ","fork":true,"url":"https://api.github.com/repos/andyw8/codeclimate-rubocop","forks_url":"https://api.github.com/repos/andyw8/codeclimate-rubocop/forks","keys_url":"https://api.github.com/repos/andyw8/codeclimate-rubocop/keys{/key_id}","collaborators_url":"https://api.github.com/repos/andyw8/codeclimate-rubocop/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/andyw8/codeclimate-rubocop/teams","hooks_url":"https://api.github.com/repos/andyw8/codeclimate-rubocop/hooks","issue_events_url":"https://api.github.com/repos/andyw8/codeclimate-rubocop/issues/events{/number}","events_url":"https://api.github.com/repos/andyw8/codeclimate-rubocop/events","assignees_url":"https://api.github.com/repos/andyw8/codeclimate-rubocop/assignees{/user}","branches_url":"https://api.github.com/repos/andyw8/codeclimate-rubocop/branches{/branch}","tags_url":"https://api.github.com/repos/andyw8/codeclimate-rubocop/tags","blobs_url":"https://api.github.com/repos/andyw8/codeclimate-rubocop/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/andyw8/codeclimate-rubocop/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/andyw8/codeclimate-rubocop/git/refs{/sha}","trees_url":"https://api.github.com/repos/andyw8/codeclimate-rubocop/git/trees{/sha}","statuses_url":"https://api.github.com/repos/andyw8/codeclimate-rubocop/statuses/{sha}","languages_url":"https://api.github.com/repos/andyw8/codeclimate-rubocop/languages","stargazers_url":"https://api.github.com/repos/andyw8/codeclimate-rubocop/stargazers","contributors_url":"https://api.github.com/repos/andyw8/codeclimate-rubocop/contributors","subscribers_url":"https://api.github.com/repos/andyw8/codeclimate-rubocop/subscribers","subscription_url":"https://api.github.com/repos/andyw8/codeclimate-rubocop/subscription","commits_url":"https://api.github.com/repos/andyw8/codeclimate-rubocop/commits{/sha}","git_commits_url":"https://api.github.com/repos/andyw8/codeclimate-rubocop/git/commits{/sha}","comments_url":"https://api.github.com/repos/andyw8/codeclimate-rubocop/comments{/number}","issue_comment_url":"https://api.github.com/repos/andyw8/codeclimate-rubocop/issues/comments{/number}","contents_url":"https://api.github.com/repos/andyw8/codeclimate-rubocop/contents/{+path}","compare_url":"https://api.github.com/repos/andyw8/codeclimate-rubocop/compare/{base}...{head}","merges_url":"https://api.github.com/repos/andyw8/codeclimate-rubocop/merges","archive_url":"https://api.github.com/repos/andyw8/codeclimate-rubocop/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/andyw8/codeclimate-rubocop/downloads","issues_url":"https://api.github.com/repos/andyw8/codeclimate-rubocop/issues{/number}","pulls_url":"https://api.github.com/repos/andyw8/codeclimate-rubocop/pulls{/number}","milestones_url":"https://api.github.com/repos/andyw8/codeclimate-rubocop/milestones{/number}","notifications_url":"https://api.github.com/repos/andyw8/codeclimate-rubocop/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/andyw8/codeclimate-rubocop/labels{/name}","releases_url":"https://api.github.com/repos/andyw8/codeclimate-rubocop/releases{/id}","created_at":"2015-09-21T20:53:35Z","updated_at":"2015-09-21T20:53:36Z","pushed_at":"2015-09-27T09:22:52Z","git_url":"git://github.com/andyw8/codeclimate-rubocop.git","ssh_url":"git@github.com:andyw8/codeclimate-rubocop.git","clone_url":"https://github.com/andyw8/codeclimate-rubocop.git","svn_url":"https://github.com/andyw8/codeclimate-rubocop","homepage":null,"size":1105,"stargazers_count":0,"watchers_count":0,"language":"Ruby","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"codeclimate:master","ref":"master","sha":"88552d76f375d44babaf36a366b137a60cd2f6a1","user":{"login":"codeclimate","id":789641,"avatar_url":"https://avatars.githubusercontent.com/u/789641?v=3","gravatar_id":"","url":"https://api.github.com/users/codeclimate","html_url":"https://github.com/codeclimate","followers_url":"https://api.github.com/users/codeclimate/followers","following_url":"https://api.github.com/users/codeclimate/following{/other_user}","gists_url":"https://api.github.com/users/codeclimate/gists{/gist_id}","starred_url":"https://api.github.com/users/codeclimate/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/codeclimate/subscriptions","organizations_url":"https://api.github.com/users/codeclimate/orgs","repos_url":"https://api.github.com/users/codeclimate/repos","events_url":"https://api.github.com/users/codeclimate/events{/privacy}","received_events_url":"https://api.github.com/users/codeclimate/received_events","type":"Organization","site_admin":false},"repo":{"id":37722820,"name":"codeclimate-rubocop","full_name":"codeclimate/codeclimate-rubocop","owner":{"login":"codeclimate","id":789641,"avatar_url":"https://avatars.githubusercontent.com/u/789641?v=3","gravatar_id":"","url":"https://api.github.com/users/codeclimate","html_url":"https://github.com/codeclimate","followers_url":"https://api.github.com/users/codeclimate/followers","following_url":"https://api.github.com/users/codeclimate/following{/other_user}","gists_url":"https://api.github.com/users/codeclimate/gists{/gist_id}","starred_url":"https://api.github.com/users/codeclimate/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/codeclimate/subscriptions","organizations_url":"https://api.github.com/users/codeclimate/orgs","repos_url":"https://api.github.com/users/codeclimate/repos","events_url":"https://api.github.com/users/codeclimate/events{/privacy}","received_events_url":"https://api.github.com/users/codeclimate/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/codeclimate/codeclimate-rubocop","description":"Code Climate Engine for Rubocop ","fork":false,"url":"https://api.github.com/repos/codeclimate/codeclimate-rubocop","forks_url":"https://api.github.com/repos/codeclimate/codeclimate-rubocop/forks","keys_url":"https://api.github.com/repos/codeclimate/codeclimate-rubocop/keys{/key_id}","collaborators_url":"https://api.github.com/repos/codeclimate/codeclimate-rubocop/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/codeclimate/codeclimate-rubocop/teams","hooks_url":"https://api.github.com/repos/codeclimate/codeclimate-rubocop/hooks","issue_events_url":"https://api.github.com/repos/codeclimate/codeclimate-rubocop/issues/events{/number}","events_url":"https://api.github.com/repos/codeclimate/codeclimate-rubocop/events","assignees_url":"https://api.github.com/repos/codeclimate/codeclimate-rubocop/assignees{/user}","branches_url":"https://api.github.com/repos/codeclimate/codeclimate-rubocop/branches{/branch}","tags_url":"https://api.github.com/repos/codeclimate/codeclimate-rubocop/tags","blobs_url":"https://api.github.com/repos/codeclimate/codeclimate-rubocop/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/codeclimate/codeclimate-rubocop/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/codeclimate/codeclimate-rubocop/git/refs{/sha}","trees_url":"https://api.github.com/repos/codeclimate/codeclimate-rubocop/git/trees{/sha}","statuses_url":"https://api.github.com/repos/codeclimate/codeclimate-rubocop/statuses/{sha}","languages_url":"https://api.github.com/repos/codeclimate/codeclimate-rubocop/languages","stargazers_url":"https://api.github.com/repos/codeclimate/codeclimate-rubocop/stargazers","contributors_url":"https://api.github.com/repos/codeclimate/codeclimate-rubocop/contributors","subscribers_url":"https://api.github.com/repos/codeclimate/codeclimate-rubocop/subscribers","subscription_url":"https://api.github.com/repos/codeclimate/codeclimate-rubocop/subscription","commits_url":"https://api.github.com/repos/codeclimate/codeclimate-rubocop/commits{/sha}","git_commits_url":"https://api.github.com/repos/codeclimate/codeclimate-rubocop/git/commits{/sha}","comments_url":"https://api.github.com/repos/codeclimate/codeclimate-rubocop/comments{/number}","issue_comment_url":"https://api.github.com/repos/codeclimate/codeclimate-rubocop/issues/comments{/number}","contents_url":"https://api.github.com/repos/codeclimate/codeclimate-rubocop/contents/{+path}","compare_url":"https://api.github.com/repos/codeclimate/codeclimate-rubocop/compare/{base}...{head}","merges_url":"https://api.github.com/repos/codeclimate/codeclimate-rubocop/merges","archive_url":"https://api.github.com/repos/codeclimate/codeclimate-rubocop/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/codeclimate/codeclimate-rubocop/downloads","issues_url":"https://api.github.com/repos/codeclimate/codeclimate-rubocop/issues{/number}","pulls_url":"https://api.github.com/repos/codeclimate/codeclimate-rubocop/pulls{/number}","milestones_url":"https://api.github.com/repos/codeclimate/codeclimate-rubocop/milestones{/number}","notifications_url":"https://api.github.com/repos/codeclimate/codeclimate-rubocop/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/codeclimate/codeclimate-rubocop/labels{/name}","releases_url":"https://api.github.com/repos/codeclimate/codeclimate-rubocop/releases{/id}","created_at":"2015-06-19T13:19:23Z","updated_at":"2015-09-28T07:26:05Z","pushed_at":"2015-09-30T18:10:27Z","git_url":"git://github.com/codeclimate/codeclimate-rubocop.git","ssh_url":"git@github.com:codeclimate/codeclimate-rubocop.git","clone_url":"https://github.com/codeclimate/codeclimate-rubocop.git","svn_url":"https://github.com/codeclimate/codeclimate-rubocop","homepage":null,"size":1513,"stargazers_count":8,"watchers_count":8,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":4,"mirror_url":null,"open_issues_count":4,"forks":4,"open_issues":4,"watchers":8,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/codeclimate/codeclimate-rubocop/pulls/23"},"html":{"href":"https://github.com/codeclimate/codeclimate-rubocop/pull/23"},"issue":{"href":"https://api.github.com/repos/codeclimate/codeclimate-rubocop/issues/23"},"comments":{"href":"https://api.github.com/repos/codeclimate/codeclimate-rubocop/issues/23/comments"},"review_comments":{"href":"https://api.github.com/repos/codeclimate/codeclimate-rubocop/pulls/23/comments"},"review_comment":{"href":"https://api.github.com/repos/codeclimate/codeclimate-rubocop/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/codeclimate/codeclimate-rubocop/pulls/23/commits"},"statuses":{"href":"https://api.github.com/repos/codeclimate/codeclimate-rubocop/statuses/5e0dd2a3fe5c53e32fad3ea7027b3106961930fe"}}}}