diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-09-18 12:09:32 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-09-18 12:09:32 +0300 |
commit | a8b87b4fe0ebd38c0f1d7789ae768a6bcacb6c51 (patch) | |
tree | c1526cfec8ac3d9189188e08265ef1110419f643 /rubocop/cop | |
parent | 0115b63f646be489bb9685dad0e4b0747a79de05 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'rubocop/cop')
-rw-r--r-- | rubocop/cop/usage_data/distinct_count_by_large_foreign_key.rb | 16 |
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 |