diff options
author | Thong Kuah <tkuah@gitlab.com> | 2019-05-20 14:48:47 +1200 |
---|---|---|
committer | Thong Kuah <tkuah@gitlab.com> | 2019-08-28 00:04:12 +1200 |
commit | 9ff86452b0c2f21c1f86cd1a14dde69c62d2ff65 (patch) | |
tree | 1d570e6be2d5a26c0017b769a0662ae03948cd26 | |
parent | df3c259da67e7184ba8590a1ce55cc43a1247668 (diff) | |
download | gitlab-ce-59719-const-get-rubocop.tar.gz |
Address ConstGetInheritFalse violations59719-const-get-rubocop
There should be no cases where we need to inherit=true.
38 files changed, 51 insertions, 49 deletions
diff --git a/app/models/clusters/concerns/application_version.rb b/app/models/clusters/concerns/application_version.rb index db94e8e08c9..6c0b014662c 100644 --- a/app/models/clusters/concerns/application_version.rb +++ b/app/models/clusters/concerns/application_version.rb @@ -8,13 +8,13 @@ module Clusters 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 diff --git a/app/models/concerns/prometheus_adapter.rb b/app/models/concerns/prometheus_adapter.rb index 9ac4722c6b1..fc3266baf65 100644 --- a/app/models/concerns/prometheus_adapter.rb +++ b/app/models/concerns/prometheus_adapter.rb @@ -42,7 +42,7 @@ module PrometheusAdapter 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) diff --git a/app/models/note.rb b/app/models/note.rb index a12d1eb7243..132f5f6fae1 100644 --- a/app/models/note.rb +++ b/app/models/note.rb @@ -25,7 +25,7 @@ class Note < ApplicationRecord class << self def values - constants.map {|const| self.const_get(const)} + constants.map {|const| self.const_get(const, false)} end def value?(val) diff --git a/app/models/upload.rb b/app/models/upload.rb index ca74f16b3b8..deb383b8f82 100644 --- a/app/models/upload.rb +++ b/app/models/upload.rb @@ -114,7 +114,7 @@ class Upload < ApplicationRecord end def uploader_class - Object.const_get(uploader) + Object.const_get(uploader, false) end def identifier diff --git a/config/initializers/fog_core_patch.rb b/config/initializers/fog_core_patch.rb index d3d02216d45..7522b6afe62 100644 --- a/config/initializers/fog_core_patch.rb +++ b/config/initializers/fog_core_patch.rb @@ -34,6 +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 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 @@ module Fog [provider_name, service_name] end end + # rubocop:enable Cop/ConstGetInheritFalse end end diff --git a/config/initializers/zz_metrics.rb b/config/initializers/zz_metrics.rb index af4aec7b355..8eaa1a33f47 100644 --- a/config/initializers/zz_metrics.rb +++ b/config/initializers/zz_metrics.rb @@ -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) diff --git a/config/settings.rb b/config/settings.rb index 8756c120645..767c6c56337 100644 --- a/config/settings.rb +++ b/config/settings.rb @@ -104,10 +104,10 @@ class Settings < Settingslogic # 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 diff --git a/lib/api/entities.rb b/lib/api/entities.rb index 5e66b4e76a5..4202c037707 100644 --- a/lib/api/entities.rb +++ b/lib/api/entities.rb @@ -978,7 +978,7 @@ module API expose :created_at def todo_target_class(target_type) - ::API::Entities.const_get(target_type) + ::API::Entities.const_get(target_type, false) end end diff --git a/lib/api/notes.rb b/lib/api/notes.rb index 84563d66ee8..a7f61894644 100644 --- a/lib/api/notes.rb +++ b/lib/api/notes.rb @@ -80,7 +80,7 @@ module 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 diff --git a/lib/api/todos.rb b/lib/api/todos.rb index 404675bfaec..e3f3aca27df 100644 --- a/lib/api/todos.rb +++ b/lib/api/todos.rb @@ -49,7 +49,7 @@ module API 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 diff --git a/lib/banzai/filter.rb b/lib/banzai/filter.rb index 7d9766c906c..2438cb3c166 100644 --- a/lib/banzai/filter.rb +++ b/lib/banzai/filter.rb @@ -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 diff --git a/lib/banzai/pipeline.rb b/lib/banzai/pipeline.rb index e8a81bebaa9..497d3f27542 100644 --- a/lib/banzai/pipeline.rb +++ b/lib/banzai/pipeline.rb @@ -4,7 +4,7 @@ module Banzai module Pipeline def self.[](name) name ||= :full - const_get("#{name.to_s.camelize}Pipeline") + const_get("#{name.to_s.camelize}Pipeline", false) end end end diff --git a/lib/banzai/reference_parser.rb b/lib/banzai/reference_parser.rb index efe15096f08..c08d3364a87 100644 --- a/lib/banzai/reference_parser.rb +++ b/lib/banzai/reference_parser.rb @@ -10,7 +10,7 @@ module Banzai # # This would return the `Banzai::ReferenceParser::IssueParser` class. def self.[](name) - const_get("#{name.to_s.camelize}Parser") + const_get("#{name.to_s.camelize}Parser", false) end end end diff --git a/lib/bitbucket/page.rb b/lib/bitbucket/page.rb index 7cc1342ad65..38c689628dd 100644 --- a/lib/bitbucket/page.rb +++ b/lib/bitbucket/page.rb @@ -30,7 +30,7 @@ module Bitbucket end def representation_class(type) - Bitbucket::Representation.const_get(type.to_s.camelize) + Bitbucket::Representation.const_get(type.to_s.camelize, false) end end end diff --git a/lib/bitbucket_server/page.rb b/lib/bitbucket_server/page.rb index 5d9a3168876..304f7cd9d72 100644 --- a/lib/bitbucket_server/page.rb +++ b/lib/bitbucket_server/page.rb @@ -30,7 +30,7 @@ module BitbucketServer end def representation_class(type) - BitbucketServer::Representation.const_get(type.to_s.camelize) + BitbucketServer::Representation.const_get(type.to_s.camelize, false) end end end diff --git a/lib/gitlab/background_migration.rb b/lib/gitlab/background_migration.rb index 2e3a4f3b869..61e0a075018 100644 --- a/lib/gitlab/background_migration.rb +++ b/lib/gitlab/background_migration.rb @@ -78,7 +78,7 @@ module Gitlab end def self.migration_class_for(class_name) - const_get(class_name) + const_get(class_name, false) end def self.enqueued_job?(queues, migration_class) diff --git a/lib/gitlab/cache/request_cache.rb b/lib/gitlab/cache/request_cache.rb index 4c658dc0b8d..6e48ca90054 100644 --- a/lib/gitlab/cache/request_cache.rb +++ b/lib/gitlab/cache/request_cache.rb @@ -23,7 +23,7 @@ module Gitlab end def request_cache(method_name, &method_key_block) - const_get(:RequestCacheExtension).module_eval do + const_get(:RequestCacheExtension, false).module_eval do cache_key_method_name = "#{method_name}_cache_key" define_method(method_name) do |*args| diff --git a/lib/gitlab/ci/build/policy.rb b/lib/gitlab/ci/build/policy.rb index 43c46ad74af..ebeebe7fb5b 100644 --- a/lib/gitlab/ci/build/policy.rb +++ b/lib/gitlab/ci/build/policy.rb @@ -6,7 +6,7 @@ module Gitlab module Policy def self.fabricate(specs) specifications = specs.to_h.map do |spec, value| - self.const_get(spec.to_s.camelize).new(value) + self.const_get(spec.to_s.camelize, false).new(value) end specifications.compact diff --git a/lib/gitlab/ci/status/factory.rb b/lib/gitlab/ci/status/factory.rb index 2a0bf060c9b..c29dc51f076 100644 --- a/lib/gitlab/ci/status/factory.rb +++ b/lib/gitlab/ci/status/factory.rb @@ -20,7 +20,7 @@ module Gitlab def core_status Gitlab::Ci::Status - .const_get(@status.capitalize) + .const_get(@status.capitalize, false) .new(@subject, @user) .extend(self.class.common_helpers) end diff --git a/lib/gitlab/config/entry/simplifiable.rb b/lib/gitlab/config/entry/simplifiable.rb index a56a89adb35..d58aba07d15 100644 --- a/lib/gitlab/config/entry/simplifiable.rb +++ b/lib/gitlab/config/entry/simplifiable.rb @@ -37,7 +37,7 @@ module Gitlab def self.entry_class(strategy) if strategy.present? - self.const_get(strategy.name) + self.const_get(strategy.name, false) else self::UnknownStrategy end diff --git a/lib/gitlab/cycle_analytics/event_fetcher.rb b/lib/gitlab/cycle_analytics/event_fetcher.rb index 98a30a8fc97..04f4b4f053f 100644 --- a/lib/gitlab/cycle_analytics/event_fetcher.rb +++ b/lib/gitlab/cycle_analytics/event_fetcher.rb @@ -4,7 +4,7 @@ module Gitlab module CycleAnalytics module EventFetcher def self.[](stage_name) - CycleAnalytics.const_get("#{stage_name.to_s.camelize}EventFetcher") + CycleAnalytics.const_get("#{stage_name.to_s.camelize}EventFetcher", false) end end end diff --git a/lib/gitlab/cycle_analytics/stage.rb b/lib/gitlab/cycle_analytics/stage.rb index 1bd40a7aa18..5cfd9ea4730 100644 --- a/lib/gitlab/cycle_analytics/stage.rb +++ b/lib/gitlab/cycle_analytics/stage.rb @@ -4,7 +4,7 @@ module Gitlab module CycleAnalytics module Stage def self.[](stage_name) - CycleAnalytics.const_get("#{stage_name.to_s.camelize}Stage") + CycleAnalytics.const_get("#{stage_name.to_s.camelize}Stage", false) end end end diff --git a/lib/gitlab/downtime_check.rb b/lib/gitlab/downtime_check.rb index 31bb6810391..457a3c12206 100644 --- a/lib/gitlab/downtime_check.rb +++ b/lib/gitlab/downtime_check.rb @@ -58,13 +58,13 @@ module Gitlab # Returns true if the given migration can be performed without downtime. def online?(migration) - migration.const_get(DOWNTIME_CONST) == false + migration.const_get(DOWNTIME_CONST, false) == false end # Returns the downtime reason, or nil if none was defined. def downtime_reason(migration) if migration.const_defined?(DOWNTIME_REASON_CONST) - migration.const_get(DOWNTIME_REASON_CONST) + migration.const_get(DOWNTIME_REASON_CONST, false) else nil end diff --git a/lib/gitlab/gitaly_client.rb b/lib/gitlab/gitaly_client.rb index 201db9fec26..ed0b8f24160 100644 --- a/lib/gitlab/gitaly_client.rb +++ b/lib/gitlab/gitaly_client.rb @@ -86,7 +86,7 @@ module Gitlab if name == :health_check Grpc::Health::V1::Health::Stub else - Gitaly.const_get(name.to_s.camelcase.to_sym).const_get(:Stub) + Gitaly.const_get(name.to_s.camelcase.to_sym, false).const_get(:Stub, false) end end diff --git a/lib/gitlab/gitaly_client/attributes_bag.rb b/lib/gitlab/gitaly_client/attributes_bag.rb index 3f1a0ef4888..f935281ac2e 100644 --- a/lib/gitlab/gitaly_client/attributes_bag.rb +++ b/lib/gitlab/gitaly_client/attributes_bag.rb @@ -8,7 +8,7 @@ module Gitlab extend ActiveSupport::Concern included do - attr_accessor(*const_get(:ATTRS)) + attr_accessor(*const_get(:ATTRS, false)) end def initialize(params) @@ -26,7 +26,7 @@ module Gitlab end def attributes - self.class.const_get(:ATTRS) + self.class.const_get(:ATTRS, false) end end end diff --git a/lib/gitlab/pages_client.rb b/lib/gitlab/pages_client.rb index 281eafb142f..bde1b074a2e 100644 --- a/lib/gitlab/pages_client.rb +++ b/lib/gitlab/pages_client.rb @@ -69,7 +69,7 @@ module Gitlab Grpc::Health::V1::Health::Stub else # TODO use pages namespace - Gitaly.const_get(name.to_s.camelcase.to_sym).const_get(:Stub) + Gitaly.const_get(name.to_s.camelcase.to_sym, false).const_get(:Stub, false) end end diff --git a/lib/gitlab/patch/prependable.rb b/lib/gitlab/patch/prependable.rb index a9f6cfb19cb..22ece0a6a8b 100644 --- a/lib/gitlab/patch/prependable.rb +++ b/lib/gitlab/patch/prependable.rb @@ -24,7 +24,7 @@ module Gitlab super if const_defined?(:ClassMethods) - klass_methods = const_get(:ClassMethods) + klass_methods = const_get(:ClassMethods, false) base.singleton_class.prepend klass_methods base.instance_variable_set(:@_prepended_class_methods, klass_methods) end @@ -40,7 +40,7 @@ module Gitlab super if instance_variable_defined?(:@_prepended_class_methods) - const_get(:ClassMethods).prepend @_prepended_class_methods + const_get(:ClassMethods, false).prepend @_prepended_class_methods end end diff --git a/qa/bin/qa b/qa/bin/qa index 6a772e93cee..cba0e216a36 100755 --- a/qa/bin/qa +++ b/qa/bin/qa @@ -3,5 +3,5 @@ require_relative '../qa' QA::Scenario - .const_get(ARGV.shift) + .const_get(ARGV.shift, false) .launch!(ARGV) diff --git a/qa/qa/page/validator.rb b/qa/qa/page/validator.rb index 9b2d0a1a41d..75e48b5785e 100644 --- a/qa/qa/page/validator.rb +++ b/qa/qa/page/validator.rb @@ -17,7 +17,7 @@ module QA def constants @consts ||= @module.constants.map do |const| - @module.const_get(const) + @module.const_get(const, false) end end diff --git a/qa/qa/runtime/browser.rb b/qa/qa/runtime/browser.rb index 2987bb1a213..a165f67e1ef 100644 --- a/qa/qa/runtime/browser.rb +++ b/qa/qa/runtime/browser.rb @@ -65,7 +65,7 @@ module QA # QA::Runtime::Env.browser.capitalize will work for every driver type except PhantomJS. # We will have no use to use PhantomJS so this shouldn't be a problem. - options = Selenium::WebDriver.const_get(QA::Runtime::Env.browser.capitalize)::Options.new + options = Selenium::WebDriver.const_get(QA::Runtime::Env.browser.capitalize, false)::Options.new if QA::Runtime::Env.browser == :chrome options.add_argument("window-size=1240,1680") diff --git a/qa/qa/runtime/release.rb b/qa/qa/runtime/release.rb index 4f96e0cf44b..cb61dd1ee89 100644 --- a/qa/qa/runtime/release.rb +++ b/qa/qa/runtime/release.rb @@ -19,7 +19,7 @@ module QA end def strategy - QA.const_get("QA::#{version}::Strategy") + QA.const_get("QA::#{version}::Strategy", false) end def self.method_missing(name, *args) diff --git a/spec/lib/gitlab/ci/status/external/factory_spec.rb b/spec/lib/gitlab/ci/status/external/factory_spec.rb index 3b90fb60cca..9d7dfc42848 100644 --- a/spec/lib/gitlab/ci/status/external/factory_spec.rb +++ b/spec/lib/gitlab/ci/status/external/factory_spec.rb @@ -22,7 +22,7 @@ describe Gitlab::Ci::Status::External::Factory do end let(:expected_status) do - Gitlab::Ci::Status.const_get(simple_status.capitalize) + Gitlab::Ci::Status.const_get(simple_status.capitalize, false) end it "fabricates a core status #{simple_status}" do diff --git a/spec/lib/gitlab/ci/status/factory_spec.rb b/spec/lib/gitlab/ci/status/factory_spec.rb index b51c0bec47e..c6d7a1ec5d9 100644 --- a/spec/lib/gitlab/ci/status/factory_spec.rb +++ b/spec/lib/gitlab/ci/status/factory_spec.rb @@ -13,7 +13,7 @@ describe Gitlab::Ci::Status::Factory do let(:resource) { double('resource', status: simple_status) } let(:expected_status) do - Gitlab::Ci::Status.const_get(simple_status.capitalize) + Gitlab::Ci::Status.const_get(simple_status.capitalize, false) end it "fabricates a core status #{simple_status}" do diff --git a/spec/lib/gitlab/ci/status/pipeline/factory_spec.rb b/spec/lib/gitlab/ci/status/pipeline/factory_spec.rb index 8a36cd1b658..3acc767ab7a 100644 --- a/spec/lib/gitlab/ci/status/pipeline/factory_spec.rb +++ b/spec/lib/gitlab/ci/status/pipeline/factory_spec.rb @@ -18,7 +18,7 @@ describe Gitlab::Ci::Status::Pipeline::Factory do let(:pipeline) { create(:ci_pipeline, status: simple_status) } let(:expected_status) do - Gitlab::Ci::Status.const_get(simple_status.capitalize) + Gitlab::Ci::Status.const_get(simple_status.capitalize, false) end it "matches correct core status for #{simple_status}" do diff --git a/spec/lib/gitlab/ci/status/stage/factory_spec.rb b/spec/lib/gitlab/ci/status/stage/factory_spec.rb index 8f5b1ff62a5..dcb53712157 100644 --- a/spec/lib/gitlab/ci/status/stage/factory_spec.rb +++ b/spec/lib/gitlab/ci/status/stage/factory_spec.rb @@ -34,7 +34,7 @@ describe Gitlab::Ci::Status::Stage::Factory do it "fabricates a core status #{core_status}" do expect(status).to be_a( - Gitlab::Ci::Status.const_get(core_status.capitalize)) + Gitlab::Ci::Status.const_get(core_status.capitalize, false)) end it 'extends core status with common stage methods' do diff --git a/spec/lib/gitlab/patch/prependable_spec.rb b/spec/lib/gitlab/patch/prependable_spec.rb index 725d733d176..255324f89d5 100644 --- a/spec/lib/gitlab/patch/prependable_spec.rb +++ b/spec/lib/gitlab/patch/prependable_spec.rb @@ -72,8 +72,8 @@ describe Gitlab::Patch::Prependable do expect(subject.ancestors.take(3)).to eq([subject, ee, ce]) expect(subject.singleton_class.ancestors.take(3)) .to eq([subject.singleton_class, - ee.const_get(:ClassMethods), - ce.const_get(:ClassMethods)]) + ee.const_get(:ClassMethods, false), + ce.const_get(:ClassMethods, false)]) end it 'prepends only once even if called twice' do @@ -115,8 +115,8 @@ describe Gitlab::Patch::Prependable do it 'has the expected ancestors' do expect(subject.ancestors.take(3)).to eq([ee, ce, subject]) expect(subject.singleton_class.ancestors.take(3)) - .to eq([ee.const_get(:ClassMethods), - ce.const_get(:ClassMethods), + .to eq([ee.const_get(:ClassMethods, false), + ce.const_get(:ClassMethods, false), subject.singleton_class]) end @@ -152,7 +152,7 @@ describe Gitlab::Patch::Prependable do it 'has the expected ancestors' do expect(subject.ancestors.take(2)).to eq([ee, subject]) expect(subject.singleton_class.ancestors.take(2)) - .to eq([ee.const_get(:ClassMethods), + .to eq([ee.const_get(:ClassMethods, false), subject.singleton_class]) end diff --git a/spec/support/shared_examples/models/cluster_application_status_shared_examples.rb b/spec/support/shared_examples/models/cluster_application_status_shared_examples.rb index 5341aacb445..bdbe37abb0a 100644 --- a/spec/support/shared_examples/models/cluster_application_status_shared_examples.rb +++ b/spec/support/shared_examples/models/cluster_application_status_shared_examples.rb @@ -61,7 +61,7 @@ shared_examples 'cluster application status specs' do |application_name| subject.reload - expect(subject.version).to eq(subject.class.const_get(:VERSION)) + expect(subject.version).to eq(subject.class.const_get(:VERSION, false)) end context 'application is updating' do @@ -90,7 +90,7 @@ shared_examples 'cluster application status specs' do |application_name| subject.reload - expect(subject.version).to eq(subject.class.const_get(:VERSION)) + expect(subject.version).to eq(subject.class.const_get(:VERSION, false)) end end end diff --git a/spec/support/shared_examples/models/cluster_application_version_shared_examples.rb b/spec/support/shared_examples/models/cluster_application_version_shared_examples.rb index 181b102e685..ba02da41b53 100644 --- a/spec/support/shared_examples/models/cluster_application_version_shared_examples.rb +++ b/spec/support/shared_examples/models/cluster_application_version_shared_examples.rb @@ -12,7 +12,7 @@ shared_examples 'cluster application version specs' do |application_name| context 'version is the same as VERSION' do let(:application) { build(application_name) } - let(:version) { application.class.const_get(:VERSION) } + let(:version) { application.class.const_get(:VERSION, false) } it { is_expected.to be_falsey } end |