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/SaveBang "use create! instead of create" false positive #190

Closed
jas14 opened this issue Jan 22, 2020 · 0 comments · Fixed by #191
Closed

Rails/SaveBang "use create! instead of create" false positive #190

jas14 opened this issue Jan 22, 2020 · 0 comments · Fixed by #191

Comments

@jas14
Copy link
Contributor

jas14 commented Jan 22, 2020

The Rails/SaveBang cop has a false positive when the return value of a create call is checked immediately (i.e. without assignment to a variable).


Expected behavior

I expect the cop to not fire when the return value is checked immediately.

Actual behavior

The cope fires when the return value is checked immediately:

app/test.rb:4:15: C: Rails/SaveBang: Use create! instead of create if the return value is not checked.
  return if X.create.persisted?
              ^^^^^^

Steps to reproduce the problem

Enable the Rails/SaveBang cop and run on the following small repro case:

def savebang
  return if X.create.persisted?
  # ... other code
end

RuboCop version

$ bundle exec rubocop -V
0.79.0 (using Parser 2.7.0.2, running on ruby 2.6.5 x86_64-darwin18)
jas14 added a commit to jas14/rubocop-rails that referenced this issue Jan 22, 2020
…mmediately

Fixes rubocop#190.

Rails/SaveBang had a false positive when the return value of a `create`
call was checked directly with a call to `persisted?`.
jas14 added a commit to jas14/rubocop-rails that referenced this issue Jan 22, 2020
…mmediately

Fixes rubocop#190.

Rails/SaveBang had a false positive when the return value of a `create`
call was checked directly with a call to `persisted?`.
jas14 added a commit to jas14/rubocop-rails that referenced this issue Jan 24, 2020
…mmediately

Fixes rubocop#190.

Rails/SaveBang had a false positive when the return value of a `create`
call was checked directly with a call to `persisted?`.
@koic koic closed this as completed in #191 Jan 24, 2020
koic added a commit that referenced this issue Jan 24, 2020
[Fix #190] Fix `Rails/SaveBang` when return value is checked immediately
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

Successfully merging a pull request may close this issue.

1 participant