From f935a0b8a1ddbc8e651e689293609dce39ada5d3 Mon Sep 17 00:00:00 2001 From: Koichi ITO Date: Wed, 18 Sep 2024 01:10:42 +0900 Subject: [PATCH] Suppress new RuboCop offenses Follow up https://github.com/rubocop/rubocop/pull/13242 This commit removes the following redundant `source_range` to suppress new RuboCop offenses: ```console $ bundle exec rake (snip) Offenses: lib/rubocop/cop/rails/redundant_foreign_key.rb:43:44: C: [Corrected] InternalAffairs/RedundantSourceRange: Remove the redundant source_range. add_offense(foreign_key_pair.source_range) do |corrector| ^^^^^^^^^^^^ lib/rubocop/cop/rails/redundant_receiver_in_with_options.rb:81:34: C: [Corrected] InternalAffairs/RedundantSourceRange: Remove the redundant source_range. add_offense(receiver.source_range) do |corrector| ^^^^^^^^^^^^ lib/rubocop/cop/rails/reflection_class_name.rb:46:47: C: [Corrected] InternalAffairs/RedundantSourceRange: Remove the redundant source_range. add_offense(reflection_class_name.source_range) do |corrector| ^^^^^^^^^^^^ lib/rubocop/cop/rails/request_referer.rb:37:30: C: [Corrected] InternalAffairs/RedundantSourceRange: Remove the redundant source_range. add_offense(node.source_range) do |corrector| ^^^^^^^^^^^^ 296 files inspected, 4 offenses detected, 4 offenses corrected ``` --- lib/rubocop/cop/rails/redundant_foreign_key.rb | 2 +- lib/rubocop/cop/rails/redundant_receiver_in_with_options.rb | 2 +- lib/rubocop/cop/rails/reflection_class_name.rb | 2 +- lib/rubocop/cop/rails/request_referer.rb | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/rubocop/cop/rails/redundant_foreign_key.rb b/lib/rubocop/cop/rails/redundant_foreign_key.rb index 3026fca294..f1f1e336fb 100644 --- a/lib/rubocop/cop/rails/redundant_foreign_key.rb +++ b/lib/rubocop/cop/rails/redundant_foreign_key.rb @@ -40,7 +40,7 @@ class RedundantForeignKey < Base def on_send(node) association_with_foreign_key(node) do |type, name, options, foreign_key_pair, foreign_key| if redundant?(node, type, name, options, foreign_key) - add_offense(foreign_key_pair.source_range) do |corrector| + add_offense(foreign_key_pair) do |corrector| range = range_with_surrounding_space(foreign_key_pair.source_range, side: :left) range = range_with_surrounding_comma(range, :left) diff --git a/lib/rubocop/cop/rails/redundant_receiver_in_with_options.rb b/lib/rubocop/cop/rails/redundant_receiver_in_with_options.rb index 62d52786cf..05df3c8675 100644 --- a/lib/rubocop/cop/rails/redundant_receiver_in_with_options.rb +++ b/lib/rubocop/cop/rails/redundant_receiver_in_with_options.rb @@ -78,7 +78,7 @@ def on_block(node) send_nodes.each do |send_node| receiver = send_node.receiver - add_offense(receiver.source_range) do |corrector| + add_offense(receiver) do |corrector| autocorrect(corrector, send_node, node) end end diff --git a/lib/rubocop/cop/rails/reflection_class_name.rb b/lib/rubocop/cop/rails/reflection_class_name.rb index d0afa1acb6..8393956b83 100644 --- a/lib/rubocop/cop/rails/reflection_class_name.rb +++ b/lib/rubocop/cop/rails/reflection_class_name.rb @@ -43,7 +43,7 @@ def on_send(node) return if reflection_class_name.value.send_type? && reflection_class_name.value.receiver.nil? return if reflection_class_name.value.lvar_type? && str_assigned?(reflection_class_name) - add_offense(reflection_class_name.source_range) do |corrector| + add_offense(reflection_class_name) do |corrector| autocorrect(corrector, reflection_class_name) end end diff --git a/lib/rubocop/cop/rails/request_referer.rb b/lib/rubocop/cop/rails/request_referer.rb index 38a68d8099..980064b884 100644 --- a/lib/rubocop/cop/rails/request_referer.rb +++ b/lib/rubocop/cop/rails/request_referer.rb @@ -34,7 +34,7 @@ def on_send(node) referer?(node) do return unless node.method?(wrong_method_name) - add_offense(node.source_range) do |corrector| + add_offense(node) do |corrector| corrector.replace(node, "request.#{style}") end end