{"action":"created","issue":{"url":"https://api.github.com/repos/bbatsov/rubocop/issues/2531","labels_url":"https://api.github.com/repos/bbatsov/rubocop/issues/2531/labels{/name}","comments_url":"https://api.github.com/repos/bbatsov/rubocop/issues/2531/comments","events_url":"https://api.github.com/repos/bbatsov/rubocop/issues/2531/events","html_url":"https://github.com/bbatsov/rubocop/issues/2531","id":123537833,"number":2531,"title":"Style/AndOr suggests replacing \"and\" with \"&&\", and doesn't autocorrect, in places where \"and\" and \"&&\" have different semantics","user":{"login":"dmolesUC3","id":10374934,"avatar_url":"https://avatars.githubusercontent.com/u/10374934?v=3","gravatar_id":"","url":"https://api.github.com/users/dmolesUC3","html_url":"https://github.com/dmolesUC3","followers_url":"https://api.github.com/users/dmolesUC3/followers","following_url":"https://api.github.com/users/dmolesUC3/following{/other_user}","gists_url":"https://api.github.com/users/dmolesUC3/gists{/gist_id}","starred_url":"https://api.github.com/users/dmolesUC3/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dmolesUC3/subscriptions","organizations_url":"https://api.github.com/users/dmolesUC3/orgs","repos_url":"https://api.github.com/users/dmolesUC3/repos","events_url":"https://api.github.com/users/dmolesUC3/events{/privacy}","received_events_url":"https://api.github.com/users/dmolesUC3/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":5,"created_at":"2015-12-22T19:00:21Z","updated_at":"2015-12-23T09:26:46Z","closed_at":null,"body":"Consider the following:\r\n\r\n```ruby\r\n@h = { a: {b: 'c'} } \r\n\r\ndef find_value_1(k1, k2)\r\n  h1 = @h[k1] and h1[k2]\r\nend\r\n\r\ndef find_value_2(k1, k2)\r\n  h1 = @h[k1] && h1[k2]\r\nend\r\n\r\nfind_value_1(:a, :b)\r\n# => \"c\"\r\n\r\nfind_value_2(:a, :b)\r\n# NoMethodError: undefined method `[]' for nil:NilClass\r\n#   from (irb):8:in `find_value_2'\r\n#   from (irb):13\r\n```\r\n\r\nRubocop suggests “Use **&&** instead of **and**” for methods like `find_value_1`. (To its credit, it doesn't autocorrect with `-a`, though.)\r\n\r\nI understand that the style guide bans use of `and` for any purpose, but in that case it seems like Rubocop should suggest a different idiom (and/or warn about parentheses / precedence) here, rather than a substitution that will fail."},"comment":{"url":"https://api.github.com/repos/bbatsov/rubocop/issues/comments/166842889","html_url":"https://github.com/bbatsov/rubocop/issues/2531#issuecomment-166842889","issue_url":"https://api.github.com/repos/bbatsov/rubocop/issues/2531","id":166842889,"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},"created_at":"2015-12-23T09:26:46Z","updated_at":"2015-12-23T09:26:46Z","body":"@dmolesUC3 what's your RuboCop version btw?"}}