From 287adc668b81ea45cad5f697636a52c2c856f083 Mon Sep 17 00:00:00 2001 From: Archana Kumari <32739028+archanaserver@users.noreply.github.com> Date: Fri, 19 Jul 2024 02:21:36 +0530 Subject: [PATCH] Fix Various Lint Cops (#11069) * Fix Lint/DuplicateRequire cop * Fix Lint/UnreachableLoop cop * Fix Lint/EmptyFile cop * Fix Lint/RedundantSafeNavigation cop * Fix Lint/DeprecatedOpenSSLConstant cop * Update .rubocop.yml --- .rubocop.yml | 3 +++ app/controllers/katello/application_controller.rb | 2 +- app/lib/actions/katello/host/hypervisors_update.rb | 2 ++ app/models/katello/candlepin/repository_mapper.rb | 2 +- app/views/katello/api/v2/repository_sets/show.json.rabl | 2 +- lib/katello.rb | 2 -- test/actions/katello/cdn_configuration/update_test.rb | 2 +- test/factories/content_credential_factory.rb | 2 +- test/models/concerns/container_extensions_test.rb | 0 test/models/rhsm_fact_parser_test.rb | 0 test/services/katello/pxe_files_downloader_test.rb | 2 +- 11 files changed, 11 insertions(+), 8 deletions(-) delete mode 100644 test/models/concerns/container_extensions_test.rb delete mode 100644 test/models/rhsm_fact_parser_test.rb diff --git a/.rubocop.yml b/.rubocop.yml index 4abe8e9b7b1..de1be94cf3d 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -191,3 +191,6 @@ Style/GlobalStdStream: Style/RedundantFileExtensionInRequire: Enabled: false + +Lint/MixedRegexpCaptureTypes: + Enabled: false diff --git a/app/controllers/katello/application_controller.rb b/app/controllers/katello/application_controller.rb index 22786486cd2..8732a0c31b9 100644 --- a/app/controllers/katello/application_controller.rb +++ b/app/controllers/katello/application_controller.rb @@ -108,7 +108,7 @@ def render_bad_parameters(*args) exception = args.find { |o| o.is_a? Exception } message = args.find { |o| o.is_a? String } || exception.try(:message) || default_message - status = if exception&.respond_to?(:status_code) + status = if exception.respond_to?(:status_code) exception.status_code else 400 diff --git a/app/lib/actions/katello/host/hypervisors_update.rb b/app/lib/actions/katello/host/hypervisors_update.rb index dbe61d7e075..c16ee2b8511 100644 --- a/app/lib/actions/katello/host/hypervisors_update.rb +++ b/app/lib/actions/katello/host/hypervisors_update.rb @@ -33,6 +33,8 @@ def run end end + return if @duplicate_uuid_hypervisors.empty? + @duplicate_uuid_hypervisors.each do |hypervisor, existing_host| fail _("Host creation was skipped for %s because it shares a BIOS UUID with %s. " \ "To report this hypervisor, override its dmi.system.uuid fact or set 'candlepin.use_system_uuid_for_matching' " \ diff --git a/app/models/katello/candlepin/repository_mapper.rb b/app/models/katello/candlepin/repository_mapper.rb index 2e9cfa0e07a..c56d59f3f08 100644 --- a/app/models/katello/candlepin/repository_mapper.rb +++ b/app/models/katello/candlepin/repository_mapper.rb @@ -83,7 +83,7 @@ def prune_substitutions(subs, url) def feed_url return if product.organization.cdn_configuration.export_sync? - @feed_url ||= if product.cdn_resource&.respond_to?(:repository_url) + @feed_url ||= if product.cdn_resource.respond_to?(:repository_url) product.cdn_resource.repository_url(content_label: content.label, arch: arch, major: version[:major], minor: version[:minor]) else product.repo_url(path) diff --git a/app/views/katello/api/v2/repository_sets/show.json.rabl b/app/views/katello/api/v2/repository_sets/show.json.rabl index 1bdf2205760..7b044d813be 100644 --- a/app/views/katello/api/v2/repository_sets/show.json.rabl +++ b/app/views/katello/api/v2/repository_sets/show.json.rabl @@ -65,7 +65,7 @@ node :enabled_content_override do |pc| end node :redhat do |pc| - if pc&.product&.respond_to? :redhat? + if pc&.product.respond_to? :redhat? pc.product.redhat? end end diff --git a/lib/katello.rb b/lib/katello.rb index 8b9b1f1c20e..0b694b3b9d6 100644 --- a/lib/katello.rb +++ b/lib/katello.rb @@ -12,8 +12,6 @@ require "deface" -require "securerandom" - # to make Foreman#in_rake? helper available if Foreman's lib is available lib_foreman = File.expand_path('lib/foreman', Rails.root) require lib_foreman if Dir.exist?(lib_foreman) diff --git a/test/actions/katello/cdn_configuration/update_test.rb b/test/actions/katello/cdn_configuration/update_test.rb index 0e1a87cab22..a92e8d2c780 100644 --- a/test/actions/katello/cdn_configuration/update_test.rb +++ b/test/actions/katello/cdn_configuration/update_test.rb @@ -22,7 +22,7 @@ def keypair cert.public_key = key.public_key cert.not_before = Time.now cert.not_after = Time.now + 1000 - cert.sign key, OpenSSL::Digest::SHA256.new + cert.sign key, OpenSSL::Digest.new('SHA256') { cert: cert, diff --git a/test/factories/content_credential_factory.rb b/test/factories/content_credential_factory.rb index 562df052da6..6fc9cc9e43a 100644 --- a/test/factories/content_credential_factory.rb +++ b/test/factories/content_credential_factory.rb @@ -6,7 +6,7 @@ cert.public_key = key.public_key cert.not_before = Time.now cert.not_after = Time.now + 1000 - cert.sign key, OpenSSL::Digest::SHA256.new + cert.sign key, OpenSSL::Digest.new('SHA256') cert.to_pem end diff --git a/test/models/concerns/container_extensions_test.rb b/test/models/concerns/container_extensions_test.rb deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/test/models/rhsm_fact_parser_test.rb b/test/models/rhsm_fact_parser_test.rb deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/test/services/katello/pxe_files_downloader_test.rb b/test/services/katello/pxe_files_downloader_test.rb index d90d1cbca75..33a936382d5 100644 --- a/test/services/katello/pxe_files_downloader_test.rb +++ b/test/services/katello/pxe_files_downloader_test.rb @@ -46,7 +46,7 @@ def generate_certificate cert.add_extension ef.create_extension("authorityKeyIdentifier", "keyid:always,issuer:always") - cert.sign key, OpenSSL::Digest::SHA1.new + cert.sign key, OpenSSL::Digest.new('SHA1') cert.to_pem end