Skip to content
Snippets Groups Projects
Commit dc545b45 authored by Ash McKenzie's avatar Ash McKenzie :two:
Browse files

Merge branch 'const_get_false' into 'master'

Lint const_get to not inherit scope (2nd arg false)

Closes #33846

See merge request !18048
parents f332ac13 8edc9723
No related branches found
No related tags found
1 merge request!18048Lint const_get to not inherit scope (2nd arg false)
Pipeline #89079052 passed with warnings
Showing
with 30 additions and 23 deletions
......@@ -178,6 +178,11 @@ Gitlab/ModuleWithInstanceVariables:
- spec/support/**/*.rb
- features/steps/**/*.rb
Gitlab/ConstGetInheritFalse:
Enabled: true
Exclude:
- 'qa/bin/*'
Gitlab/HTTParty:
Enabled: true
Exclude:
......
......@@ -8,13 +8,13 @@ module ApplicationVersion
included do
state_machine :status do
before_transition any => [:installed, :updated] do |application|
application.version = application.class.const_get(:VERSION)
application.version = application.class.const_get(:VERSION, false)
end
end
end
def update_available?
version != self.class.const_get(:VERSION)
version != self.class.const_get(:VERSION, false)
end
end
end
......
......@@ -44,7 +44,7 @@ def calculate_reactive_cache(query_class_name, *args)
end
def query_klass_for(query_name)
Gitlab::Prometheus::Queries.const_get("#{query_name.to_s.classify}Query")
Gitlab::Prometheus::Queries.const_get("#{query_name.to_s.classify}Query", false)
end
def build_query_args(*args)
......
......@@ -24,7 +24,7 @@ module SpecialRole
class << self
def values
constants.map {|const| self.const_get(const)}
constants.map {|const| self.const_get(const, false)}
end
def value?(val)
......
......@@ -138,7 +138,7 @@ def relative_path?
end
def uploader_class
Object.const_get(uploader)
Object.const_get(uploader, false)
end
def identifier
......
......@@ -34,6 +34,7 @@ module ServicesMixin
# Gems that have not yet updated with the new fog-core namespace
LEGACY_FOG_PROVIDERS = %w(google rackspace aliyun).freeze
# 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))
......@@ -48,5 +49,6 @@ def service_provider_search_args(service_name, provider_name)
[provider_name, service_name]
end
end
# rubocop:enable Gitlab/ConstGetInheritFalse
end
end
......@@ -13,7 +13,7 @@ def instrument_classes(instrumentation)
instrumentation.instrument_methods(Gitlab::Git)
Gitlab::Git.constants.each do |name|
const = Gitlab::Git.const_get(name)
const = Gitlab::Git.const_get(name, false)
next unless const.is_a?(Module)
......@@ -75,7 +75,7 @@ def instrument_classes(instrumentation)
instrumentation.instrument_instance_methods(Rouge::Formatters::HTMLGitlab)
[:XML, :HTML].each do |namespace|
namespace_mod = Nokogiri.const_get(namespace)
namespace_mod = Nokogiri.const_get(namespace, false)
instrumentation.instrument_methods(namespace_mod)
instrumentation.instrument_methods(namespace_mod::Document)
......
......@@ -104,10 +104,10 @@ def verify_constant_array(modul, current, default)
# check that `current` (string or integer) is a contant in `modul`.
def verify_constant(modul, current, default)
constant = modul.constants.find { |name| modul.const_get(name) == current }
value = constant.nil? ? default : modul.const_get(constant)
constant = modul.constants.find { |name| modul.const_get(name, false) == current }
value = constant.nil? ? default : modul.const_get(constant, false)
if current.is_a? String
value = modul.const_get(current.upcase) rescue default
value = modul.const_get(current.upcase, false) rescue default
end
value
......
......@@ -22,7 +22,7 @@ def protected_ref_access_levels(*types)
validates :"#{type}_access_levels", length: { is: 1 }, if: -> { false }
# Returns access levels that grant the specified access type to the given user / group.
access_level_class = const_get("#{type}_access_level".classify)
access_level_class = const_get("#{type}_access_level".classify, false)
protected_type = self.model_name.singular
scope(
:"#{type}_access_by_user",
......
......@@ -4,7 +4,7 @@ module CommitStatusPresenter
extend ActiveSupport::Concern
prepended do
EE_CALLOUT_FAILURE_MESSAGES = const_get(:CALLOUT_FAILURE_MESSAGES).merge(
EE_CALLOUT_FAILURE_MESSAGES = const_get(:CALLOUT_FAILURE_MESSAGES, false).merge(
protected_environment_failure: 'The environment this job is deploying to is protected. Only users with permission may successfully run this job.',
insufficient_bridge_permissions: 'This job could not be executed because of insufficient permissions to create a downstream pipeline.',
insufficient_upstream_permissions: 'This job could not be executed because of insufficient permissions to track the upstream project.',
......
......@@ -7,7 +7,7 @@ module QuickActionsService
include ::Gitlab::Utils::StrongMemoize
prepended do
EE_UPDATE_SERVICES = const_get(:UPDATE_SERVICES).merge(
EE_UPDATE_SERVICES = const_get(:UPDATE_SERVICES, false).merge(
'Epic' => Epics::UpdateService
).freeze
EE::Notes::QuickActionsService.private_constant :EE_UPDATE_SERVICES
......
......@@ -9,7 +9,7 @@ module Jobs
extend ActiveSupport::Concern
prepended do
EE_TYPES = const_get(:TYPES) + [::EE::Gitlab::Ci::Config::Entry::Bridge]
EE_TYPES = const_get(:TYPES, false) + [::EE::Gitlab::Ci::Config::Entry::Bridge]
end
class_methods do
......
......@@ -9,7 +9,7 @@ module Failed
extend ActiveSupport::Concern
prepended do
EE_REASONS = const_get(:REASONS).merge(
EE_REASONS = const_get(:REASONS, false).merge(
protected_environment_failure: 'protected environment failure',
invalid_bridge_trigger: 'downstream pipeline trigger definition is invalid',
downstream_bridge_project_not_found: 'downstream project could not be found',
......
......@@ -9,7 +9,7 @@ module ClassProxyUtil
def initialize(target)
super(target)
config = version_namespace.const_get('Config')
config = version_namespace.const_get('Config', false)
@index_name = config.index_name
@document_type = config.document_type
......
......@@ -9,7 +9,7 @@ module InstanceProxyUtil
def initialize(target)
super(target)
config = version_namespace.const_get('Config')
config = version_namespace.const_get('Config', false)
@index_name = config.index_name
@document_type = config.document_type
......
......@@ -12,8 +12,8 @@ module MultiVersionUtil
# @params version [String, Module] can be a string "V12p1" or module (Elastic::V12p1)
def version(version)
version = Elastic.const_get(version) if version.is_a?(String)
version.const_get(proxy_class_name).new(data_target)
version = Elastic.const_get(version, false) if version.is_a?(String)
version.const_get(proxy_class_name, false).new(data_target)
end
private
......
......@@ -159,7 +159,7 @@ def create_items(project, feature_settings = nil)
# access_level can be :disabled, :enabled or :private
def feature_settings(access_level)
Hash[features.collect { |k| ["#{k}_access_level", ProjectFeature.const_get(access_level.to_s.upcase)] }]
Hash[features.collect { |k| ["#{k}_access_level", ProjectFeature.const_get(access_level.to_s.upcase, false)] }]
end
def expect_no_items_to_be_found(user)
......
......@@ -80,7 +80,7 @@ class Notes < Grape::API
note = create_note(noteable, opts)
if note.valid?
present note, with: Entities.const_get(note.class.name)
present note, with: Entities.const_get(note.class.name, false)
else
bad_request!("Note #{note.errors.messages}")
end
......
......@@ -49,7 +49,7 @@ def find_todos
resource :todos do
helpers do
def issuable_and_awardable?(type)
obj_type = Object.const_get(type)
obj_type = Object.const_get(type, false)
(obj_type < Issuable) && (obj_type < Awardable)
rescue NameError
......
......@@ -3,7 +3,7 @@
module Banzai
module Filter
def self.[](name)
const_get("#{name.to_s.camelize}Filter")
const_get("#{name.to_s.camelize}Filter", false)
end
end
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment