Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
10ae1994
Commit
10ae1994
authored
May 26, 2021
by
Piotr Skorupa
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor HistogramWithLargeTable cop to capture less
parent
951c6dd2
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
12 additions
and
10 deletions
+12
-10
rubocop/cop/usage_data/histogram_with_large_table.rb
rubocop/cop/usage_data/histogram_with_large_table.rb
+6
-10
spec/rubocop/cop/usage_data/histogram_with_large_table_spec.rb
...rubocop/cop/usage_data/histogram_with_large_table_spec.rb
+6
-0
No files found.
rubocop/cop/usage_data/histogram_with_large_table.rb
View file @
10ae1994
...
@@ -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
))
...
...
spec/rubocop/cop/usage_data/histogram_with_large_table_spec.rb
View file @
10ae1994
...
@@ -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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment