From 8856702f3f83570ac466dc016b3aba005f8b3949 Mon Sep 17 00:00:00 2001 From: Tim Smith Date: Fri, 31 Dec 2021 23:37:21 -0500 Subject: Resolve Style/SelectByRegexp warnings Simplify how we collect or reject data based on regex matches Signed-off-by: Tim Smith --- chef-config/lib/chef-config/config.rb | 2 +- knife/lib/chef/knife/acl_bulk_add.rb | 2 +- knife/lib/chef/knife/acl_bulk_remove.rb | 2 +- knife/lib/chef/knife/core/subcommand_loader.rb | 2 +- knife/spec/knife_spec_helper.rb | 4 ++-- lib/chef/cookbook/syntax_check.rb | 2 +- spec/spec_helper.rb | 6 +++--- 7 files changed, 10 insertions(+), 10 deletions(-) diff --git a/chef-config/lib/chef-config/config.rb b/chef-config/lib/chef-config/config.rb index 3eb8c8475c..4700a687ee 100644 --- a/chef-config/lib/chef-config/config.rb +++ b/chef-config/lib/chef-config/config.rb @@ -1223,7 +1223,7 @@ module ChefConfig "en.UTF-8" else # Will match en_ZZ.UTF-8, en_ZZ.utf-8, en_ZZ.UTF8, en_ZZ.utf8 - guesses = locales.select { |l| l =~ /^en_.*UTF-?8$/i } + guesses = locales.grep(/^en_.*UTF-?8$/i) unless guesses.empty? guessed_locale = guesses.first # Transform into the form en_ZZ.UTF-8 diff --git a/knife/lib/chef/knife/acl_bulk_add.rb b/knife/lib/chef/knife/acl_bulk_add.rb index 4992fe2afa..bdd2e0fdc4 100644 --- a/knife/lib/chef/knife/acl_bulk_add.rb +++ b/knife/lib/chef/knife/acl_bulk_add.rb @@ -56,7 +56,7 @@ class Chef objects_to_modify = [] all_objects = rest.get_rest(object_type) - objects_to_modify = all_objects.keys.select { |object_name| object_name =~ object_name_matcher } + objects_to_modify = all_objects.keys.grep(object_name_matcher) if objects_to_modify.empty? ui.info "No #{object_type} match the expression /#{regex}/" diff --git a/knife/lib/chef/knife/acl_bulk_remove.rb b/knife/lib/chef/knife/acl_bulk_remove.rb index 0f35f1e2fb..fce76f250d 100644 --- a/knife/lib/chef/knife/acl_bulk_remove.rb +++ b/knife/lib/chef/knife/acl_bulk_remove.rb @@ -61,7 +61,7 @@ class Chef objects_to_modify = [] all_objects = rest.get_rest(object_type) - objects_to_modify = all_objects.keys.select { |object_name| object_name =~ object_name_matcher } + objects_to_modify = all_objects.keys.grep(object_name_matcher) if objects_to_modify.empty? ui.info "No #{object_type} match the expression /#{regex}/" diff --git a/knife/lib/chef/knife/core/subcommand_loader.rb b/knife/lib/chef/knife/core/subcommand_loader.rb index ca7bfcd008..d70ba11a59 100644 --- a/knife/lib/chef/knife/core/subcommand_loader.rb +++ b/knife/lib/chef/knife/core/subcommand_loader.rb @@ -184,7 +184,7 @@ class Chef # @return [Array] # def positional_arguments(args) - args.select { |arg| arg =~ /^(([[:alnum:]])[[:alnum:]\_\-]+)$/ } + args.grep(/^(([[:alnum:]])[[:alnum:]\_\-]+)$/) end # Returns an Array of paths to knife commands located in diff --git a/knife/spec/knife_spec_helper.rb b/knife/spec/knife_spec_helper.rb index 7395d2759b..5a3c0761d5 100644 --- a/knife/spec/knife_spec_helper.rb +++ b/knife/spec/knife_spec_helper.rb @@ -78,8 +78,8 @@ require "spec/support/shared/matchers/match_environment_variable" # Excludes support/platforms by default # Do not change the gsub. Dir["spec/support/**/*.rb"] - .reject { |f| f =~ %r{^spec/support/platforms} } - .reject { |f| f =~ %r{^spec/support/pedant} } + .grep_v(%r{^spec/support/platforms}) + .grep_v(%r{^spec/support/pedant}) .map { |f| f.gsub(/.rb$/, "") } .map { |f| f.gsub(%r{spec/}, "") } .each { |f| require f } diff --git a/lib/chef/cookbook/syntax_check.rb b/lib/chef/cookbook/syntax_check.rb index 8b593eea81..555d2f6715 100644 --- a/lib/chef/cookbook/syntax_check.rb +++ b/lib/chef/cookbook/syntax_check.rb @@ -113,7 +113,7 @@ class Chef end def remove_uninteresting_ruby_files(file_list) - file_list.reject { |f| f =~ %r{#{Regexp.quote(cookbook_path)}/(files|templates)/} } + file_list.grep_v(%r{#{Regexp.quote(cookbook_path)}/(files|templates)/}) end def ruby_files diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 60b608e4ff..5cd04437be 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -78,9 +78,9 @@ require "spec/support/recipe_dsl_helper" # Excludes support/platforms by default # Do not change the gsub. Dir["spec/support/**/*.rb"] - .reject { |f| f =~ %r{^spec/support/platforms} } - .reject { |f| f =~ %r{^spec/support/pedant} } - .reject { |f| f =~ %r{^spec/support/shared/integration/knife_support} } + .grep_v(%r{^spec/support/platforms}) + .grep_v(%r{^spec/support/pedant}) + .grep_v(%r{^spec/support/shared/integration/knife_support}) .map { |f| f.gsub(/.rb$/, "") } .map { |f| f.gsub(%r{spec/}, "") } .each { |f| require f } -- cgit v1.2.1