Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rails cop idea: use bang methods when not checking return result #3128

Closed
mockdeep opened this issue May 11, 2016 · 0 comments
Closed

Rails cop idea: use bang methods when not checking return result #3128

mockdeep opened this issue May 11, 2016 · 0 comments

Comments

@mockdeep
Copy link
Contributor

We generally prefer to have things fail loud when we're not checking the return result, so it would be great to have a rubocop rule to enforce this strategy:

# bad
user.update(email: 'not an email') # silently fails

# good
user.update!(email: 'not an email') # => validation error

# good
if user.update(email: 'not an email')
  ...
else
  ...
end

Same with save!, create!, and other AR methods.

QuinnHarris added a commit to QuinnHarris/rubocop that referenced this issue Jul 19, 2016
Neodelf pushed a commit to Neodelf/rubocop that referenced this issue Oct 15, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant