From 0909f0ebe5df723b26f057243ade4e046957a512 Mon Sep 17 00:00:00 2001 From: Earlopain <14981592+Earlopain@users.noreply.github.com> Date: Sat, 24 Aug 2024 12:06:10 +0200 Subject: [PATCH] Remove RuboCop < 1.52 compatibility code The minimum required version right now is >= 1.52 --- lib/rubocop/cop/rails/action_order.rb | 6 +--- .../rails/active_record_callbacks_order.rb | 6 +--- .../redundant_active_record_all_method.rb | 29 ------------------- 3 files changed, 2 insertions(+), 39 deletions(-) diff --git a/lib/rubocop/cop/rails/action_order.rb b/lib/rubocop/cop/rails/action_order.rb index a2bcd3b462..954c1ae2fd 100644 --- a/lib/rubocop/cop/rails/action_order.rb +++ b/lib/rubocop/cop/rails/action_order.rb @@ -92,11 +92,7 @@ def add_range(range1, range2) end def range_with_comments(node) - # rubocop:todo InternalAffairs/LocationExpression - # Using `RuboCop::Ext::Comment#source_range` requires RuboCop > 1.46, - # which introduces https://github.com/rubocop/rubocop/pull/11630. - ranges = [node, *processed_source.ast_with_comments[node]].map { |comment| comment.loc.expression } - # rubocop:enable InternalAffairs/LocationExpression + ranges = [node, *processed_source.ast_with_comments[node]].map(&:source_range) ranges.reduce do |result, range| add_range(result, range) end diff --git a/lib/rubocop/cop/rails/active_record_callbacks_order.rb b/lib/rubocop/cop/rails/active_record_callbacks_order.rb index 8742e76338..cb544234f6 100644 --- a/lib/rubocop/cop/rails/active_record_callbacks_order.rb +++ b/lib/rubocop/cop/rails/active_record_callbacks_order.rb @@ -123,11 +123,7 @@ def begin_pos_with_comment(node) end def inline_comment?(comment) - # rubocop:todo InternalAffairs/LocationExpression - # Using `RuboCop::Ext::Comment#source_range` requires RuboCop > 1.46, - # which introduces https://github.com/rubocop/rubocop/pull/11630. - !comment_line?(comment.loc.expression.source_line) - # rubocop:enable InternalAffairs/LocationExpression + !comment_line?(comment.source_range.source_line) end def start_line_position(node) diff --git a/lib/rubocop/cop/rails/redundant_active_record_all_method.rb b/lib/rubocop/cop/rails/redundant_active_record_all_method.rb index ee5fa6afd6..252e890875 100644 --- a/lib/rubocop/cop/rails/redundant_active_record_all_method.rb +++ b/lib/rubocop/cop/rails/redundant_active_record_all_method.rb @@ -3,35 +3,6 @@ module RuboCop module Cop module Rails - # 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 - # Detect redundant `all` used as a receiver for Active Record query methods. # # For the methods `delete_all` and `destroy_all`, this cop will only check cases where the receiver is a model.