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
8edc9723
Commit
8edc9723
authored
Oct 11, 2019
by
Thong Kuah
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Rename to Gitlab/ConstGetInheritFalse
As it is a Gitlab specific lint Also, enable in .rubocop.yml
parent
a9628c9b
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
52 additions
and
47 deletions
+52
-47
.rubocop.yml
.rubocop.yml
+5
-0
config/initializers/fog_core_patch.rb
config/initializers/fog_core_patch.rb
+2
-2
qa/bin/qa
qa/bin/qa
+0
-2
rubocop/cop/const_get_inherit_false.rb
rubocop/cop/const_get_inherit_false.rb
+0
-40
rubocop/cop/gitlab/const_get_inherit_false.rb
rubocop/cop/gitlab/const_get_inherit_false.rb
+42
-0
rubocop/rubocop.rb
rubocop/rubocop.rb
+1
-1
spec/rubocop/cop/gitlab/const_get_inherit_false_spec.rb
spec/rubocop/cop/gitlab/const_get_inherit_false_spec.rb
+2
-2
No files found.
.rubocop.yml
View file @
8edc9723
...
...
@@ -178,6 +178,11 @@ Gitlab/ModuleWithInstanceVariables:
-
spec/support/**/*.rb
-
features/steps/**/*.rb
Gitlab/ConstGetInheritFalse
:
Enabled
:
true
Exclude
:
-
'
qa/bin/*'
Gitlab/HTTParty
:
Enabled
:
true
Exclude
:
...
...
config/initializers/fog_core_patch.rb
View file @
8edc9723
...
...
@@ -34,7 +34,7 @@ module Fog
# Gems that have not yet updated with the new fog-core namespace
LEGACY_FOG_PROVIDERS
=
%w(google rackspace aliyun)
.
freeze
# rubocop:disable
Cop
/ConstGetInheritFalse
# rubocop:disable
Gitlab
/ConstGetInheritFalse
def
service_provider_constant
(
service_name
,
provider_name
)
args
=
service_provider_search_args
(
service_name
,
provider_name
)
Fog
.
const_get
(
args
.
first
).
const_get
(
*
const_get_args
(
args
.
second
))
...
...
@@ -49,6 +49,6 @@ module Fog
[
provider_name
,
service_name
]
end
end
# rubocop:enable
Cop
/ConstGetInheritFalse
# rubocop:enable
Gitlab
/ConstGetInheritFalse
end
end
qa/bin/qa
View file @
8edc9723
...
...
@@ -2,8 +2,6 @@
require_relative
'../qa'
# rubocop:disable Cop/ConstGetInheritFalse
QA
::
Scenario
.
const_get
(
ARGV
.
shift
)
.
launch!
(
ARGV
)
# rubocop:enable Cop/ConstGetInheritFalse
rubocop/cop/const_get_inherit_false.rb
deleted
100644 → 0
View file @
a9628c9b
# frozen_string_literal: true
module
RuboCop
module
Cop
# Cop that encourages usage of inherit=false for 2nd argument when using const_get.
#
# See https://gitlab.com/gitlab-org/gitlab-ce/issues/59719
class
ConstGetInheritFalse
<
RuboCop
::
Cop
::
Cop
MSG
=
'Use inherit=false when using const_get.'
def_node_matcher
:const_get?
,
<<~
PATTERN
(send _ :const_get ...)
PATTERN
def
on_send
(
node
)
return
unless
const_get
?(
node
)
return
if
second_argument
(
node
)
&
.
false_type?
add_offense
(
node
,
location:
:
selector
)
end
def
autocorrect
(
node
)
lambda
do
|
corrector
|
if
arg
=
second_argument
(
node
)
corrector
.
replace
(
arg
.
source_range
,
'false'
)
else
first_argument
=
node
.
arguments
[
0
]
corrector
.
insert_after
(
first_argument
.
source_range
,
', false'
)
end
end
end
private
def
second_argument
(
node
)
node
.
arguments
[
1
]
end
end
end
end
rubocop/cop/gitlab/const_get_inherit_false.rb
0 → 100644
View file @
8edc9723
# frozen_string_literal: true
module
RuboCop
module
Cop
module
Gitlab
# Cop that encourages usage of inherit=false for 2nd argument when using const_get.
#
# See https://gitlab.com/gitlab-org/gitlab/issues/27678
class
ConstGetInheritFalse
<
RuboCop
::
Cop
::
Cop
MSG
=
'Use inherit=false when using const_get.'
def_node_matcher
:const_get?
,
<<~
PATTERN
(send _ :const_get ...)
PATTERN
def
on_send
(
node
)
return
unless
const_get
?(
node
)
return
if
second_argument
(
node
)
&
.
false_type?
add_offense
(
node
,
location:
:
selector
)
end
def
autocorrect
(
node
)
lambda
do
|
corrector
|
if
arg
=
second_argument
(
node
)
corrector
.
replace
(
arg
.
source_range
,
'false'
)
else
first_argument
=
node
.
arguments
[
0
]
corrector
.
insert_after
(
first_argument
.
source_range
,
', false'
)
end
end
end
private
def
second_argument
(
node
)
node
.
arguments
[
1
]
end
end
end
end
end
rubocop/rubocop.rb
View file @
8edc9723
require_relative
'cop/gitlab/const_get_inherit_false'
require_relative
'cop/gitlab/module_with_instance_variables'
require_relative
'cop/gitlab/predicate_memoization'
require_relative
'cop/gitlab/httparty'
...
...
@@ -11,7 +12,6 @@ require_relative 'cop/active_record_association_reload'
require_relative
'cop/avoid_return_from_blocks'
require_relative
'cop/avoid_break_from_strong_memoize'
require_relative
'cop/avoid_route_redirect_leading_slash'
require_relative
'cop/const_get_inherit_false'
require_relative
'cop/line_break_around_conditional_block'
require_relative
'cop/prefer_class_methods_over_module'
require_relative
'cop/migration/add_column'
...
...
spec/rubocop/cop/const_get_inherit_false_spec.rb
→
spec/rubocop/cop/
gitlab/
const_get_inherit_false_spec.rb
View file @
8edc9723
...
...
@@ -3,9 +3,9 @@
require
'spec_helper'
require
'rubocop'
require
'rubocop/rspec/support'
require_relative
'../../../
rubocop/cop
/const_get_inherit_false'
require_relative
'../../../
../rubocop/cop/gitlab
/const_get_inherit_false'
describe
RuboCop
::
Cop
::
ConstGetInheritFalse
do
describe
RuboCop
::
Cop
::
Gitlab
::
ConstGetInheritFalse
do
include
CopHelper
subject
(
:cop
)
{
described_class
.
new
}
...
...
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