Commit 8edc9723 authored by Thong Kuah's avatar Thong Kuah

Rename to Gitlab/ConstGetInheritFalse

As it is a Gitlab specific lint

Also, enable in .rubocop.yml
parent a9628c9b
......@@ -178,6 +178,11 @@ Gitlab/ModuleWithInstanceVariables:
- spec/support/**/*.rb
- features/steps/**/*.rb
Gitlab/ConstGetInheritFalse:
Enabled: true
Exclude:
- 'qa/bin/*'
Gitlab/HTTParty:
Enabled: true
Exclude:
......
......@@ -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
......@@ -2,8 +2,6 @@
require_relative '../qa'
# rubocop:disable Cop/ConstGetInheritFalse
QA::Scenario
.const_get(ARGV.shift)
.launch!(ARGV)
# rubocop:enable Cop/ConstGetInheritFalse
# 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
# 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
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'
......
......@@ -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 }
......
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