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 ...@@ -385,7 +385,6 @@ module EE
# rubocop:enable CodeReuse/ActiveRecord # rubocop:enable CodeReuse/ActiveRecord
# rubocop:disable CodeReuse/ActiveRecord # rubocop:disable CodeReuse/ActiveRecord
# rubocop: disable UsageData/DistinctCountByLargeForeignKey
def projects_with_sectional_code_owner_rules(time_period) def projects_with_sectional_code_owner_rules(time_period)
distinct_count( distinct_count(
::ApprovalMergeRequestRule ::ApprovalMergeRequestRule
...@@ -398,7 +397,6 @@ module EE ...@@ -398,7 +397,6 @@ module EE
finish: project_maximum_id finish: project_maximum_id
) )
end end
# rubocop: enable UsageData/DistinctCountByLargeForeignKey
# rubocop:enable CodeReuse/ActiveRecord # rubocop:enable CodeReuse/ActiveRecord
end end
end end
......
...@@ -31,7 +31,7 @@ module RuboCop ...@@ -31,7 +31,7 @@ module RuboCop
private private
def allowed_foreign_key?(key) 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 end
def allowed_foreign_keys def allowed_foreign_keys
......
...@@ -44,3 +44,4 @@ UsageData/DistinctCountByLargeForeignKey: ...@@ -44,3 +44,4 @@ UsageData/DistinctCountByLargeForeignKey:
- :project_id - :project_id
- :issue_id - :issue_id
- :merge_request_id - :merge_request_id
- :merge_requests.target_project_id
...@@ -10,7 +10,7 @@ require_relative '../../../../rubocop/cop/usage_data/distinct_count_by_large_for ...@@ -10,7 +10,7 @@ require_relative '../../../../rubocop/cop/usage_data/distinct_count_by_large_for
RSpec.describe RuboCop::Cop::UsageData::DistinctCountByLargeForeignKey, type: :rubocop do RSpec.describe RuboCop::Cop::UsageData::DistinctCountByLargeForeignKey, type: :rubocop do
include CopHelper 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 let(:config) do
RuboCop::Config.new('UsageData/DistinctCountByLargeForeignKey' => { RuboCop::Config.new('UsageData/DistinctCountByLargeForeignKey' => {
...@@ -29,10 +29,16 @@ RSpec.describe RuboCop::Cop::UsageData::DistinctCountByLargeForeignKey, type: :r ...@@ -29,10 +29,16 @@ RSpec.describe RuboCop::Cop::UsageData::DistinctCountByLargeForeignKey, type: :r
end end
context 'when calling by allowed key' do 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)') inspect_source('distinct_count(Issue, :author_id)')
expect(cop.offenses).to be_empty expect(cop.offenses).to be_empty
end 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
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