summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Smith <tsmith84@gmail.com>2021-12-31 23:37:21 -0500
committerTim Smith <tsmith84@gmail.com>2021-12-31 23:37:21 -0500
commit8856702f3f83570ac466dc016b3aba005f8b3949 (patch)
treef4309fbdfbef78e740aa7127634092f0ddfeb7fd
parentbb6116d12fbc75dbb3d1daa36b8413b1bc6638d1 (diff)
downloadchef-Style_SelectByRegexp.tar.gz
Resolve Style/SelectByRegexp warningsStyle_SelectByRegexp
Simplify how we collect or reject data based on regex matches Signed-off-by: Tim Smith <tsmith@chef.io>
-rw-r--r--chef-config/lib/chef-config/config.rb2
-rw-r--r--knife/lib/chef/knife/acl_bulk_add.rb2
-rw-r--r--knife/lib/chef/knife/acl_bulk_remove.rb2
-rw-r--r--knife/lib/chef/knife/core/subcommand_loader.rb2
-rw-r--r--knife/spec/knife_spec_helper.rb4
-rw-r--r--lib/chef/cookbook/syntax_check.rb2
-rw-r--r--spec/spec_helper.rb6
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<String>]
#
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 }