Commit 3f62178f authored by Sean McGivern's avatar Sean McGivern

Merge branch '238555-follow-up-from-add-codeowners-to-usage-data' into 'master'

Allow distinct_count cop by string

Closes #238555

See merge request gitlab-org/gitlab!40154
parents 129a9b5d 990d5388
......@@ -385,7 +385,6 @@ module EE
# rubocop:enable CodeReuse/ActiveRecord
# rubocop:disable CodeReuse/ActiveRecord
# rubocop: disable UsageData/DistinctCountByLargeForeignKey
def projects_with_sectional_code_owner_rules(time_period)
distinct_count(
::ApprovalMergeRequestRule
......@@ -398,7 +397,6 @@ module EE
finish: project_maximum_id
)
end
# rubocop: enable UsageData/DistinctCountByLargeForeignKey
# rubocop:enable CodeReuse/ActiveRecord
end
end
......
......@@ -31,7 +31,7 @@ module RuboCop
private
def allowed_foreign_key?(key)
key.type == :sym && allowed_foreign_keys.include?(key.value)
[:sym, :str].include?(key.type) && allowed_foreign_keys.include?(key.value.to_sym)
end
def allowed_foreign_keys
......
......@@ -44,3 +44,4 @@ UsageData/DistinctCountByLargeForeignKey:
- :project_id
- :issue_id
- :merge_request_id
- :merge_requests.target_project_id
......@@ -10,7 +10,7 @@ require_relative '../../../../rubocop/cop/usage_data/distinct_count_by_large_for
RSpec.describe RuboCop::Cop::UsageData::DistinctCountByLargeForeignKey, type: :rubocop do
include CopHelper
let(:allowed_foreign_keys) { %i[author_id user_id] }
let(:allowed_foreign_keys) { [:author_id, :user_id, :'merge_requests.target_project_id'] }
let(:config) do
RuboCop::Config.new('UsageData/DistinctCountByLargeForeignKey' => {
......@@ -29,10 +29,16 @@ RSpec.describe RuboCop::Cop::UsageData::DistinctCountByLargeForeignKey, type: :r
end
context 'when calling by allowed key' do
it 'does not register an offence' do
it 'does not register an offence with symbol' do
inspect_source('distinct_count(Issue, :author_id)')
expect(cop.offenses).to be_empty
end
it 'does not register an offence with string' do
inspect_source("distinct_count(Issue, 'merge_requests.target_project_id')")
expect(cop.offenses).to be_empty
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment