Skip to content

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

Closed
@jas14

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)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions