flyerhzm / rails_best_practices

a code metric tool for rails projects
http://rails-bestpractices.com
MIT License
4.16k stars 276 forks source link

False positives on "check 'save' return value" #400

Open hakanai opened 1 year ago

hakanai commented 1 year ago

We're getting a couple false positives on checking the return value from 'save' where we clearly are checking it.

  1. The case where the result is assigned to something, and then checked later:
saved =
  begin
    @thing.save
  rescue SomeOtherError => e
    ...
  end

if saved
  ...
end
  1. The case where the result is checked via an aggregate of some sort:
# any? { ... } may also trigger it but haven't tested, I'm just including it the way I found it in our code,
if @things.map { |thing| !thing.save }.any?
  ...
end