{"action":"created","issue":{"url":"https://api.github.com/repos/bbatsov/rubocop/issues/3371","repository_url":"https://api.github.com/repos/bbatsov/rubocop","labels_url":"https://api.github.com/repos/bbatsov/rubocop/issues/3371/labels{/name}","comments_url":"https://api.github.com/repos/bbatsov/rubocop/issues/3371/comments","events_url":"https://api.github.com/repos/bbatsov/rubocop/issues/3371/events","html_url":"https://github.com/bbatsov/rubocop/issues/3371","id":169621614,"number":3371,"title":"Style/NumericPredicate unsafe auto-correct","user":{"login":"madwort","id":2082895,"avatar_url":"https://avatars.githubusercontent.com/u/2082895?v=3","gravatar_id":"","url":"https://api.github.com/users/madwort","html_url":"https://github.com/madwort","followers_url":"https://api.github.com/users/madwort/followers","following_url":"https://api.github.com/users/madwort/following{/other_user}","gists_url":"https://api.github.com/users/madwort/gists{/gist_id}","starred_url":"https://api.github.com/users/madwort/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/madwort/subscriptions","organizations_url":"https://api.github.com/users/madwort/orgs","repos_url":"https://api.github.com/users/madwort/repos","events_url":"https://api.github.com/users/madwort/events{/privacy}","received_events_url":"https://api.github.com/users/madwort/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":12,"created_at":"2016-08-05T14:36:40Z","updated_at":"2016-08-13T05:41:05Z","closed_at":null,"body":"## Expected behavior\r\n\r\nThis is a trivial example, but we have some code with an effect like this:\r\n\r\n```\r\nmy_var_may_be_nil =\r\n  if something_is_true\r\n    1\r\n  else\r\n    nil\r\n  end\r\n\r\nmy_var_may_be_nil == 0\r\n```\r\n\r\nIn the event that `my_var_may_be_nil` is `nil`, the result of the last statement is false.\r\n\r\n## Actual behavior\r\n\r\nThis cop auto-corrects our code to:\r\n\r\n```\r\nmy_var_may_be_nil =\r\n  if something_is_true\r\n    1\r\n  else\r\n    nil\r\n  end\r\n\r\nmy_var_may_be_nil.zero?\r\n```\r\n\r\nIn the event that `my_var_may_be_nil` is `nil`, the result of the last statement is failure: \r\n```\r\nNoMethodError: undefined method `zero?' for nil:NilClass\r\n\tfrom (irb):1\r\n\tfrom /opt/rbenv/versions/2.2.2/bin/irb:11:in `<main>'\r\n```\r\n\r\nIMHO default configuration auto-correct would preferably not introduce semantic changes like this. \r\n\r\n## RuboCop version\r\n\r\n```\r\n$ rubocop -V\r\n0.42.0 (using Parser 2.3.1.2, running on ruby 2.2.2 x86_64-linux)\r\n```\r\n"},"comment":{"url":"https://api.github.com/repos/bbatsov/rubocop/issues/comments/239603902","html_url":"https://github.com/bbatsov/rubocop/issues/3371#issuecomment-239603902","issue_url":"https://api.github.com/repos/bbatsov/rubocop/issues/3371","id":239603902,"user":{"login":"Drenmi","id":5259935,"avatar_url":"https://avatars.githubusercontent.com/u/5259935?v=3","gravatar_id":"","url":"https://api.github.com/users/Drenmi","html_url":"https://github.com/Drenmi","followers_url":"https://api.github.com/users/Drenmi/followers","following_url":"https://api.github.com/users/Drenmi/following{/other_user}","gists_url":"https://api.github.com/users/Drenmi/gists{/gist_id}","starred_url":"https://api.github.com/users/Drenmi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Drenmi/subscriptions","organizations_url":"https://api.github.com/users/Drenmi/orgs","repos_url":"https://api.github.com/users/Drenmi/repos","events_url":"https://api.github.com/users/Drenmi/events{/privacy}","received_events_url":"https://api.github.com/users/Drenmi/received_events","type":"User","site_admin":false},"created_at":"2016-08-13T05:41:05Z","updated_at":"2016-08-13T05:41:05Z","body":"> It turns out that \"Time\" and \"Datetime\" do not support \".zero?\" and \".nonzero?\" and we failed.\r\n\r\nA good question to ask first is \"why are we comparing a `Time` to a number?\", since it is essentially the same as using `if false`. 😀 '\r\n\r\nConsidering the number of issues this caused in the wild, I will submit a PR to make the auto-correct disabled by default. 😀 "}}
{"actor":{"display_login":"Drenmi"}}