{"action":"created","comment":{"url":"https://api.github.com/repos/bbatsov/rubocop/pulls/comments/82161140","pull_request_review_id":3086774,"id":82161140,"diff_hunk":"@@ -0,0 +1,59 @@\n+# encoding: utf-8\n+# frozen_string_literal: true\n+\n+module RuboCop\n+  module Cop\n+    module Rails\n+      # This cop looks for delegations that pass :allow_blank as an option\n+      # instead of :allow_nil. :allow_blank is not a valid option to pass\n+      # to ActiveSupport's :delegate method.\n+      #\n+      # @example\n+      #   # bad\n+      #   delegate :foo, to: :bar, allow_blank: true\n+      #\n+      #   # good\n+      #   delegate :foo, to: :bar, allow_nil: true\n+      class DelegateAllowBlank < Cop\n+        MSG = '`allow_blank` is not a valid option, use `allow_nil`'.freeze\n+\n+        def_node_matcher :delegate, <<-PATTERN\n+          (send _ :delegate _ $hash)\n+        PATTERN\n+\n+        def_node_matcher :delegate_options, <<-PATTERN\n+          (hash $...)\n+        PATTERN\n+\n+        def_node_matcher :allow_blank?, <<-PATTERN\n+          (pair $(sym :allow_blank) true)\n+        PATTERN\n+\n+        def on_send(node)\n+          return unless (offending_node = allow_blank_option(node))\n+\n+          allow_blank = offending_node.children.first\n+          add_offense(node, allow_blank.source_range, MSG)\n+        end\n+\n+        def autocorrect(node)\n+          return unless (offending_node = allow_blank_option(node))","path":"lib/rubocop/cop/rails/delegate_allow_blank.rb","position":40,"original_position":40,"commit_id":"5a1c4ec5361ed4a3a6402dcae9818b063566b6b2","original_commit_id":"5a1c4ec5361ed4a3a6402dcae9818b063566b6b2","user":{"login":"bbatsov","id":103882,"avatar_url":"https://avatars.githubusercontent.com/u/103882?v=3","gravatar_id":"","url":"https://api.github.com/users/bbatsov","html_url":"https://github.com/bbatsov","followers_url":"https://api.github.com/users/bbatsov/followers","following_url":"https://api.github.com/users/bbatsov/following{/other_user}","gists_url":"https://api.github.com/users/bbatsov/gists{/gist_id}","starred_url":"https://api.github.com/users/bbatsov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bbatsov/subscriptions","organizations_url":"https://api.github.com/users/bbatsov/orgs","repos_url":"https://api.github.com/users/bbatsov/repos","events_url":"https://api.github.com/users/bbatsov/events{/privacy}","received_events_url":"https://api.github.com/users/bbatsov/received_events","type":"User","site_admin":false},"body":"Same here.","created_at":"2016-10-06T10:44:41Z","updated_at":"2016-10-06T10:44:41Z","html_url":"https://github.com/bbatsov/rubocop/pull/3434#discussion_r82161140","pull_request_url":"https://api.github.com/repos/bbatsov/rubocop/pulls/3434","_links":{"self":{"href":"https://api.github.com/repos/bbatsov/rubocop/pulls/comments/82161140"},"html":{"href":"https://github.com/bbatsov/rubocop/pull/3434#discussion_r82161140"},"pull_request":{"href":"https://api.github.com/repos/bbatsov/rubocop/pulls/3434"}}},"pull_request":{"url":"https://api.github.com/repos/bbatsov/rubocop/pulls/3434","id":82278736,"html_url":"https://github.com/bbatsov/rubocop/pull/3434","diff_url":"https://github.com/bbatsov/rubocop/pull/3434.diff","patch_url":"https://github.com/bbatsov/rubocop/pull/3434.patch","issue_url":"https://api.github.com/repos/bbatsov/rubocop/issues/3434","number":3434,"state":"open","locked":false,"title":"New cop Rails/DelegateAllowBlank","user":{"login":"connorjacobsen","id":1803137,"avatar_url":"https://avatars.githubusercontent.com/u/1803137?v=3","gravatar_id":"","url":"https://api.github.com/users/connorjacobsen","html_url":"https://github.com/connorjacobsen","followers_url":"https://api.github.com/users/connorjacobsen/followers","following_url":"https://api.github.com/users/connorjacobsen/following{/other_user}","gists_url":"https://api.github.com/users/connorjacobsen/gists{/gist_id}","starred_url":"https://api.github.com/users/connorjacobsen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/connorjacobsen/subscriptions","organizations_url":"https://api.github.com/users/connorjacobsen/orgs","repos_url":"https://api.github.com/users/connorjacobsen/repos","events_url":"https://api.github.com/users/connorjacobsen/events{/privacy}","received_events_url":"https://api.github.com/users/connorjacobsen/received_events","type":"User","site_admin":false},"body":"Adds a new cop to catch usage of `allow_blank` as an option to `ActiveSupport`'s `delegate` method. `allow_blank` is not a supported option and fails silently. The correct option is `allow_nil`. Other parts of Rails have `allow_blank` as an option, such as some validations.\r\n\r\nPlease let me know if there are more idiomatic ways to do this, especially using `def_node_matcher`.\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* [ ] Commit message starts with `[Fix #issue-number]` (if the related issue exists).\r\n* [x] Used the same coding conventions as the rest of the project.\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] All tests are passing.\r\n* [x] The new code doesn't generate RuboCop offenses.\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\r\n[1]: http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html\r\n\r\n","created_at":"2016-08-22T23:08:16Z","updated_at":"2016-10-06T10:44:41Z","closed_at":null,"merged_at":null,"merge_commit_sha":"27cf1f238a5688e289877b9312de56e1d16cb734","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/bbatsov/rubocop/pulls/3434/commits","review_comments_url":"https://api.github.com/repos/bbatsov/rubocop/pulls/3434/comments","review_comment_url":"https://api.github.com/repos/bbatsov/rubocop/pulls/comments{/number}","comments_url":"https://api.github.com/repos/bbatsov/rubocop/issues/3434/comments","statuses_url":"https://api.github.com/repos/bbatsov/rubocop/statuses/5a1c4ec5361ed4a3a6402dcae9818b063566b6b2","head":{"label":"connorjacobsen:activesupport-delegate-allow-blank","ref":"activesupport-delegate-allow-blank","sha":"5a1c4ec5361ed4a3a6402dcae9818b063566b6b2","user":{"login":"connorjacobsen","id":1803137,"avatar_url":"https://avatars.githubusercontent.com/u/1803137?v=3","gravatar_id":"","url":"https://api.github.com/users/connorjacobsen","html_url":"https://github.com/connorjacobsen","followers_url":"https://api.github.com/users/connorjacobsen/followers","following_url":"https://api.github.com/users/connorjacobsen/following{/other_user}","gists_url":"https://api.github.com/users/connorjacobsen/gists{/gist_id}","starred_url":"https://api.github.com/users/connorjacobsen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/connorjacobsen/subscriptions","organizations_url":"https://api.github.com/users/connorjacobsen/orgs","repos_url":"https://api.github.com/users/connorjacobsen/repos","events_url":"https://api.github.com/users/connorjacobsen/events{/privacy}","received_events_url":"https://api.github.com/users/connorjacobsen/received_events","type":"User","site_admin":false},"repo":{"id":64003621,"name":"rubocop","full_name":"connorjacobsen/rubocop","owner":{"login":"connorjacobsen","id":1803137,"avatar_url":"https://avatars.githubusercontent.com/u/1803137?v=3","gravatar_id":"","url":"https://api.github.com/users/connorjacobsen","html_url":"https://github.com/connorjacobsen","followers_url":"https://api.github.com/users/connorjacobsen/followers","following_url":"https://api.github.com/users/connorjacobsen/following{/other_user}","gists_url":"https://api.github.com/users/connorjacobsen/gists{/gist_id}","starred_url":"https://api.github.com/users/connorjacobsen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/connorjacobsen/subscriptions","organizations_url":"https://api.github.com/users/connorjacobsen/orgs","repos_url":"https://api.github.com/users/connorjacobsen/repos","events_url":"https://api.github.com/users/connorjacobsen/events{/privacy}","received_events_url":"https://api.github.com/users/connorjacobsen/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/connorjacobsen/rubocop","description":"A Ruby static code analyzer, based on the community Ruby style guide.","fork":true,"url":"https://api.github.com/repos/connorjacobsen/rubocop","forks_url":"https://api.github.com/repos/connorjacobsen/rubocop/forks","keys_url":"https://api.github.com/repos/connorjacobsen/rubocop/keys{/key_id}","collaborators_url":"https://api.github.com/repos/connorjacobsen/rubocop/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/connorjacobsen/rubocop/teams","hooks_url":"https://api.github.com/repos/connorjacobsen/rubocop/hooks","issue_events_url":"https://api.github.com/repos/connorjacobsen/rubocop/issues/events{/number}","events_url":"https://api.github.com/repos/connorjacobsen/rubocop/events","assignees_url":"https://api.github.com/repos/connorjacobsen/rubocop/assignees{/user}","branches_url":"https://api.github.com/repos/connorjacobsen/rubocop/branches{/branch}","tags_url":"https://api.github.com/repos/connorjacobsen/rubocop/tags","blobs_url":"https://api.github.com/repos/connorjacobsen/rubocop/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/connorjacobsen/rubocop/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/connorjacobsen/rubocop/git/refs{/sha}","trees_url":"https://api.github.com/repos/connorjacobsen/rubocop/git/trees{/sha}","statuses_url":"https://api.github.com/repos/connorjacobsen/rubocop/statuses/{sha}","languages_url":"https://api.github.com/repos/connorjacobsen/rubocop/languages","stargazers_url":"https://api.github.com/repos/connorjacobsen/rubocop/stargazers","contributors_url":"https://api.github.com/repos/connorjacobsen/rubocop/contributors","subscribers_url":"https://api.github.com/repos/connorjacobsen/rubocop/subscribers","subscription_url":"https://api.github.com/repos/connorjacobsen/rubocop/subscription","commits_url":"https://api.github.com/repos/connorjacobsen/rubocop/commits{/sha}","git_commits_url":"https://api.github.com/repos/connorjacobsen/rubocop/git/commits{/sha}","comments_url":"https://api.github.com/repos/connorjacobsen/rubocop/comments{/number}","issue_comment_url":"https://api.github.com/repos/connorjacobsen/rubocop/issues/comments{/number}","contents_url":"https://api.github.com/repos/connorjacobsen/rubocop/contents/{+path}","compare_url":"https://api.github.com/repos/connorjacobsen/rubocop/compare/{base}...{head}","merges_url":"https://api.github.com/repos/connorjacobsen/rubocop/merges","archive_url":"https://api.github.com/repos/connorjacobsen/rubocop/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/connorjacobsen/rubocop/downloads","issues_url":"https://api.github.com/repos/connorjacobsen/rubocop/issues{/number}","pulls_url":"https://api.github.com/repos/connorjacobsen/rubocop/pulls{/number}","milestones_url":"https://api.github.com/repos/connorjacobsen/rubocop/milestones{/number}","notifications_url":"https://api.github.com/repos/connorjacobsen/rubocop/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/connorjacobsen/rubocop/labels{/name}","releases_url":"https://api.github.com/repos/connorjacobsen/rubocop/releases{/id}","deployments_url":"https://api.github.com/repos/connorjacobsen/rubocop/deployments","created_at":"2016-07-23T06:56:30Z","updated_at":"2016-07-23T06:56:34Z","pushed_at":"2016-08-23T00:10:26Z","git_url":"git://github.com/connorjacobsen/rubocop.git","ssh_url":"git@github.com:connorjacobsen/rubocop.git","clone_url":"https://github.com/connorjacobsen/rubocop.git","svn_url":"https://github.com/connorjacobsen/rubocop","homepage":"http://rubocop.readthedocs.io","size":12734,"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":"bbatsov:master","ref":"master","sha":"df4e986436af3d249e1e4453045f6bf03c081d43","user":{"login":"bbatsov","id":103882,"avatar_url":"https://avatars.githubusercontent.com/u/103882?v=3","gravatar_id":"","url":"https://api.github.com/users/bbatsov","html_url":"https://github.com/bbatsov","followers_url":"https://api.github.com/users/bbatsov/followers","following_url":"https://api.github.com/users/bbatsov/following{/other_user}","gists_url":"https://api.github.com/users/bbatsov/gists{/gist_id}","starred_url":"https://api.github.com/users/bbatsov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bbatsov/subscriptions","organizations_url":"https://api.github.com/users/bbatsov/orgs","repos_url":"https://api.github.com/users/bbatsov/repos","events_url":"https://api.github.com/users/bbatsov/events{/privacy}","received_events_url":"https://api.github.com/users/bbatsov/received_events","type":"User","site_admin":false},"repo":{"id":4095287,"name":"rubocop","full_name":"bbatsov/rubocop","owner":{"login":"bbatsov","id":103882,"avatar_url":"https://avatars.githubusercontent.com/u/103882?v=3","gravatar_id":"","url":"https://api.github.com/users/bbatsov","html_url":"https://github.com/bbatsov","followers_url":"https://api.github.com/users/bbatsov/followers","following_url":"https://api.github.com/users/bbatsov/following{/other_user}","gists_url":"https://api.github.com/users/bbatsov/gists{/gist_id}","starred_url":"https://api.github.com/users/bbatsov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bbatsov/subscriptions","organizations_url":"https://api.github.com/users/bbatsov/orgs","repos_url":"https://api.github.com/users/bbatsov/repos","events_url":"https://api.github.com/users/bbatsov/events{/privacy}","received_events_url":"https://api.github.com/users/bbatsov/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/bbatsov/rubocop","description":"A Ruby static code analyzer, based on the community Ruby style guide.","fork":false,"url":"https://api.github.com/repos/bbatsov/rubocop","forks_url":"https://api.github.com/repos/bbatsov/rubocop/forks","keys_url":"https://api.github.com/repos/bbatsov/rubocop/keys{/key_id}","collaborators_url":"https://api.github.com/repos/bbatsov/rubocop/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/bbatsov/rubocop/teams","hooks_url":"https://api.github.com/repos/bbatsov/rubocop/hooks","issue_events_url":"https://api.github.com/repos/bbatsov/rubocop/issues/events{/number}","events_url":"https://api.github.com/repos/bbatsov/rubocop/events","assignees_url":"https://api.github.com/repos/bbatsov/rubocop/assignees{/user}","branches_url":"https://api.github.com/repos/bbatsov/rubocop/branches{/branch}","tags_url":"https://api.github.com/repos/bbatsov/rubocop/tags","blobs_url":"https://api.github.com/repos/bbatsov/rubocop/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/bbatsov/rubocop/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/bbatsov/rubocop/git/refs{/sha}","trees_url":"https://api.github.com/repos/bbatsov/rubocop/git/trees{/sha}","statuses_url":"https://api.github.com/repos/bbatsov/rubocop/statuses/{sha}","languages_url":"https://api.github.com/repos/bbatsov/rubocop/languages","stargazers_url":"https://api.github.com/repos/bbatsov/rubocop/stargazers","contributors_url":"https://api.github.com/repos/bbatsov/rubocop/contributors","subscribers_url":"https://api.github.com/repos/bbatsov/rubocop/subscribers","subscription_url":"https://api.github.com/repos/bbatsov/rubocop/subscription","commits_url":"https://api.github.com/repos/bbatsov/rubocop/commits{/sha}","git_commits_url":"https://api.github.com/repos/bbatsov/rubocop/git/commits{/sha}","comments_url":"https://api.github.com/repos/bbatsov/rubocop/comments{/number}","issue_comment_url":"https://api.github.com/repos/bbatsov/rubocop/issues/comments{/number}","contents_url":"https://api.github.com/repos/bbatsov/rubocop/contents/{+path}","compare_url":"https://api.github.com/repos/bbatsov/rubocop/compare/{base}...{head}","merges_url":"https://api.github.com/repos/bbatsov/rubocop/merges","archive_url":"https://api.github.com/repos/bbatsov/rubocop/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/bbatsov/rubocop/downloads","issues_url":"https://api.github.com/repos/bbatsov/rubocop/issues{/number}","pulls_url":"https://api.github.com/repos/bbatsov/rubocop/pulls{/number}","milestones_url":"https://api.github.com/repos/bbatsov/rubocop/milestones{/number}","notifications_url":"https://api.github.com/repos/bbatsov/rubocop/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/bbatsov/rubocop/labels{/name}","releases_url":"https://api.github.com/repos/bbatsov/rubocop/releases{/id}","deployments_url":"https://api.github.com/repos/bbatsov/rubocop/deployments","created_at":"2012-04-21T10:09:58Z","updated_at":"2016-10-06T01:28:21Z","pushed_at":"2016-10-06T05:59:07Z","git_url":"git://github.com/bbatsov/rubocop.git","ssh_url":"git@github.com:bbatsov/rubocop.git","clone_url":"https://github.com/bbatsov/rubocop.git","svn_url":"https://github.com/bbatsov/rubocop","homepage":"http://rubocop.readthedocs.io","size":17373,"stargazers_count":6827,"watchers_count":6827,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":1006,"mirror_url":null,"open_issues_count":137,"forks":1006,"open_issues":137,"watchers":6827,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/bbatsov/rubocop/pulls/3434"},"html":{"href":"https://github.com/bbatsov/rubocop/pull/3434"},"issue":{"href":"https://api.github.com/repos/bbatsov/rubocop/issues/3434"},"comments":{"href":"https://api.github.com/repos/bbatsov/rubocop/issues/3434/comments"},"review_comments":{"href":"https://api.github.com/repos/bbatsov/rubocop/pulls/3434/comments"},"review_comment":{"href":"https://api.github.com/repos/bbatsov/rubocop/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/bbatsov/rubocop/pulls/3434/commits"},"statuses":{"href":"https://api.github.com/repos/bbatsov/rubocop/statuses/5a1c4ec5361ed4a3a6402dcae9818b063566b6b2"}}}}
{"actor":{"display_login":"bbatsov"}}