Commit 10ae1994 authored by Piotr Skorupa's avatar Piotr Skorupa

Refactor HistogramWithLargeTable cop to capture less

parent 951c6dd2
...@@ -17,17 +17,17 @@ module RuboCop ...@@ -17,17 +17,17 @@ module RuboCop
# Match one level const as Issue, Gitlab # Match one level const as Issue, Gitlab
def_node_matcher :one_level_node, <<~PATTERN def_node_matcher :one_level_node, <<~PATTERN
(send nil? :histogram (send nil? :histogram
`(const {nil? cbase} $...) `(const {nil? cbase} $_)
$...) ...)
PATTERN PATTERN
# Match two level const as ::Clusters::Cluster, ::Ci::Pipeline # Match two level const as ::Clusters::Cluster, ::Ci::Pipeline
def_node_matcher :two_level_node, <<~PATTERN def_node_matcher :two_level_node, <<~PATTERN
(send nil? :histogram (send nil? :histogram
`(const `(const
(const {nil? cbase} $...) (const {nil? cbase} $_)
$...) $_)
$...) ...)
PATTERN PATTERN
def on_send(node) def on_send(node)
...@@ -36,11 +36,7 @@ module RuboCop ...@@ -36,11 +36,7 @@ module RuboCop
return unless Array(one_level_matches).any? || Array(two_level_matches).any? return unless Array(one_level_matches).any? || Array(two_level_matches).any?
class_name = if two_level_matches class_name = two_level_matches ? two_level_matches.join('::').to_sym : one_level_matches
"#{two_level_matches[0].first}::#{two_level_matches[1].first}".to_sym
else
one_level_matches[0].first
end
if large_table?(class_name) if large_table?(class_name)
add_offense(node, location: :expression, message: format(MSG, model_name: class_name)) add_offense(node, location: :expression, message: format(MSG, model_name: class_name))
......
...@@ -99,4 +99,10 @@ RSpec.describe RuboCop::Cop::UsageData::HistogramWithLargeTable do ...@@ -99,4 +99,10 @@ RSpec.describe RuboCop::Cop::UsageData::HistogramWithLargeTable do
expect_no_offenses('histogram(MergeRequest, buckets: 1..100)') expect_no_offenses('histogram(MergeRequest, buckets: 1..100)')
end end
end end
context 'with non related method' do
it 'does not register an offense' do
expect_no_offenses('count(Issue, buckets: 1..100)')
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