From 6246271b0397e1419328f8fff10b956a47eb6bab Mon Sep 17 00:00:00 2001 From: Tim Meusel Date: Wed, 4 Jun 2025 20:24:51 +0200 Subject: [PATCH] voxpupuli-rubocop: Update 2.8.0->3.1.0 --- .rubocop.yml | 3 + .rubocop_todo.yml | 61 +++---------------- features/support/env.rb | 3 +- hiera-eyaml.gemspec | 6 +- lib/hiera/backend/eyaml/highlinehelper.rb | 6 +- lib/hiera/backend/eyaml/logginghelper.rb | 2 +- .../backend/eyaml/parser/encrypted_tokens.rb | 8 +-- lib/hiera/backend/eyaml/parser/token.rb | 1 - lib/hiera/backend/eyaml/plugins.rb | 1 - lib/hiera/backend/eyaml/subcommand.rb | 2 +- .../eyaml/subcommands/unknown_command.rb | 1 - .../backend/eyaml/subcommands/version.rb | 2 - lib/hiera/backend/eyaml/utils.rb | 2 +- lib/hiera/backend/eyaml_backend.rb | 2 +- 14 files changed, 24 insertions(+), 76 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index c2a2c07..da1449c 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -6,3 +6,6 @@ inherit_gem: Metrics: Enabled: false + +Style/IfUnlessModifier: + Enabled: false diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index a353392..9d53db5 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,6 +1,6 @@ # This configuration was generated by -# `rubocop --auto-gen-config` -# on 2024-10-20 14:24:21 UTC using RuboCop version 1.64.1. +# `rubocop --auto-gen-config --no-auto-gen-timestamp` +# using RuboCop version 1.75.8. # The point is for the user to remove these configuration records # one by one as the offenses are removed from the code base. # Note that changes in the inspected code, or installation of new @@ -13,14 +13,6 @@ Layout/CommentIndentation: Exclude: - 'lib/hiera/backend/eyaml/subcommands/help.rb' -# Offense count: 2 -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: EnforcedStyle. -# SupportedStyles: space, compact, no_space -Layout/SpaceInsideParens: - Exclude: - - 'lib/hiera/backend/eyaml/logginghelper.rb' - # Offense count: 1 Lint/DuplicateMethods: Exclude: @@ -45,23 +37,6 @@ Lint/RescueException: Exclude: - 'lib/hiera/backend/eyaml/subcommand.rb' -# Offense count: 1 -Lint/ShadowingOuterLocalVariable: - Exclude: - - 'lib/hiera/backend/eyaml_backend.rb' - -# Offense count: 7 -# This cop supports unsafe autocorrection (--autocorrect-all). -# Configuration parameters: AutoCorrect. -Lint/UselessAssignment: - Exclude: - - 'features/support/env.rb' - - 'lib/hiera/backend/eyaml/plugins.rb' - - 'lib/hiera/backend/eyaml/subcommand.rb' - - 'lib/hiera/backend/eyaml/subcommands/unknown_command.rb' - - 'lib/hiera/backend/eyaml/subcommands/version.rb' - - 'lib/hiera/backend/eyaml/utils.rb' - # Offense count: 1 # This cop supports unsafe autocorrection (--autocorrect-all). # Configuration parameters: AutoCorrect. @@ -74,7 +49,7 @@ Lint/UselessMethodDefinition: # Configuration parameters: AutoCorrect, CheckForMethodsWithNoSideEffects. Lint/Void: Exclude: - - 'lib/hiera/backend/eyaml/parser/token.rb' + - 'features/support/env.rb' # Offense count: 1 Naming/AccessorMethodName: @@ -107,8 +82,9 @@ Naming/HeredocDelimiterNaming: - 'lib/hiera/backend/eyaml/subcommands/unknown_command.rb' # Offense count: 1 -# Configuration parameters: EnforcedStyle, AllowedPatterns. +# Configuration parameters: EnforcedStyle, AllowedPatterns, ForbiddenIdentifiers, ForbiddenPatterns. # SupportedStyles: snake_case, camelCase +# ForbiddenIdentifiers: __id__, __send__ Naming/MethodName: Exclude: - 'lib/hiera/backend/eyaml/encryptors/pkcs7.rb' @@ -123,7 +99,7 @@ Naming/MethodParameterName: # Offense count: 1 # Configuration parameters: EnforcedStyle, CheckMethodNames, CheckSymbols, AllowedIdentifiers, AllowedPatterns. # SupportedStyles: snake_case, normalcase, non_integer -# AllowedIdentifiers: capture3, iso8601, rfc1123_date, rfc822, rfc2822, rfc3339, x86_64 +# AllowedIdentifiers: TLS1_1, TLS1_2, capture3, iso8601, rfc1123_date, rfc822, rfc2822, rfc3339, x86_64 Naming/VariableNumber: Exclude: - 'lib/hiera/backend/eyaml/utils.rb' @@ -169,14 +145,13 @@ Security/YAMLLoad: - 'features/step_definitions/decrypt_steps.rb' - 'lib/hiera/backend/eyaml_backend.rb' -# Offense count: 9 +# Offense count: 8 # This cop supports unsafe autocorrection (--autocorrect-all). # Configuration parameters: EnforcedStyle. # SupportedStyles: always, conditionals Style/AndOr: Exclude: - 'lib/hiera/backend/eyaml/encryptors/pkcs7.rb' - - 'lib/hiera/backend/eyaml/highlinehelper.rb' - 'lib/hiera/backend/eyaml/logginghelper.rb' - 'lib/hiera/backend/eyaml/subcommand.rb' - 'lib/hiera/backend/eyaml_backend.rb' @@ -220,7 +195,7 @@ Style/EnvHome: # Offense count: 10 # This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: MaxUnannotatedPlaceholdersAllowed, AllowedMethods, AllowedPatterns. +# Configuration parameters: MaxUnannotatedPlaceholdersAllowed, Mode, AllowedMethods, AllowedPatterns. # SupportedStyles: annotated, template, unannotated Style/FormatStringToken: EnforcedStyle: unannotated @@ -248,22 +223,6 @@ Style/IdenticalConditionalBranches: - 'lib/hiera/backend/eyaml/subcommands/decrypt.rb' - 'lib/hiera/backend/eyaml/subcommands/edit.rb' -# Offense count: 3 -# This cop supports safe autocorrection (--autocorrect). -Style/IfUnlessModifier: - Exclude: - - 'lib/hiera/backend/eyaml/encryptors/pkcs7.rb' - - 'lib/hiera/backend/eyaml/parser/encrypted_tokens.rb' - -# Offense count: 2 -# This cop supports unsafe autocorrection (--autocorrect-all). -# Configuration parameters: AllowedMethods. -# AllowedMethods: nonzero? -Style/IfWithBooleanLiteralBranches: - Exclude: - - 'lib/hiera/backend/eyaml/highlinehelper.rb' - - 'lib/hiera/backend/eyaml_backend.rb' - # Offense count: 1 # This cop supports unsafe autocorrection (--autocorrect-all). Style/MapIntoArray: @@ -408,9 +367,9 @@ Style/ZeroLengthPredicate: Exclude: - 'lib/hiera/backend/eyaml/parser/parser.rb' -# Offense count: 11 +# Offense count: 13 # This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, AllowedPatterns. +# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, AllowedPatterns, SplitStrings. # URISchemes: http, https Layout/LineLength: Max: 194 diff --git a/features/support/env.rb b/features/support/env.rb index 4bcac1b..bdc4ad7 100644 --- a/features/support/env.rb +++ b/features/support/env.rb @@ -15,8 +15,7 @@ Dir.glob('features/sandbox/**/*', File::FNM_DOTMATCH).each do |file_name| next unless File.file? file_name - read_mode = 'r' - read_mode = 'rb' if /\.bin$/.match?(file_name) + 'rb' if /\.bin$/.match?(file_name) file = File.open(file_name, 'r') file_contents = file.read file.close diff --git a/hiera-eyaml.gemspec b/hiera-eyaml.gemspec index 7a35ef3..c0075d4 100644 --- a/hiera-eyaml.gemspec +++ b/hiera-eyaml.gemspec @@ -16,12 +16,12 @@ Gem::Specification.new do |gem| gem.executables = gem.files.grep(%r{^bin/}).map { |f| File.basename(f) } gem.require_paths = ['lib'] - gem.add_runtime_dependency 'highline', '>= 2.1', '< 4' - gem.add_runtime_dependency 'optimist', '~> 3.1' + gem.add_dependency 'highline', '>= 2.1', '< 4' + gem.add_dependency 'optimist', '~> 3.1' gem.add_development_dependency 'rake', '~> 13.2', '>= 13.2.1' gem.add_development_dependency 'rspec-expectations', '~> 3.13' - gem.add_development_dependency 'voxpupuli-rubocop', '~> 2.8.0' + gem.add_development_dependency 'voxpupuli-rubocop', '~> 3.1.0' gem.required_ruby_version = '>= 2.7', ' < 4' end diff --git a/lib/hiera/backend/eyaml/highlinehelper.rb b/lib/hiera/backend/eyaml/highlinehelper.rb index 7938aeb..8ada493 100644 --- a/lib/hiera/backend/eyaml/highlinehelper.rb +++ b/lib/hiera/backend/eyaml/highlinehelper.rb @@ -10,11 +10,7 @@ def self.read_password def self.confirm?(message) result = ask("#{message} (y/N): ") - if result.downcase == 'y' or result.downcase == 'yes' - true - else - false - end + %w[y yes].include?(result.downcase) || false end end end diff --git a/lib/hiera/backend/eyaml/logginghelper.rb b/lib/hiera/backend/eyaml/logginghelper.rb index 4993de6..c7d68fd 100644 --- a/lib/hiera/backend/eyaml/logginghelper.rb +++ b/lib/hiera/backend/eyaml/logginghelper.rb @@ -50,7 +50,7 @@ def self.print_message(args) if hiera? Hiera.send(hiera_loglevel, message) if threshold.nil? or Eyaml.verbosity_level > threshold elsif threshold.nil? or Eyaml.verbosity_level > threshold - STDERR.puts self.colorize( message, cli_color ) + STDERR.puts self.colorize(message, cli_color) end end diff --git a/lib/hiera/backend/eyaml/parser/encrypted_tokens.rb b/lib/hiera/backend/eyaml/parser/encrypted_tokens.rb index 29133df..5a4554e 100644 --- a/lib/hiera/backend/eyaml/parser/encrypted_tokens.rb +++ b/lib/hiera/backend/eyaml/parser/encrypted_tokens.rb @@ -146,9 +146,7 @@ def initialize def create_token(string) md = @regex.match(string) - if EncToken.encrypt_unchanged == false && !md[1].nil? && (md[3] == EncToken.tokens_map[md[1]]) - return EncToken.plain_text_value(:string, md[3], md[2], string, md[1]) - end + return EncToken.plain_text_value(:string, md[3], md[2], string, md[1]) if EncToken.encrypt_unchanged == false && !md[1].nil? && (md[3] == EncToken.tokens_map[md[1]]) EncToken.decrypted_value(:string, md[3], md[2], string, md[1]) end @@ -161,9 +159,7 @@ def initialize def create_token(string) md = @regex.match(string) - if EncToken.encrypt_unchanged == false && !md[2].nil? && (md[4] == EncToken.tokens_map[md[2]]) - return EncToken.plain_text_value(:string, md[4], md[3], string, md[2]) - end + return EncToken.plain_text_value(:string, md[4], md[3], string, md[2]) if EncToken.encrypt_unchanged == false && !md[2].nil? && (md[4] == EncToken.tokens_map[md[2]]) EncToken.decrypted_value(:block, md[4], md[3], string, md[2], md[1]) end diff --git a/lib/hiera/backend/eyaml/parser/token.rb b/lib/hiera/backend/eyaml/parser/token.rb index 997c6dc..314dc4f 100644 --- a/lib/hiera/backend/eyaml/parser/token.rb +++ b/lib/hiera/backend/eyaml/parser/token.rb @@ -5,7 +5,6 @@ module Parser class TokenType attr_reader :regex - @regex def create_token(_string) raise 'Abstract method called' end diff --git a/lib/hiera/backend/eyaml/plugins.rb b/lib/hiera/backend/eyaml/plugins.rb index f034b09..c4d5d31 100644 --- a/lib/hiera/backend/eyaml/plugins.rb +++ b/lib/hiera/backend/eyaml/plugins.rb @@ -37,7 +37,6 @@ def self.find dependency = spec.dependencies.find { |d| d.name == 'hiera-eyaml' } next if dependency && !dependency.requirement.satisfied_by?(this_version) - file = nil file = if gem_version >= Gem::Version.new('1.8.0') spec.matches_for_glob('**/eyaml_init.rb').first else diff --git a/lib/hiera/backend/eyaml/subcommand.rb b/lib/hiera/backend/eyaml/subcommand.rb index efab19e..a6ac095 100644 --- a/lib/hiera/backend/eyaml/subcommand.rb +++ b/lib/hiera/backend/eyaml/subcommand.rb @@ -86,7 +86,7 @@ def self.attach_option(opt) def self.find(commandname = 'unknown_command') begin require "hiera/backend/eyaml/subcommands/#{commandname.downcase}" - rescue Exception => e + rescue Exception require 'hiera/backend/eyaml/subcommands/unknown_command' return Hiera::Backend::Eyaml::Subcommands::UnknownCommand end diff --git a/lib/hiera/backend/eyaml/subcommands/unknown_command.rb b/lib/hiera/backend/eyaml/subcommands/unknown_command.rb index 2613b55..dda2ba2 100644 --- a/lib/hiera/backend/eyaml/subcommands/unknown_command.rb +++ b/lib/hiera/backend/eyaml/subcommands/unknown_command.rb @@ -20,7 +20,6 @@ def self.description end def self.execute - subcommands = Eyaml.subcommands puts <<~EOS Unknown subcommand#{': ' + Eyaml.subcommand if Eyaml.subcommand} diff --git a/lib/hiera/backend/eyaml/subcommands/version.rb b/lib/hiera/backend/eyaml/subcommands/version.rb index 1865e86..b32e1c8 100644 --- a/lib/hiera/backend/eyaml/subcommands/version.rb +++ b/lib/hiera/backend/eyaml/subcommands/version.rb @@ -15,8 +15,6 @@ def self.description end def self.execute - plugin_versions = {} - Eyaml::LoggingHelper.info "hiera-eyaml (core): #{Eyaml::VERSION}" Plugins.plugins.each do |plugin| diff --git a/lib/hiera/backend/eyaml/utils.rb b/lib/hiera/backend/eyaml/utils.rb index 9d7b89a..05f12f1 100644 --- a/lib/hiera/backend/eyaml/utils.rb +++ b/lib/hiera/backend/eyaml/utils.rb @@ -60,7 +60,7 @@ def self.convert_to_utf_8(string) return string if orig_encoding == Encoding::UTF_8 string.dup.force_encoding(Encoding::UTF_8) - rescue EncodingError => e + rescue EncodingError warn "Unable to encode to \"Encoding::UTF_8\" using the original \"#{orig_encoding}\"" string end diff --git a/lib/hiera/backend/eyaml_backend.rb b/lib/hiera/backend/eyaml_backend.rb index 6416e3a..c5bf3df 100644 --- a/lib/hiera/backend/eyaml_backend.rb +++ b/lib/hiera/backend/eyaml_backend.rb @@ -105,7 +105,7 @@ def decrypt(data) end def encrypted?(data) - /.*ENC\[.*\]/.match?(data) ? true : false + /.*ENC\[.*\]/.match?(data) || false end def parse_answer(data, scope, extra_data = {})