summaryrefslogtreecommitdiff
path: root/rubocop/cop/usage_data/distinct_count_by_large_foreign_key.rb
diff options
context:
space:
mode:
Diffstat (limited to 'rubocop/cop/usage_data/distinct_count_by_large_foreign_key.rb')
-rw-r--r--rubocop/cop/usage_data/distinct_count_by_large_foreign_key.rb16
1 files changed, 16 insertions, 0 deletions
diff --git a/rubocop/cop/usage_data/distinct_count_by_large_foreign_key.rb b/rubocop/cop/usage_data/distinct_count_by_large_foreign_key.rb
index 36bcda527e8..9fdf52dac8b 100644
--- a/rubocop/cop/usage_data/distinct_count_by_large_foreign_key.rb
+++ b/rubocop/cop/usage_data/distinct_count_by_large_foreign_key.rb
@@ -22,6 +22,7 @@ module RuboCop
def on_send(node)
distinct_count?(node) do |method_name, method_arguments|
next unless method_arguments && method_arguments.length >= 2
+ next if batch_set_to_false?(method_arguments[2])
next if allowed_foreign_key?(method_arguments[1])
add_offense(node, location: :selector, message: format(MSG, method_name))
@@ -37,6 +38,21 @@ module RuboCop
def allowed_foreign_keys
(cop_config['AllowedForeignKeys'] || []).map(&:to_s)
end
+
+ def batch_set_to_false?(options)
+ return false unless options.is_a?(RuboCop::AST::HashNode)
+
+ batch_set_to_false = false
+ options.each_pair do |key, value|
+ next unless value.boolean_type? && value.falsey_literal?
+ next unless key.type == :sym && key.value == :batch
+
+ batch_set_to_false = true
+ break
+ end
+
+ batch_set_to_false
+ end
end
end
end