Closed
Description
Expected behavior
I expect the following code to be allowed by rubocop, because the value of the create
method is (possibly) returned by the function, and AllowImplicitReturn
is true by default.
def find_or_create(**opts)
find(**opts) || create(**opts)
end
Actual behavior
The Rails/SaveBang cop reports that I should use create!
instead of create
.
my_model.rb:3:21: C: Rails/SaveBang: create returns a model which is always truthy.
find(**opts) || create(**opts)
^^^^^^
Steps to reproduce the problem
Assuming you have Rails cops enabled. Save the following file and run rubocop filename.rb
.
class MyModel < ActiveRecord::Model
def find_or_create(**opts)
find(**opts) || create(**opts)
end
end
RuboCop version
0.68.1 (using Parser 2.6.3.0, running on ruby 2.6.1 x86_64-linux)
Activity