Skip to content

Commit

Permalink
(FACT-3428) Performance/RegexpMatch
Browse files Browse the repository at this point in the history
If you don't need MatchData, then it's better to use String#match?
  • Loading branch information
joshcooper committed Jan 8, 2024
1 parent a7e3f9c commit c8c09ef
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 11 deletions.
6 changes: 0 additions & 6 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,6 @@
# Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again.

# Offense count: 3
# This cop supports safe autocorrection (--autocorrect).
Performance/RegexpMatch:
Exclude:
- 'install.rb'

# Offense count: 70
# Configuration parameters: Include, CustomTransform, IgnoreMethods, SpecSuffixOnly.
# Include: **/*_spec*rb*, **/spec/**/*
Expand Down
10 changes: 5 additions & 5 deletions install.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class Installer

# Returns true if OS is windows (copied from facter/util/config.rb)
def windows?
(defined?(RbConfig) ? RbConfig : Config)::CONFIG['host_os'] =~ /mswin|win32|dos|mingw|cygwin/i
(defined?(RbConfig) ? RbConfig : Config)::CONFIG['host_os'].match?(/mswin|win32|dos|mingw|cygwin/i)
end

def glob(list)
Expand Down Expand Up @@ -153,7 +153,7 @@ def prepare_installation
# /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin
# which is not generally where people expect executables to be installed
# These settings are appropriate defaults for all OS X versions.
RbConfig::CONFIG['bindir'] = '/usr/bin' if RUBY_PLATFORM =~ /^universal-darwin[\d.]+$/
RbConfig::CONFIG['bindir'] = '/usr/bin' if RUBY_PLATFORM.match?(/^universal-darwin[\d.]+$/)

# if InstallOptions.configdir
# configdir = InstallOptions.configdir
Expand All @@ -173,10 +173,10 @@ def prepare_installation
else
sitelibdir = RbConfig::CONFIG['sitelibdir']
if sitelibdir.nil?
sitelibdir = $LOAD_PATH.find { |x| x =~ /site_ruby/ }
sitelibdir = $LOAD_PATH.find { |x| x.match?(/site_ruby/) }
if sitelibdir.nil?
sitelibdir = File.join(libdir, 'site_ruby')
elsif sitelibdir !~ Regexp.quote(version)
elsif !sitelibdir.match?(Regexp.quote(version))
sitelibdir = File.join(sitelibdir, version)
end
end
Expand Down Expand Up @@ -232,7 +232,7 @@ def install_binfile(from, op_file, target)
File.open(tmp_file.path, 'w') do |op|
op.puts "#!#{ruby}"
contents = ip.readlines
contents.shift if contents[0] =~ /^#!/
contents.shift if contents[0].match?(/^#!/)
op.write contents.join
end
end
Expand Down

0 comments on commit c8c09ef

Please sign in to comment.