Closed
Description
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)
Metadata
Metadata
Assignees
Labels
No labels
Activity