summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorTim Smith <tsmith@chef.io>2020-10-30 11:53:44 -0700
committerGitHub <noreply@github.com>2020-10-30 11:53:44 -0700
commit7cf56f572fc2705d1258e84f0e0c44802739f0be (patch)
tree04ea729446f724bd73a1168dccaeb3778cdcb10f /lib
parentf1d97705b51c6ef0d460d92752bd77eca029f3a7 (diff)
parent6317fe5cc33d1879a1f3243d877a3ef1570c9a8d (diff)
downloadchef-7cf56f572fc2705d1258e84f0e0c44802739f0be.tar.gz
Merge pull request #10584 from chef/simplify_regex
Signed-off-by: Tim Smith <tsmith@chef.io>
Diffstat (limited to 'lib')
-rw-r--r--lib/chef/environment.rb2
-rw-r--r--lib/chef/formatters/error_inspectors/compile_error_inspector.rb4
-rw-r--r--lib/chef/formatters/error_inspectors/resource_failure_inspector.rb8
-rw-r--r--lib/chef/knife/core/cookbook_scm_repo.rb2
-rw-r--r--lib/chef/knife/core/gem_glob_loader.rb2
-rw-r--r--lib/chef/mixin/unformatter.rb2
-rw-r--r--lib/chef/provider/package/rubygems.rb2
-rw-r--r--lib/chef/provider/package/yum/rpm_utils.rb2
-rw-r--r--lib/chef/run_lock.rb2
9 files changed, 13 insertions, 13 deletions
diff --git a/lib/chef/environment.rb b/lib/chef/environment.rb
index d6a2215423..e651e1b4aa 100644
--- a/lib/chef/environment.rb
+++ b/lib/chef/environment.rb
@@ -35,7 +35,7 @@ class Chef
include Chef::Mixin::ParamsValidate
include Chef::Mixin::FromFile
- COMBINED_COOKBOOK_CONSTRAINT = /(.+)(?:[\s]+)((?:#{Chef::VersionConstraint::OPS.join('|')})(?:[\s]+).+)$/.freeze
+ COMBINED_COOKBOOK_CONSTRAINT = /(.+)(?:\s+)((?:#{Chef::VersionConstraint::OPS.join('|')})(?:\s+).+)$/.freeze
def initialize(chef_server_rest: nil)
@name = ""
diff --git a/lib/chef/formatters/error_inspectors/compile_error_inspector.rb b/lib/chef/formatters/error_inspectors/compile_error_inspector.rb
index d765e66e7a..e42340ff3a 100644
--- a/lib/chef/formatters/error_inspectors/compile_error_inspector.rb
+++ b/lib/chef/formatters/error_inspectors/compile_error_inspector.rb
@@ -115,14 +115,14 @@ class Chef
def culprit_line
@culprit_line ||= begin
- line_number = culprit_backtrace_entry[/^(?:.\:)?[^:]+:([\d]+)/, 1].to_i
+ line_number = culprit_backtrace_entry[/^(?:.\:)?[^:]+:(\d+)/, 1].to_i
Chef::Log.trace("Line number of compile error: '#{line_number}'")
line_number
end
end
def culprit_file
- @culprit_file ||= culprit_backtrace_entry[/^((?:.\:)?[^:]+):([\d]+)/, 1]
+ @culprit_file ||= culprit_backtrace_entry[/^((?:.\:)?[^:]+):(\d+)/, 1]
end
def filtered_bt
diff --git a/lib/chef/formatters/error_inspectors/resource_failure_inspector.rb b/lib/chef/formatters/error_inspectors/resource_failure_inspector.rb
index d858c756a4..905a438f56 100644
--- a/lib/chef/formatters/error_inspectors/resource_failure_inspector.rb
+++ b/lib/chef/formatters/error_inspectors/resource_failure_inspector.rb
@@ -79,8 +79,8 @@ class Chef
loop do
# low rent parser. try to gracefully handle nested blocks in resources
- nesting += 1 if /[\s]+do[\s]*/.match?(lines[current_line])
- nesting -= 1 if /end[\s]*$/.match?(lines[current_line])
+ nesting += 1 if /\s+do\s*/.match?(lines[current_line])
+ nesting -= 1 if /end\s*$/.match?(lines[current_line])
relevant_lines << format_line(current_line, lines[current_line])
@@ -114,11 +114,11 @@ class Chef
end
def parse_source
- resource.source_line[/^(([\w]:)?[^:]+):([\d]+)/, 1]
+ resource.source_line[/^((\w:)?[^:]+):(\d+)/, 1]
end
def parse_line(source)
- resource.source_line[/^#{Regexp.escape(source)}:([\d]+)/, 1].to_i
+ resource.source_line[/^#{Regexp.escape(source)}:(\d+)/, 1].to_i
end
end
diff --git a/lib/chef/knife/core/cookbook_scm_repo.rb b/lib/chef/knife/core/cookbook_scm_repo.rb
index 31654d2954..ba194a8a6d 100644
--- a/lib/chef/knife/core/cookbook_scm_repo.rb
+++ b/lib/chef/knife/core/cookbook_scm_repo.rb
@@ -22,7 +22,7 @@ class Chef
class Knife
class CookbookSCMRepo
- DIRTY_REPO = /^[\s]+M/.freeze
+ DIRTY_REPO = /^\s+M/.freeze
include Chef::Mixin::ShellOut
diff --git a/lib/chef/knife/core/gem_glob_loader.rb b/lib/chef/knife/core/gem_glob_loader.rb
index b29df38c86..d058379e71 100644
--- a/lib/chef/knife/core/gem_glob_loader.rb
+++ b/lib/chef/knife/core/gem_glob_loader.rb
@@ -22,7 +22,7 @@ class Chef
class Knife
class SubcommandLoader
class GemGlobLoader < Chef::Knife::SubcommandLoader
- MATCHES_CHEF_GEM ||= %r{/chef-[\d]+\.[\d]+\.[\d]+}.freeze
+ MATCHES_CHEF_GEM ||= %r{/chef-\d+\.\d+\.\d+}.freeze
MATCHES_THIS_CHEF_GEM ||= %r{/chef-#{Chef::VERSION}(-\w+)?(-\w+)?/}.freeze
def subcommand_files
diff --git a/lib/chef/mixin/unformatter.rb b/lib/chef/mixin/unformatter.rb
index fbe1bdccb4..c233549b17 100644
--- a/lib/chef/mixin/unformatter.rb
+++ b/lib/chef/mixin/unformatter.rb
@@ -21,7 +21,7 @@ class Chef
module Unformatter
def write(message)
- data = message.match(/(\[.+?\] )?([\w]+):(.*)$/)
+ data = message.match(/(\[.+?\] )?(\w+):(.*)$/)
send(data[2].downcase.chomp.to_sym, data[3].strip)
rescue NoMethodError
send(:info, message)
diff --git a/lib/chef/provider/package/rubygems.rb b/lib/chef/provider/package/rubygems.rb
index 8aba495c4c..9ac1e7d31b 100644
--- a/lib/chef/provider/package/rubygems.rb
+++ b/lib/chef/provider/package/rubygems.rb
@@ -427,7 +427,7 @@ class Chef
logger.trace("#{new_resource} detected omnibus installation in #{RbConfig::CONFIG["bindir"]}")
# Omnibus installs to a static path because of linking on unix, find it.
true
- elsif RbConfig::CONFIG["bindir"].sub(/^[\w]:/, "") == "/opscode/chef/embedded/bin"
+ elsif RbConfig::CONFIG["bindir"].sub(/^\w:/, "") == "/opscode/chef/embedded/bin"
logger.trace("#{new_resource} detected omnibus installation in #{RbConfig::CONFIG["bindir"]}")
# windows, with the drive letter removed
true
diff --git a/lib/chef/provider/package/yum/rpm_utils.rb b/lib/chef/provider/package/yum/rpm_utils.rb
index b2a24abb1c..7514d57bce 100644
--- a/lib/chef/provider/package/yum/rpm_utils.rb
+++ b/lib/chef/provider/package/yum/rpm_utils.rb
@@ -46,7 +46,7 @@ class Chef
lead = 0
tail = evr.size
- if /^([\d]+):/.match(evr) # rubocop:disable Performance/RedundantMatch
+ if /^(\d+):/.match(evr) # rubocop:disable Performance/RedundantMatch
epoch = $1.to_i
lead = $1.length + 1
elsif evr[0].ord == ":".ord
diff --git a/lib/chef/run_lock.rb b/lib/chef/run_lock.rb
index 75d1432773..416147a9e0 100644
--- a/lib/chef/run_lock.rb
+++ b/lib/chef/run_lock.rb
@@ -173,7 +173,7 @@ class Chef
# Mutex name is case-sensitive contrary to other things in
# windows. "\" is the only invalid character.
def acquire_win32_mutex
- @mutex = Chef::ReservedNames::Win32::Mutex.new("Global\\#{runlock_file.gsub(/[\\]/, "/").downcase}")
+ @mutex = Chef::ReservedNames::Win32::Mutex.new("Global\\#{runlock_file.gsub(/\\/, "/").downcase}")
mutex.test
end