Skip to content

Commit

Permalink
Merge pull request #1167 from koic/fix_an_error_for_rails_redundant_a…
Browse files Browse the repository at this point in the history
…ctive_record_all_method

[Fix #1143] Fix an error for `Rails/RedundantActiveRecordAllMethod`
  • Loading branch information
koic authored Oct 27, 2023
2 parents edeaa45 + 89c2135 commit d5842ef
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* [#1143](https://github.com/rubocop/rubocop-rails/issues/1143): Fix an error for `Rails/RedundantActiveRecordAllMethod` when using RuboCop 1.51 or lower. ([@koic][])
29 changes: 29 additions & 0 deletions lib/rubocop/cop/rails/redundant_active_record_all_method.rb
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,35 @@ def possible_enumerable_block_method?(node)
def offense_range(node)
range_between(node.loc.selector.begin_pos, node.source_range.end_pos)
end

# TODO: In the future, please support only RuboCop 1.52+ and use `RuboCop::Cop::AllowedReceivers`:
# https://github.com/rubocop/rubocop/blob/v1.52.0/lib/rubocop/cop/mixin/allowed_receivers.rb
# At that time, this duplicated module implementation can be removed.
module AllowedReceivers
def allowed_receiver?(receiver)
receiver_name = receiver_name(receiver)

allowed_receivers.include?(receiver_name)
end

def receiver_name(receiver)
return receiver_name(receiver.receiver) if receiver.receiver && !receiver.receiver.const_type?

if receiver.send_type?
if receiver.receiver
"#{receiver_name(receiver.receiver)}.#{receiver.method_name}"
else
receiver.method_name.to_s
end
else
receiver.source
end
end

def allowed_receivers
cop_config.fetch('AllowedReceivers', [])
end
end
end
end
end
Expand Down

0 comments on commit d5842ef

Please sign in to comment.