From f524b1998385a83ac4b98205e6d573fca3009229 Mon Sep 17 00:00:00 2001 From: Gavin Didrichsen Date: Mon, 4 Dec 2023 16:14:11 +0000 Subject: [PATCH] (maint) Fix rubocop lint warnings Signed-off-by: Gavin Didrichsen --- lib/pdk/cli/util/option_normalizer.rb | 2 +- lib/pdk/config/namespace.rb | 4 +++- lib/pdk/report.rb | 10 +++++++--- lib/pdk/util.rb | 2 +- lib/pdk/util/puppet_version.rb | 6 +++++- spec/support/file_based_namespaces.rb | 2 +- spec/support/validators.rb | 2 +- 7 files changed, 19 insertions(+), 9 deletions(-) diff --git a/lib/pdk/cli/util/option_normalizer.rb b/lib/pdk/cli/util/option_normalizer.rb index d8680581b..a170438b1 100644 --- a/lib/pdk/cli/util/option_normalizer.rb +++ b/lib/pdk/cli/util/option_normalizer.rb @@ -44,7 +44,7 @@ def self.report_formats(formats) target = PDK::Report.default_target end - { method: "write_#{format}".to_sym, target: target } + { method: "write_#{format}", target: target } end end end diff --git a/lib/pdk/config/namespace.rb b/lib/pdk/config/namespace.rb index 712840951..c09e5087d 100644 --- a/lib/pdk/config/namespace.rb +++ b/lib/pdk/config/namespace.rb @@ -217,7 +217,9 @@ def include_in_parent? # @api private def read_only! @read_only = true - @mounts.each { |_, child| child.read_only! } + # pass the read_only! method as a block to the each_value method. This means that + # for each value in the @mounts hash, the read_only! method will be called on that value. + @mounts.each_value(&:read_only!) end private diff --git a/lib/pdk/report.rb b/lib/pdk/report.rb index 4bea9e1c8..49b433f54 100644 --- a/lib/pdk/report.rb +++ b/lib/pdk/report.rb @@ -93,13 +93,17 @@ def write_junit(target = self.class.default_target) # This report is designed for interactive use by a human and so excludes # all passing events in order to be consise. # - # @param target [#write] an IO object that the report will be written to. - # Defaults to PDK::Report.default_target. + # @param target [String, IO] The IO target to write the report to. + # If a String is provided, the report will be written to a file with the given path. + # If an IO object is provided, the report will be written to the IO object. + # If no target is provided, the default target PDK::Report.default_target will be used. + # + # @return [void] def write_text(target = self.class.default_target) coverage_report = nil report = [] - events.each do |_tool, tool_events| + events.each_value do |tool_events| tool_events.each do |event| if event.rspec_puppet_coverage? coverage_report = event.to_text diff --git a/lib/pdk/util.rb b/lib/pdk/util.rb index c649d5839..9b8e7de2d 100644 --- a/lib/pdk/util.rb +++ b/lib/pdk/util.rb @@ -95,7 +95,7 @@ def package_install? def development_mode? require 'pdk/util/version' - (!PDK::Util::Version.git_ref.nil? || PDK::VERSION.end_with?('.pre')) + !PDK::Util::Version.git_ref.nil? || PDK::VERSION.end_with?('.pre') end module_function :development_mode? diff --git a/lib/pdk/util/puppet_version.rb b/lib/pdk/util/puppet_version.rb index 14f83108b..8bf055656 100644 --- a/lib/pdk/util/puppet_version.rb +++ b/lib/pdk/util/puppet_version.rb @@ -206,10 +206,14 @@ def find_in_rubygems(requirement) version.nil? ? nil : { gem_version: version, ruby_version: PDK::Util::RubyVersion.default_ruby_version } end + # Finds the specified requirement in the package cache. + # + # @param requirement [Gem::Requirement] The requirement to search for. + # @return [Hash] A hash containing the gem version and ruby version if found, or nil if not found. def find_in_package_cache(requirement) require 'pdk/util/ruby_version' - PDK::Util::RubyVersion.versions.each do |ruby_version, _| + PDK::Util::RubyVersion.versions.each_key do |ruby_version| PDK::Util::RubyVersion.use(ruby_version) version = PDK::Util::RubyVersion.available_puppet_versions.find { |r| requirement.satisfied_by?(r) } return { gem_version: version, ruby_version: ruby_version } unless version.nil? diff --git a/spec/support/file_based_namespaces.rb b/spec/support/file_based_namespaces.rb index a99acb5c1..6f84bf09a 100644 --- a/spec/support/file_based_namespaces.rb +++ b/spec/support/file_based_namespaces.rb @@ -50,7 +50,7 @@ it 'does not add or lose any data when round tripping the serialization' do # Force the file to be loaded - expected_settings.each { |k, _| subject[k] } + expected_settings.each_key { |k| subject[k] } # Force a setting to be saved by setting a single known value expect(PDK::Util::Filesystem).to receive(:write_file).with(subject.file, content) key = expected_settings.keys[0] diff --git a/spec/support/validators.rb b/spec/support/validators.rb index 26fc0f313..f12ec19ea 100644 --- a/spec/support/validators.rb +++ b/spec/support/validators.rb @@ -74,7 +74,7 @@ def invoke(report) RSpec::Matchers.define :have_number_of_events do |state, expected_count| def get_event_count(report, state) count = 0 - report.events.each do |_source, events| + report.events.each_value do |events| count += events.count { |event| event.state == state } end