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: incorrectly thinks the return value of save is discarded #1153

Open
akimd opened this issue Oct 12, 2023 · 0 comments
Open

Comments

@akimd
Copy link

akimd commented Oct 12, 2023

Hi again!

Expected behavior

In the following sample, the return value of save is checked. Or, more exactly, it is not discarded. So there should be no warnings about it.

$ cat save.rb
res = true
res &&= foo.save
res &&= bar.save
res

Actual behavior

$ bundle exec rubocop save.rb
Inspecting 1 file
C

Offenses:

save.rb:1:1: C: [Correctable] Style/FrozenStringLiteralComment: Missing frozen string literal comment.
res = true
^
save.rb:2:13: C: [Correctable] Rails/SaveBang: Use save! instead of save if the return value is not checked.
res &&= foo.save
            ^^^^
save.rb:3:13: C: [Correctable] Rails/SaveBang: Use save! instead of save if the return value is not checked.
res &&= bar.save
            ^^^^

1 file inspected, 3 offenses detected, 3 offenses autocorrectable

Steps to reproduce the problem

See above.

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-rails 2.21.2
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

No branches or pull requests

1 participant