diff options
author | Tim Smith <tsmith@chef.io> | 2020-10-30 11:53:44 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-10-30 11:53:44 -0700 |
commit | 7cf56f572fc2705d1258e84f0e0c44802739f0be (patch) | |
tree | 04ea729446f724bd73a1168dccaeb3778cdcb10f | |
parent | f1d97705b51c6ef0d460d92752bd77eca029f3a7 (diff) | |
parent | 6317fe5cc33d1879a1f3243d877a3ef1570c9a8d (diff) | |
download | chef-7cf56f572fc2705d1258e84f0e0c44802739f0be.tar.gz |
Merge pull request #10584 from chef/simplify_regex
Signed-off-by: Tim Smith <tsmith@chef.io>
-rw-r--r-- | chef-config/lib/chef-config/workstation_config_loader.rb | 6 | ||||
-rw-r--r-- | lib/chef/environment.rb | 2 | ||||
-rw-r--r-- | lib/chef/formatters/error_inspectors/compile_error_inspector.rb | 4 | ||||
-rw-r--r-- | lib/chef/formatters/error_inspectors/resource_failure_inspector.rb | 8 | ||||
-rw-r--r-- | lib/chef/knife/core/cookbook_scm_repo.rb | 2 | ||||
-rw-r--r-- | lib/chef/knife/core/gem_glob_loader.rb | 2 | ||||
-rw-r--r-- | lib/chef/mixin/unformatter.rb | 2 | ||||
-rw-r--r-- | lib/chef/provider/package/rubygems.rb | 2 | ||||
-rw-r--r-- | lib/chef/provider/package/yum/rpm_utils.rb | 2 | ||||
-rw-r--r-- | lib/chef/run_lock.rb | 2 | ||||
-rw-r--r-- | spec/functional/resource/apt_package_spec.rb | 6 | ||||
-rw-r--r-- | spec/unit/knife/configure_spec.rb | 6 | ||||
-rw-r--r-- | spec/unit/resource/breakpoint_spec.rb | 2 | ||||
-rw-r--r-- | spec/unit/shell_spec.rb | 4 |
14 files changed, 25 insertions, 25 deletions
diff --git a/chef-config/lib/chef-config/workstation_config_loader.rb b/chef-config/lib/chef-config/workstation_config_loader.rb index bbec74911b..ea42211120 100644 --- a/chef-config/lib/chef-config/workstation_config_loader.rb +++ b/chef-config/lib/chef-config/workstation_config_loader.rb @@ -195,8 +195,8 @@ module ChefConfig message = "" message << "You have invalid ruby syntax in your config file #{config_file_path}\n\n" message << "#{e.class.name}: #{e.message}\n" - if file_line = e.message[/#{Regexp.escape(config_file_path)}:[\d]+/] - line = file_line[/:([\d]+)$/, 1].to_i + if file_line = e.message[/#{Regexp.escape(config_file_path)}:\d+/] + line = file_line[/:(\d+)$/, 1].to_i message << highlight_config_error(config_file_path, line) end raise ChefConfig::ConfigurationError, message @@ -206,7 +206,7 @@ module ChefConfig filtered_trace = e.backtrace.grep(/#{Regexp.escape(config_file_path)}/) filtered_trace.each { |bt_line| message << " " << bt_line << "\n" } unless filtered_trace.empty? - line_nr = filtered_trace.first[/#{Regexp.escape(config_file_path)}:([\d]+)/, 1] + line_nr = filtered_trace.first[/#{Regexp.escape(config_file_path)}:(\d+)/, 1] message << highlight_config_error(config_file_path, line_nr.to_i) end raise ChefConfig::ConfigurationError, message 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 diff --git a/spec/functional/resource/apt_package_spec.rb b/spec/functional/resource/apt_package_spec.rb index 228882a2e7..6a1031feb8 100644 --- a/spec/functional/resource/apt_package_spec.rb +++ b/spec/functional/resource/apt_package_spec.rb @@ -326,7 +326,7 @@ describe Chef::Resource::AptPackage, metadata do pkg_check = shell_out!("dpkg -l chef-integration-test", returns: [0, 1]) if pkg_check.exitstatus == 0 - expect(pkg_check.stdout).to match(/un[\s]+chef-integration-test/) + expect(pkg_check.stdout).to match(/un\s+chef-integration-test/) end end @@ -359,7 +359,7 @@ describe Chef::Resource::AptPackage, metadata do it "upgrades the package for action :upgrade" do package_resource.run_action(:upgrade) dpkg_l = shell_out!("dpkg -l chef-integration-test", returns: [0]) - expect(dpkg_l.stdout).to match(/chef\-integration\-test[\s]+1\.1\-1/) + expect(dpkg_l.stdout).to match(/chef\-integration\-test\s+1\.1\-1/) expect(package_resource).to be_updated_by_last_action end @@ -373,7 +373,7 @@ describe Chef::Resource::AptPackage, metadata do it "upgrades the package for action :install" do package_resource.run_action(:install) dpkg_l = shell_out!("dpkg -l chef-integration-test", returns: [0]) - expect(dpkg_l.stdout).to match(/chef\-integration\-test[\s]+1\.1\-1/) + expect(dpkg_l.stdout).to match(/chef\-integration\-test\s+1\.1\-1/) expect(package_resource).to be_updated_by_last_action end end diff --git a/spec/unit/knife/configure_spec.rb b/spec/unit/knife/configure_spec.rb index 6b41e54778..7d6c840d1f 100644 --- a/spec/unit/knife/configure_spec.rb +++ b/spec/unit/knife/configure_spec.rb @@ -157,9 +157,9 @@ describe Chef::Knife::Configure do expect(::File).to receive(:open).with("/home/you/.chef/credentials", "w").and_yield config_file @knife.config[:repository] = "/home/you/chef-repo" @knife.run - expect(config_file.string).to match(/^client_name[\s]+=[\s]+'#{Etc.getlogin}'$/) - expect(config_file.string).to match(%r{^client_key[\s]+=[\s]+'/home/you/.chef/#{Etc.getlogin}.pem'$}) - expect(config_file.string).to match(/^chef_server_url\s+=[\s]+'#{default_server_url}'$/) + expect(config_file.string).to match(/^client_name\s+=\s+'#{Etc.getlogin}'$/) + expect(config_file.string).to match(%r{^client_key\s+=\s+'/home/you/.chef/#{Etc.getlogin}.pem'$}) + expect(config_file.string).to match(/^chef_server_url\s+=\s+'#{default_server_url}'$/) end it "creates a new client when given the --initial option" do diff --git a/spec/unit/resource/breakpoint_spec.rb b/spec/unit/resource/breakpoint_spec.rb index 0804c27cab..4b1aed6f8e 100644 --- a/spec/unit/resource/breakpoint_spec.rb +++ b/spec/unit/resource/breakpoint_spec.rb @@ -58,7 +58,7 @@ describe Chef::Resource::Breakpoint do it "names itself after the line number of the file where it's created" do resource = Chef::Resource::Breakpoint.new - expect(resource.name).to match(/breakpoint_spec\.rb\:[\d]{2}\:in \`new\'$/) + expect(resource.name).to match(/breakpoint_spec\.rb\:\d{2}\:in \`new\'$/) end end diff --git a/spec/unit/shell_spec.rb b/spec/unit/shell_spec.rb index 18b622698e..9c1a0c8e3d 100644 --- a/spec/unit/shell_spec.rb +++ b/spec/unit/shell_spec.rb @@ -150,8 +150,8 @@ describe Shell do end it "creates a help banner with the command descriptions" do - expect(@chef_object.help_banner).to match(/^\|\ Command[\s]+\|\ Description[\s]*$/) - expect(@chef_object.help_banner).to match(/^\|\ rspec_method[\s]+\|\ rspecin\'[\s]*$/) + expect(@chef_object.help_banner).to match(/^\|\ Command\s+\|\ Description\s*$/) + expect(@chef_object.help_banner).to match(/^\|\ rspec_method\s+\|\ rspecin\'\s*$/) end end |