Commit e39972b7 authored by Matthias Käppler's avatar Matthias Käppler

Merge branch 'resolve-class-equality-comparison' into 'master'

Resolve Style/ClassEqualityComparison exceptions

See merge request gitlab-org/gitlab!65357
parents 64779a74 154e0bad
...@@ -2146,11 +2146,6 @@ Gitlab/NamespacedClass: ...@@ -2146,11 +2146,6 @@ Gitlab/NamespacedClass:
- 'spec/tasks/gitlab/task_helpers_spec.rb' - 'spec/tasks/gitlab/task_helpers_spec.rb'
- 'spec/uploaders/object_storage_spec.rb' - 'spec/uploaders/object_storage_spec.rb'
Style/ClassEqualityComparison:
Exclude:
- spec/lib/peek/views/active_record_spec.rb
- ee/spec/lib/peek/views/active_record_spec.rb
# WIP See https://gitlab.com/gitlab-org/gitlab/-/issues/207950 # WIP See https://gitlab.com/gitlab-org/gitlab/-/issues/207950
Cop/UserAdmin: Cop/UserAdmin:
Exclude: Exclude:
......
...@@ -660,23 +660,6 @@ Style/BisectedAttrAccessor: ...@@ -660,23 +660,6 @@ Style/BisectedAttrAccessor:
Style/CaseLikeIf: Style/CaseLikeIf:
Enabled: false Enabled: false
# Offense count: 10
# Cop supports --auto-correct.
# Configuration parameters: IgnoredMethods.
# IgnoredMethods: ==, equal?, eql?
Style/ClassEqualityComparison:
Exclude:
- 'app/finders/security/jobs_finder.rb'
- 'app/services/projects/overwrite_project_service.rb'
- 'app/uploaders/dependency_proxy/file_uploader.rb'
- 'ee/app/graphql/resolvers/vulnerabilities/issue_links_resolver.rb'
- 'lib/gitlab/background_migration/user_mentions/models/note.rb'
- 'lib/gitlab/diff/file.rb'
- 'lib/gitlab/git.rb'
- 'lib/gitlab/import_export/relation_tree_restorer.rb'
- 'spec/requests/api/services_spec.rb'
- 'spec/support/shared_examples/lib/gitlab/import_export/relation_factory_shared_examples.rb'
# Offense count: 13 # Offense count: 13
Style/CombinableLoops: Style/CombinableLoops:
Exclude: Exclude:
......
...@@ -20,7 +20,7 @@ module Security ...@@ -20,7 +20,7 @@ module Security
end end
def initialize(pipeline:, job_types: []) def initialize(pipeline:, job_types: [])
if self.class == Security::JobsFinder if self.instance_of?(Security::JobsFinder)
raise NotImplementedError, 'This is an abstract class, please instantiate its descendants' raise NotImplementedError, 'This is an abstract class, please instantiate its descendants'
end end
......
...@@ -20,7 +20,7 @@ module Projects ...@@ -20,7 +20,7 @@ module Projects
rescue Exception => e # rubocop:disable Lint/RescueException rescue Exception => e # rubocop:disable Lint/RescueException
attempt_restore_repositories(source_project) attempt_restore_repositories(source_project)
if e.class == Exception if e.instance_of?(Exception)
raise StandardError, e.message raise StandardError, e.message
else else
raise raise
......
...@@ -24,7 +24,7 @@ class DependencyProxy::FileUploader < GitlabUploader ...@@ -24,7 +24,7 @@ class DependencyProxy::FileUploader < GitlabUploader
# so we must store the custom content type in object storage. # so we must store the custom content type in object storage.
# This does not apply to DependencyProxy::Blob uploads. # This does not apply to DependencyProxy::Blob uploads.
def set_content_type(file) def set_content_type(file)
return unless model.class == DependencyProxy::Manifest return unless model.instance_of?(DependencyProxy::Manifest)
file.content_type = model.content_type file.content_type = model.content_type
end end
......
...@@ -35,7 +35,7 @@ module Resolvers ...@@ -35,7 +35,7 @@ module Resolvers
end end
def valid_link_type?(args) def valid_link_type?(args)
if args[:link_type].class == String if args[:link_type].instance_of?(String)
link_type = args[:link_type].downcase link_type = args[:link_type].downcase
link_types = ::Vulnerabilities::IssueLink.link_types.keys link_types = ::Vulnerabilities::IssueLink.link_types.keys
......
...@@ -21,7 +21,7 @@ module Gitlab ...@@ -21,7 +21,7 @@ module Gitlab
belongs_to :project, class_name: "::Gitlab::BackgroundMigration::UserMentions::Models::Project" belongs_to :project, class_name: "::Gitlab::BackgroundMigration::UserMentions::Models::Project"
def for_personal_snippet? def for_personal_snippet?
noteable && noteable.class.name == 'PersonalSnippet' noteable && noteable.instance_of?(PersonalSnippet)
end end
def for_project_noteable? def for_project_noteable?
......
...@@ -449,7 +449,7 @@ module Gitlab ...@@ -449,7 +449,7 @@ module Gitlab
end end
def alternate_viewer_class def alternate_viewer_class
return unless viewer.class == DiffViewer::Renamed return unless viewer.instance_of?(DiffViewer::Renamed)
find_renderable_viewer_class(RICH_VIEWERS) || (DiffViewer::Text if text?) find_renderable_viewer_class(RICH_VIEWERS) || (DiffViewer::Text if text?)
end end
......
...@@ -80,7 +80,7 @@ module Gitlab ...@@ -80,7 +80,7 @@ module Gitlab
def shas_eql?(sha1, sha2) def shas_eql?(sha1, sha2)
return true if sha1.nil? && sha2.nil? return true if sha1.nil? && sha2.nil?
return false if sha1.nil? || sha2.nil? return false if sha1.nil? || sha2.nil?
return false unless sha1.class == sha2.class return false unless sha1.instance_of?(sha2.class)
# If either of the shas is below the minimum length, we cannot be sure # If either of the shas is below the minimum length, we cannot be sure
# that they actually refer to the same commit because of hash collision. # that they actually refer to the same commit because of hash collision.
......
...@@ -37,7 +37,7 @@ module Gitlab ...@@ -37,7 +37,7 @@ module Gitlab
ActiveRecord::Base.no_touching do ActiveRecord::Base.no_touching do
update_params! update_params!
BulkInsertableAssociations.with_bulk_insert(enabled: @importable.class == ::Project) do BulkInsertableAssociations.with_bulk_insert(enabled: @importable.instance_of?(::Project)) do
fix_ci_pipelines_not_sorted_on_legacy_project_json! fix_ci_pipelines_not_sorted_on_legacy_project_json!
create_relations! create_relations!
end end
......
...@@ -76,7 +76,7 @@ RSpec.describe API::Services do ...@@ -76,7 +76,7 @@ RSpec.describe API::Services do
required_attributes = service_attrs_list.select do |attr| required_attributes = service_attrs_list.select do |attr|
service_klass.validators_on(attr).any? do |v| service_klass.validators_on(attr).any? do |v|
v.class == ActiveRecord::Validations::PresenceValidator && v.instance_of?(ActiveRecord::Validations::PresenceValidator) &&
# exclude presence validators with conditional since those are not really required # exclude presence validators with conditional since those are not really required
![:if, :unless].any? { |cond| v.options.include?(cond) } ![:if, :unless].any? { |cond| v.options.include?(cond) }
end end
......
...@@ -12,7 +12,7 @@ RSpec.shared_examples 'Notes user references' do ...@@ -12,7 +12,7 @@ RSpec.shared_examples 'Notes user references' do
'id' => 111, 'id' => 111,
'access_level' => 30, 'access_level' => 30,
'source_id' => 1, 'source_id' => 1,
'source_type' => importable.class.name == 'Project' ? 'Project' : 'Namespace', 'source_type' => importable.instance_of?(Project) ? 'Project' : 'Namespace',
'user_id' => 3, 'user_id' => 3,
'notification_level' => 3, 'notification_level' => 3,
'created_at' => '2016-11-18T09:29:42.634Z', 'created_at' => '2016-11-18T09:29:42.634Z',
......
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