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: parens are enough to fool it #1160

Closed
akimd opened this issue Oct 18, 2023 · 1 comment · Fixed by #1165
Closed

Rails/SaveBang: parens are enough to fool it #1160

akimd opened this issue Oct 18, 2023 · 1 comment · Fixed by #1165
Labels
bug Something isn't working

Comments

@akimd
Copy link

akimd commented Oct 18, 2023

Hi guys!

Expected behavior

Here, save's return value is checked, there should not be complains about it.

$ cat /tmp/save.rb
  def foo
    @user = User.find(params[:id])
    if(@user.save)
      puts 'ok'
    else
      puts 'ko'
    end
  end

Actual behavior

$ bundle exec rubocop --only Rails/SaveBang /tmp/save.rb
Inspecting 1 file
Offenses:

/tmp/save.rb:3:14: C: [Correctable] Rails/SaveBang: Use save! instead of save if the return value is not checked.
    if(@user.save)
             ^^^^

1 file inspected, 1 offense detected, 1 offense autocorrectable

Steps to reproduce the problem

The problem is the parens. I wholeheartedly agree that they are not just superfluous, they are undesirable. Yet this piece of code is valid, and the parens should be ignored.

RuboCop version

$ bundle exec rubocop -V
1.56.3 (using Parser 3.2.2.3, rubocop-ast 1.29.0, running on ruby 3.2.2) [arm64-darwin22]
  - rubocop-performance 1.19.1
  - rubocop-rails 2.21.2
  - rubocop-thread_safety 0.5.1
@koic koic added the bug Something isn't working label Oct 19, 2023
@akimd
Copy link
Author

akimd commented Oct 23, 2023

Thanks a lot for this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants