Autocorrect Rubocop Style/PerlBackrefs.

This commit is contained in:
Mike McQuaid 2017-06-10 20:23:20 +03:00
parent 564b03aa01
commit 7a0aff1080
20 changed files with 83 additions and 83 deletions

View File

@ -79,7 +79,7 @@ module Homebrew
def github_remote_path(remote, path) def github_remote_path(remote, path)
if remote =~ %r{^(?:https?://|git(?:@|://))github\.com[:/](.+)/(.+?)(?:\.git)?$} if remote =~ %r{^(?:https?://|git(?:@|://))github\.com[:/](.+)/(.+?)(?:\.git)?$}
"https://github.com/#{$1}/#{$2}/blob/master/#{path}" "https://github.com/#{Regexp.last_match(1)}/#{Regexp.last_match(2)}/blob/master/#{path}"
else else
"#{remote}/#{path}" "#{remote}/#{path}"
end end

View File

@ -80,7 +80,7 @@ module Homebrew
if name !~ HOMEBREW_TAP_FORMULA_REGEX && name !~ HOMEBREW_CASK_TAP_CASK_REGEX if name !~ HOMEBREW_TAP_FORMULA_REGEX && name !~ HOMEBREW_CASK_TAP_CASK_REGEX
next next
end end
tap = Tap.fetch($1, $2) tap = Tap.fetch(Regexp.last_match(1), Regexp.last_match(2))
tap.install unless tap.installed? tap.install unless tap.installed?
end end
end end

View File

@ -93,7 +93,7 @@ module Homebrew
def query_regexp(query) def query_regexp(query)
case query case query
when %r{^/(.*)/$} then Regexp.new($1) when %r{^/(.*)/$} then Regexp.new(Regexp.last_match(1))
else /.*#{Regexp.escape(query)}.*/i else /.*#{Regexp.escape(query)}.*/i
end end
rescue RegexpError rescue RegexpError

View File

@ -578,7 +578,7 @@ class FormulaAuditor
next unless o.name =~ /^with(out)?-(?:checks?|tests)$/ next unless o.name =~ /^with(out)?-(?:checks?|tests)$/
unless formula.deps.any? { |d| d.name == "check" && (d.optional? || d.recommended?) } unless formula.deps.any? { |d| d.name == "check" && (d.optional? || d.recommended?) }
problem "Use '--with#{$1}-test' instead of '--#{o.name}'. Migrate '--#{o.name}' with `deprecated_option`." problem "Use '--with#{Regexp.last_match(1)}-test' instead of '--#{o.name}'. Migrate '--#{o.name}' with `deprecated_option`."
end end
end end
@ -722,7 +722,7 @@ class FormulaAuditor
stable = formula.stable stable = formula.stable
case stable && stable.url case stable && stable.url
when /[\d\._-](alpha|beta|rc\d)/ when /[\d\._-](alpha|beta|rc\d)/
matched = $1 matched = Regexp.last_match(1)
version_prefix = stable.version.to_s.sub(/\d+$/, "") version_prefix = stable.version.to_s.sub(/\d+$/, "")
return if unstable_whitelist.include?([formula.name, version_prefix]) return if unstable_whitelist.include?([formula.name, version_prefix])
problem "Stable version URLs should not contain #{matched}" problem "Stable version URLs should not contain #{matched}"
@ -837,7 +837,7 @@ class FormulaAuditor
when %r{https?://patch-diff\.githubusercontent\.com/raw/(.+)/(.+)/pull/(.+)\.(?:diff|patch)} when %r{https?://patch-diff\.githubusercontent\.com/raw/(.+)/(.+)/pull/(.+)\.(?:diff|patch)}
problem <<-EOS.undent problem <<-EOS.undent
use GitHub pull request URLs: use GitHub pull request URLs:
https://github.com/#{$1}/#{$2}/pull/#{$3}.patch https://github.com/#{Regexp.last_match(1)}/#{Regexp.last_match(2)}/pull/#{Regexp.last_match(3)}.patch
Rather than patch-diff: Rather than patch-diff:
#{patch.url} #{patch.url}
EOS EOS
@ -875,7 +875,7 @@ class FormulaAuditor
def line_problems(line, _lineno) def line_problems(line, _lineno)
if line =~ /<(Formula|AmazonWebServicesFormula|ScriptFileFormula|GithubGistFormula)/ if line =~ /<(Formula|AmazonWebServicesFormula|ScriptFileFormula|GithubGistFormula)/
problem "Use a space in class inheritance: class Foo < #{$1}" problem "Use a space in class inheritance: class Foo < #{Regexp.last_match(1)}"
end end
# Commented-out cmake support from default template # Commented-out cmake support from default template
@ -899,52 +899,52 @@ class FormulaAuditor
# FileUtils is included in Formula # FileUtils is included in Formula
# encfs modifies a file with this name, so check for some leading characters # encfs modifies a file with this name, so check for some leading characters
if line =~ %r{[^'"/]FileUtils\.(\w+)} if line =~ %r{[^'"/]FileUtils\.(\w+)}
problem "Don't need 'FileUtils.' before #{$1}." problem "Don't need 'FileUtils.' before #{Regexp.last_match(1)}."
end end
# Check for long inreplace block vars # Check for long inreplace block vars
if line =~ /inreplace .* do \|(.{2,})\|/ if line =~ /inreplace .* do \|(.{2,})\|/
problem "\"inreplace <filenames> do |s|\" is preferred over \"|#{$1}|\"." problem "\"inreplace <filenames> do |s|\" is preferred over \"|#{Regexp.last_match(1)}|\"."
end end
# Check for string interpolation of single values. # Check for string interpolation of single values.
if line =~ /(system|inreplace|gsub!|change_make_var!).*[ ,]"#\{([\w.]+)\}"/ if line =~ /(system|inreplace|gsub!|change_make_var!).*[ ,]"#\{([\w.]+)\}"/
problem "Don't need to interpolate \"#{$2}\" with #{$1}" problem "Don't need to interpolate \"#{Regexp.last_match(2)}\" with #{Regexp.last_match(1)}"
end end
# Check for string concatenation; prefer interpolation # Check for string concatenation; prefer interpolation
if line =~ /(#\{\w+\s*\+\s*['"][^}]+\})/ if line =~ /(#\{\w+\s*\+\s*['"][^}]+\})/
problem "Try not to concatenate paths in string interpolation:\n #{$1}" problem "Try not to concatenate paths in string interpolation:\n #{Regexp.last_match(1)}"
end end
# Prefer formula path shortcuts in Pathname+ # Prefer formula path shortcuts in Pathname+
if line =~ %r{\(\s*(prefix\s*\+\s*(['"])(bin|include|libexec|lib|sbin|share|Frameworks)[/'"])} if line =~ %r{\(\s*(prefix\s*\+\s*(['"])(bin|include|libexec|lib|sbin|share|Frameworks)[/'"])}
problem "\"(#{$1}...#{$2})\" should be \"(#{$3.downcase}+...)\"" problem "\"(#{Regexp.last_match(1)}...#{Regexp.last_match(2)})\" should be \"(#{Regexp.last_match(3).downcase}+...)\""
end end
if line =~ /((man)\s*\+\s*(['"])(man[1-8])(['"]))/ if line =~ /((man)\s*\+\s*(['"])(man[1-8])(['"]))/
problem "\"#{$1}\" should be \"#{$4}\"" problem "\"#{Regexp.last_match(1)}\" should be \"#{Regexp.last_match(4)}\""
end end
# Prefer formula path shortcuts in strings # Prefer formula path shortcuts in strings
if line =~ %r[(\#\{prefix\}/(bin|include|libexec|lib|sbin|share|Frameworks))] if line =~ %r[(\#\{prefix\}/(bin|include|libexec|lib|sbin|share|Frameworks))]
problem "\"#{$1}\" should be \"\#{#{$2.downcase}}\"" problem "\"#{Regexp.last_match(1)}\" should be \"\#{#{Regexp.last_match(2).downcase}}\""
end end
if line =~ %r[((\#\{prefix\}/share/man/|\#\{man\}/)(man[1-8]))] if line =~ %r[((\#\{prefix\}/share/man/|\#\{man\}/)(man[1-8]))]
problem "\"#{$1}\" should be \"\#{#{$3}}\"" problem "\"#{Regexp.last_match(1)}\" should be \"\#{#{Regexp.last_match(3)}}\""
end end
if line =~ %r[((\#\{share\}/(man)))[/'"]] if line =~ %r[((\#\{share\}/(man)))[/'"]]
problem "\"#{$1}\" should be \"\#{#{$3}}\"" problem "\"#{Regexp.last_match(1)}\" should be \"\#{#{Regexp.last_match(3)}}\""
end end
if line =~ %r[(\#\{prefix\}/share/(info|man))] if line =~ %r[(\#\{prefix\}/share/(info|man))]
problem "\"#{$1}\" should be \"\#{#{$2}}\"" problem "\"#{Regexp.last_match(1)}\" should be \"\#{#{Regexp.last_match(2)}}\""
end end
if line =~ /depends_on :(automake|autoconf|libtool)/ if line =~ /depends_on :(automake|autoconf|libtool)/
problem ":#{$1} is deprecated. Usage should be \"#{$1}\"" problem ":#{Regexp.last_match(1)} is deprecated. Usage should be \"#{Regexp.last_match(1)}\""
end end
if line =~ /depends_on :apr/ if line =~ /depends_on :apr/
@ -954,23 +954,23 @@ class FormulaAuditor
problem ":tex is deprecated" if line =~ /depends_on :tex/ problem ":tex is deprecated" if line =~ /depends_on :tex/
if line =~ /depends_on\s+['"](.+)['"]\s+=>\s+:(lua|perl|python|ruby)(\d*)/ if line =~ /depends_on\s+['"](.+)['"]\s+=>\s+:(lua|perl|python|ruby)(\d*)/
problem "#{$2} modules should be vendored rather than use deprecated `depends_on \"#{$1}\" => :#{$2}#{$3}`" problem "#{Regexp.last_match(2)} modules should be vendored rather than use deprecated `depends_on \"#{Regexp.last_match(1)}\" => :#{Regexp.last_match(2)}#{Regexp.last_match(3)}`"
end end
if line =~ /depends_on\s+['"](.+)['"]\s+=>\s+(.*)/ if line =~ /depends_on\s+['"](.+)['"]\s+=>\s+(.*)/
dep = $1 dep = Regexp.last_match(1)
$2.split(" ").map do |o| Regexp.last_match(2).split(" ").map do |o|
break if ["if", "unless"].include?(o) break if ["if", "unless"].include?(o)
next unless o =~ /^\[?['"](.*)['"]/ next unless o =~ /^\[?['"](.*)['"]/
problem "Dependency #{dep} should not use option #{$1}" problem "Dependency #{dep} should not use option #{Regexp.last_match(1)}"
end end
end end
# Commented-out depends_on # Commented-out depends_on
problem "Commented-out dep #{$1}" if line =~ /#\s*depends_on\s+(.+)\s*$/ problem "Commented-out dep #{Regexp.last_match(1)}" if line =~ /#\s*depends_on\s+(.+)\s*$/
if line =~ /if\s+ARGV\.include\?\s+'--(HEAD|devel)'/ if line =~ /if\s+ARGV\.include\?\s+'--(HEAD|devel)'/
problem "Use \"if build.#{$1.downcase}?\" instead" problem "Use \"if build.#{Regexp.last_match(1).downcase}?\" instead"
end end
problem "Use separate make calls" if line.include?("make && make") problem "Use separate make calls" if line.include?("make && make")
@ -983,15 +983,15 @@ class FormulaAuditor
# Avoid hard-coding compilers # Avoid hard-coding compilers
if line =~ %r{(system|ENV\[.+\]\s?=)\s?['"](/usr/bin/)?(gcc|llvm-gcc|clang)['" ]} if line =~ %r{(system|ENV\[.+\]\s?=)\s?['"](/usr/bin/)?(gcc|llvm-gcc|clang)['" ]}
problem "Use \"\#{ENV.cc}\" instead of hard-coding \"#{$3}\"" problem "Use \"\#{ENV.cc}\" instead of hard-coding \"#{Regexp.last_match(3)}\""
end end
if line =~ %r{(system|ENV\[.+\]\s?=)\s?['"](/usr/bin/)?((g|llvm-g|clang)\+\+)['" ]} if line =~ %r{(system|ENV\[.+\]\s?=)\s?['"](/usr/bin/)?((g|llvm-g|clang)\+\+)['" ]}
problem "Use \"\#{ENV.cxx}\" instead of hard-coding \"#{$3}\"" problem "Use \"\#{ENV.cxx}\" instead of hard-coding \"#{Regexp.last_match(3)}\""
end end
if line =~ /system\s+['"](env|export)(\s+|['"])/ if line =~ /system\s+['"](env|export)(\s+|['"])/
problem "Use ENV instead of invoking '#{$1}' to modify the environment" problem "Use ENV instead of invoking '#{Regexp.last_match(1)}' to modify the environment"
end end
if formula.name != "wine" && line =~ /ENV\.universal_binary/ if formula.name != "wine" && line =~ /ENV\.universal_binary/
@ -1007,27 +1007,27 @@ class FormulaAuditor
end end
if line =~ /build\.include\?[\s\(]+['"]\-\-(.*)['"]/ if line =~ /build\.include\?[\s\(]+['"]\-\-(.*)['"]/
problem "Reference '#{$1}' without dashes" problem "Reference '#{Regexp.last_match(1)}' without dashes"
end end
if line =~ /build\.include\?[\s\(]+['"]with(out)?-(.*)['"]/ if line =~ /build\.include\?[\s\(]+['"]with(out)?-(.*)['"]/
problem "Use build.with#{$1}? \"#{$2}\" instead of build.include? 'with#{$1}-#{$2}'" problem "Use build.with#{Regexp.last_match(1)}? \"#{Regexp.last_match(2)}\" instead of build.include? 'with#{Regexp.last_match(1)}-#{Regexp.last_match(2)}'"
end end
if line =~ /build\.with\?[\s\(]+['"]-?-?with-(.*)['"]/ if line =~ /build\.with\?[\s\(]+['"]-?-?with-(.*)['"]/
problem "Don't duplicate 'with': Use `build.with? \"#{$1}\"` to check for \"--with-#{$1}\"" problem "Don't duplicate 'with': Use `build.with? \"#{Regexp.last_match(1)}\"` to check for \"--with-#{Regexp.last_match(1)}\""
end end
if line =~ /build\.without\?[\s\(]+['"]-?-?without-(.*)['"]/ if line =~ /build\.without\?[\s\(]+['"]-?-?without-(.*)['"]/
problem "Don't duplicate 'without': Use `build.without? \"#{$1}\"` to check for \"--without-#{$1}\"" problem "Don't duplicate 'without': Use `build.without? \"#{Regexp.last_match(1)}\"` to check for \"--without-#{Regexp.last_match(1)}\""
end end
if line =~ /unless build\.with\?(.*)/ if line =~ /unless build\.with\?(.*)/
problem "Use if build.without?#{$1} instead of unless build.with?#{$1}" problem "Use if build.without?#{Regexp.last_match(1)} instead of unless build.with?#{Regexp.last_match(1)}"
end end
if line =~ /unless build\.without\?(.*)/ if line =~ /unless build\.without\?(.*)/
problem "Use if build.with?#{$1} instead of unless build.without?#{$1}" problem "Use if build.with?#{Regexp.last_match(1)} instead of unless build.without?#{Regexp.last_match(1)}"
end end
if line =~ /(not\s|!)\s*build\.with?\?/ if line =~ /(not\s|!)\s*build\.with?\?/
@ -1071,7 +1071,7 @@ class FormulaAuditor
end end
if line =~ /^def (\w+).*$/ if line =~ /^def (\w+).*$/
problem "Define method #{$1.inspect} in the class body, not at the top-level" problem "Define method #{Regexp.last_match(1).inspect} in the class body, not at the top-level"
end end
if line.include?("ENV.fortran") && !formula.requirements.map(&:class).include?(FortranRequirement) if line.include?("ENV.fortran") && !formula.requirements.map(&:class).include?(FortranRequirement)
@ -1083,20 +1083,20 @@ class FormulaAuditor
end end
if line =~ /depends_on :(.+) (if.+|unless.+)$/ if line =~ /depends_on :(.+) (if.+|unless.+)$/
conditional_dep_problems($1.to_sym, $2, $&) conditional_dep_problems(Regexp.last_match(1).to_sym, Regexp.last_match(2), $&)
end end
if line =~ /depends_on ['"](.+)['"] (if.+|unless.+)$/ if line =~ /depends_on ['"](.+)['"] (if.+|unless.+)$/
conditional_dep_problems($1, $2, $&) conditional_dep_problems(Regexp.last_match(1), Regexp.last_match(2), $&)
end end
if line =~ /(Dir\[("[^\*{},]+")\])/ if line =~ /(Dir\[("[^\*{},]+")\])/
problem "#{$1} is unnecessary; just use #{$2}" problem "#{Regexp.last_match(1)} is unnecessary; just use #{Regexp.last_match(2)}"
end end
if line =~ /system (["'](#{FILEUTILS_METHODS})["' ])/o if line =~ /system (["'](#{FILEUTILS_METHODS})["' ])/o
system = $1 system = Regexp.last_match(1)
method = $2 method = Regexp.last_match(2)
problem "Use the `#{method}` Ruby method instead of `system #{system}`" problem "Use the `#{method}` Ruby method instead of `system #{system}`"
end end
@ -1114,7 +1114,7 @@ class FormulaAuditor
end end
if line =~ /system\s+['"](otool|install_name_tool|lipo)/ && formula.name != "cctools" if line =~ /system\s+['"](otool|install_name_tool|lipo)/ && formula.name != "cctools"
problem "Use ruby-macho instead of calling #{$1}" problem "Use ruby-macho instead of calling #{Regexp.last_match(1)}"
end end
if formula.tap.to_s == "homebrew/core" if formula.tap.to_s == "homebrew/core"
@ -1125,29 +1125,29 @@ class FormulaAuditor
end end
if line =~ /((revision|version_scheme)\s+0)/ if line =~ /((revision|version_scheme)\s+0)/
problem "'#{$1}' should be removed" problem "'#{Regexp.last_match(1)}' should be removed"
end end
return unless @strict return unless @strict
problem "`#{$1}` in formulae is deprecated" if line =~ /(env :(std|userpaths))/ problem "`#{Regexp.last_match(1)}` in formulae is deprecated" if line =~ /(env :(std|userpaths))/
if line =~ /system ((["'])[^"' ]*(?:\s[^"' ]*)+\2)/ if line =~ /system ((["'])[^"' ]*(?:\s[^"' ]*)+\2)/
bad_system = $1 bad_system = Regexp.last_match(1)
unless %w[| < > & ; *].any? { |c| bad_system.include? c } unless %w[| < > & ; *].any? { |c| bad_system.include? c }
good_system = bad_system.gsub(" ", "\", \"") good_system = bad_system.gsub(" ", "\", \"")
problem "Use `system #{good_system}` instead of `system #{bad_system}` " problem "Use `system #{good_system}` instead of `system #{bad_system}` "
end end
end end
problem "`#{$1}` is now unnecessary" if line =~ /(require ["']formula["'])/ problem "`#{Regexp.last_match(1)}` is now unnecessary" if line =~ /(require ["']formula["'])/
if line =~ %r{#\{share\}/#{Regexp.escape(formula.name)}[/'"]} if line =~ %r{#\{share\}/#{Regexp.escape(formula.name)}[/'"]}
problem "Use \#{pkgshare} instead of \#{share}/#{formula.name}" problem "Use \#{pkgshare} instead of \#{share}/#{formula.name}"
end end
return unless line =~ %r{share(\s*[/+]\s*)(['"])#{Regexp.escape(formula.name)}(?:\2|/)} return unless line =~ %r{share(\s*[/+]\s*)(['"])#{Regexp.escape(formula.name)}(?:\2|/)}
problem "Use pkgshare instead of (share#{$1}\"#{formula.name}\")" problem "Use pkgshare instead of (share#{Regexp.last_match(1)}\"#{formula.name}\")"
end end
def audit_reverse_migration def audit_reverse_migration
@ -1297,7 +1297,7 @@ class ResourceAuditor
def audit_download_strategy def audit_download_strategy
if url =~ %r{^(cvs|bzr|hg|fossil)://} || url =~ %r{^(svn)\+http://} if url =~ %r{^(cvs|bzr|hg|fossil)://} || url =~ %r{^(svn)\+http://}
problem "Use of the #{$&} scheme is deprecated, pass `:using => :#{$1}` instead" problem "Use of the #{$&} scheme is deprecated, pass `:using => :#{Regexp.last_match(1)}` instead"
end end
url_strategy = DownloadStrategyDetector.detect(url) url_strategy = DownloadStrategyDetector.detect(url)
@ -1341,7 +1341,7 @@ class ResourceAuditor
def audit_urls def audit_urls
# Check GNU urls; doesn't apply to mirrors # Check GNU urls; doesn't apply to mirrors
if url =~ %r{^(?:https?|ftp)://ftpmirror.gnu.org/(.*)} if url =~ %r{^(?:https?|ftp)://ftpmirror.gnu.org/(.*)}
problem "Please use \"https://ftp.gnu.org/gnu/#{$1}\" instead of #{url}." problem "Please use \"https://ftp.gnu.org/gnu/#{Regexp.last_match(1)}\" instead of #{url}."
end end
if mirrors.include?(url) if mirrors.include?(url)
@ -1375,11 +1375,11 @@ class ResourceAuditor
%r{^http://(?:[^/]*\.)?mirrorservice\.org/} %r{^http://(?:[^/]*\.)?mirrorservice\.org/}
problem "Please use https:// for #{p}" problem "Please use https:// for #{p}"
when %r{^http://search\.mcpan\.org/CPAN/(.*)}i when %r{^http://search\.mcpan\.org/CPAN/(.*)}i
problem "#{p} should be `https://cpan.metacpan.org/#{$1}`" problem "#{p} should be `https://cpan.metacpan.org/#{Regexp.last_match(1)}`"
when %r{^(http|ftp)://ftp\.gnome\.org/pub/gnome/(.*)}i when %r{^(http|ftp)://ftp\.gnome\.org/pub/gnome/(.*)}i
problem "#{p} should be `https://download.gnome.org/#{$2}`" problem "#{p} should be `https://download.gnome.org/#{Regexp.last_match(2)}`"
when %r{^git://anonscm\.debian\.org/users/(.*)}i when %r{^git://anonscm\.debian\.org/users/(.*)}i
problem "#{p} should be `https://anonscm.debian.org/git/users/#{$1}`" problem "#{p} should be `https://anonscm.debian.org/git/users/#{Regexp.last_match(1)}`"
end end
end end
@ -1389,7 +1389,7 @@ class ResourceAuditor
when %r{^ftp://ftp\.mirrorservice\.org} when %r{^ftp://ftp\.mirrorservice\.org}
problem "Please use https:// for #{p}" problem "Please use https:// for #{p}"
when %r{^ftp://ftp\.cpan\.org/pub/CPAN(.*)}i when %r{^ftp://ftp\.cpan\.org/pub/CPAN(.*)}i
problem "#{p} should be `http://search.cpan.org/CPAN#{$1}`" problem "#{p} should be `http://search.cpan.org/CPAN#{Regexp.last_match(1)}`"
end end
end end
@ -1403,7 +1403,7 @@ class ResourceAuditor
next unless p =~ %r{^https?://.*\b(sourceforge|sf)\.(com|net)} next unless p =~ %r{^https?://.*\b(sourceforge|sf)\.(com|net)}
if p =~ /(\?|&)use_mirror=/ if p =~ /(\?|&)use_mirror=/
problem "Don't use #{$1}use_mirror in SourceForge urls (url is #{p})." problem "Don't use #{Regexp.last_match(1)}use_mirror in SourceForge urls (url is #{p})."
end end
if p.end_with?("/download") if p.end_with?("/download")
@ -1433,7 +1433,7 @@ class ResourceAuditor
problem <<-EOS.undent problem <<-EOS.undent
Please use a secure mirror for Debian URLs. Please use a secure mirror for Debian URLs.
We recommend: We recommend:
https://mirrors.ocf.berkeley.edu/debian/#{$1} https://mirrors.ocf.berkeley.edu/debian/#{Regexp.last_match(1)}
EOS EOS
end end
@ -1486,7 +1486,7 @@ class ResourceAuditor
next unless u =~ %r{https?://codeload\.github\.com/(.+)/(.+)/(?:tar\.gz|zip)/(.+)} next unless u =~ %r{https?://codeload\.github\.com/(.+)/(.+)/(?:tar\.gz|zip)/(.+)}
problem <<-EOS.undent problem <<-EOS.undent
use GitHub archive URLs: use GitHub archive URLs:
https://github.com/#{$1}/#{$2}/archive/#{$3}.tar.gz https://github.com/#{Regexp.last_match(1)}/#{Regexp.last_match(2)}/archive/#{Regexp.last_match(3)}.tar.gz
Rather than codeload: Rather than codeload:
#{u} #{u}
EOS EOS
@ -1495,7 +1495,7 @@ class ResourceAuditor
# Check for Maven Central urls, prefer HTTPS redirector over specific host # Check for Maven Central urls, prefer HTTPS redirector over specific host
urls.each do |u| urls.each do |u|
next unless u =~ %r{https?://(?:central|repo\d+)\.maven\.org/maven2/(.+)$} next unless u =~ %r{https?://(?:central|repo\d+)\.maven\.org/maven2/(.+)$}
problem "#{u} should be `https://search.maven.org/remotecontent?filepath=#{$1}`" problem "#{u} should be `https://search.maven.org/remotecontent?filepath=#{Regexp.last_match(1)}`"
end end
if name == "curl" && !urls.find { |u| u.start_with?("http://") } if name == "curl" && !urls.find { |u| u.start_with?("http://") }
@ -1506,7 +1506,7 @@ class ResourceAuditor
if @strict if @strict
urls.each do |p| urls.each do |p|
next unless p =~ %r{^https?://pypi.python.org/(.*)} next unless p =~ %r{^https?://pypi.python.org/(.*)}
problem "#{p} should be `https://files.pythonhosted.org/#{$1}`" problem "#{p} should be `https://files.pythonhosted.org/#{Regexp.last_match(1)}`"
end end
end end

View File

@ -101,13 +101,13 @@ class FormulaCreator
if @name.nil? if @name.nil?
case url case url
when %r{github\.com/(\S+)/(\S+)\.git} when %r{github\.com/(\S+)/(\S+)\.git}
@user = $1 @user = Regexp.last_match(1)
@name = $2 @name = Regexp.last_match(2)
@head = true @head = true
@github = true @github = true
when %r{github\.com/(\S+)/(\S+)/(archive|releases)/} when %r{github\.com/(\S+)/(\S+)/(archive|releases)/}
@user = $1 @user = Regexp.last_match(1)
@name = $2 @name = Regexp.last_match(2)
@github = true @github = true
else else
@name = path.basename.to_s[/(.*?)[-_.]?#{Regexp.escape(path.version.to_s)}/, 1] @name = path.basename.to_s[/(.*?)[-_.]?#{Regexp.escape(path.version.to_s)}/, 1]

View File

@ -87,7 +87,7 @@ module Homebrew
date = if ARGV.include?("--fail-if-changed") && date = if ARGV.include?("--fail-if-changed") &&
target.extname == ".1" && target.exist? target.extname == ".1" && target.exist?
/"(\d{1,2})" "([A-Z][a-z]+) (\d{4})" "#{organisation}" "#{manual}"/ =~ target.read /"(\d{1,2})" "([A-Z][a-z]+) (\d{4})" "#{organisation}" "#{manual}"/ =~ target.read
Date.parse("#{$1} #{$2} #{$3}") Date.parse("#{Regexp.last_match(1)} #{Regexp.last_match(2)} #{Regexp.last_match(3)}")
else else
Date.today Date.today
end end

View File

@ -347,7 +347,7 @@ module Homebrew
formulae = [] formulae = []
others = [] others = []
File.foreach(patchfile) do |line| File.foreach(patchfile) do |line|
files << $1 if line =~ %r{^\+\+\+ b/(.*)} files << Regexp.last_match(1) if line =~ %r{^\+\+\+ b/(.*)}
end end
files.each do |file| files.each do |file|
if tap && tap.formula_file?(file) if tap && tap.formula_file?(file)

View File

@ -33,7 +33,7 @@ module Homebrew
if ARGV.include?("--markdown") if ARGV.include?("--markdown")
output.map! do |s| output.map! do |s|
/(.*\d)+ \(@(.+)\) - (.*)/ =~ s /(.*\d)+ \(@(.+)\) - (.*)/ =~ s
"- [#{$3}](#{$1}) (@#{$2})" "- [#{Regexp.last_match(3)}](#{Regexp.last_match(1)}) (@#{Regexp.last_match(2)})"
end end
end end

View File

@ -49,7 +49,7 @@ module Homebrew
case line.chomp case line.chomp
# regex matches: /dev/disk0s2 489562928 440803616 48247312 91% / # regex matches: /dev/disk0s2 489562928 440803616 48247312 91% /
when /^.+\s+[0-9]+\s+[0-9]+\s+[0-9]+\s+[0-9]{1,3}%\s+(.+)/ when /^.+\s+[0-9]+\s+[0-9]+\s+[0-9]+\s+[0-9]{1,3}%\s+(.+)/
vols << $1 vols << Regexp.last_match(1)
end end
end end
end end
@ -919,11 +919,11 @@ module Homebrew
return unless which "python" return unless which "python"
`python -V 2>&1` =~ /Python (\d+)\./ `python -V 2>&1` =~ /Python (\d+)\./
# This won't be the right warning if we matched nothing at all # This won't be the right warning if we matched nothing at all
return if $1.nil? return if Regexp.last_match(1).nil?
return if $1 == "2" return if Regexp.last_match(1) == "2"
<<-EOS.undent <<-EOS.undent
python is symlinked to python#{$1} python is symlinked to python#{Regexp.last_match(1)}
This will confuse build scripts and in general lead to subtle breakage. This will confuse build scripts and in general lead to subtle breakage.
EOS EOS
end end

View File

@ -517,8 +517,8 @@ class S3DownloadStrategy < CurlDownloadStrategy
if @url !~ %r{^https?://([^.].*)\.s3\.amazonaws\.com/(.+)$} if @url !~ %r{^https?://([^.].*)\.s3\.amazonaws\.com/(.+)$}
raise "Bad S3 URL: " + @url raise "Bad S3 URL: " + @url
end end
bucket = $1 bucket = Regexp.last_match(1)
key = $2 key = Regexp.last_match(2)
ENV["AWS_ACCESS_KEY_ID"] = ENV["HOMEBREW_AWS_ACCESS_KEY_ID"] ENV["AWS_ACCESS_KEY_ID"] = ENV["HOMEBREW_AWS_ACCESS_KEY_ID"]
ENV["AWS_SECRET_ACCESS_KEY"] = ENV["HOMEBREW_AWS_SECRET_ACCESS_KEY"] ENV["AWS_SECRET_ACCESS_KEY"] = ENV["HOMEBREW_AWS_SECRET_ACCESS_KEY"]

View File

@ -182,7 +182,7 @@ class TapFormulaAmbiguityError < RuntimeError
@paths = paths @paths = paths
@formulae = paths.map do |path| @formulae = paths.map do |path|
path.to_s =~ HOMEBREW_TAP_PATH_REGEX path.to_s =~ HOMEBREW_TAP_PATH_REGEX
"#{Tap.fetch($1, $2)}/#{path.basename(".rb")}" "#{Tap.fetch(Regexp.last_match(1), Regexp.last_match(2))}/#{path.basename(".rb")}"
end end
super <<-EOS.undent super <<-EOS.undent
@ -202,7 +202,7 @@ class TapFormulaWithOldnameAmbiguityError < RuntimeError
@taps = possible_tap_newname_formulae.map do |newname| @taps = possible_tap_newname_formulae.map do |newname|
newname =~ HOMEBREW_TAP_FORMULA_REGEX newname =~ HOMEBREW_TAP_FORMULA_REGEX
"#{$1}/#{$2}" "#{Regexp.last_match(1)}/#{Regexp.last_match(2)}"
end end
super <<-EOS.undent super <<-EOS.undent
@ -504,7 +504,7 @@ class CurlDownloadStrategyError < RuntimeError
def initialize(url) def initialize(url)
case url case url
when %r{^file://(.+)} when %r{^file://(.+)}
super "File does not exist: #{$1}" super "File does not exist: #{Regexp.last_match(1)}"
else else
super "Download failed: #{url}" super "Download failed: #{url}"
end end

View File

@ -200,7 +200,7 @@ module Stdenv
# @private # @private
def set_cpu_flags(flags, default = DEFAULT_FLAGS, map = Hardware::CPU.optimization_flags) def set_cpu_flags(flags, default = DEFAULT_FLAGS, map = Hardware::CPU.optimization_flags)
cflags =~ /(-Xarch_#{Hardware::CPU.arch_32_bit} )-march=/ cflags =~ /(-Xarch_#{Hardware::CPU.arch_32_bit} )-march=/
xarch = $1.to_s xarch = Regexp.last_match(1).to_s
remove flags, /(-Xarch_#{Hardware::CPU.arch_32_bit} )?-march=\S*/ remove flags, /(-Xarch_#{Hardware::CPU.arch_32_bit} )?-march=\S*/
remove flags, /( -Xclang \S+)+/ remove flags, /( -Xclang \S+)+/
remove flags, /-mssse3/ remove flags, /-mssse3/

View File

@ -266,7 +266,7 @@ module Superenv
def make_jobs def make_jobs
self["MAKEFLAGS"] =~ /-\w*j(\d+)/ self["MAKEFLAGS"] =~ /-\w*j(\d+)/
[$1.to_i, 1].max [Regexp.last_match(1).to_i, 1].max
end end
def universal_binary def universal_binary

View File

@ -32,7 +32,7 @@ module Utils
# :tiger_g4, :tiger_g5, etc. # :tiger_g4, :tiger_g5, etc.
def find_altivec_tag(tag) def find_altivec_tag(tag)
return unless tag.to_s =~ /(\w+)_(g4|g4e|g5)$/ return unless tag.to_s =~ /(\w+)_(g4|g4e|g5)$/
altivec_tag = "#{$1}_altivec".to_sym altivec_tag = "#{Regexp.last_match(1)}_altivec".to_sym
altivec_tag if key?(altivec_tag) altivec_tag if key?(altivec_tag)
end end

View File

@ -177,7 +177,7 @@ class Formula
@tap = if path == Formulary.core_path(name) @tap = if path == Formulary.core_path(name)
CoreTap.instance CoreTap.instance
elsif path.to_s =~ HOMEBREW_TAP_PATH_REGEX elsif path.to_s =~ HOMEBREW_TAP_PATH_REGEX
Tap.fetch($1, $2) Tap.fetch(Regexp.last_match(1), Regexp.last_match(2))
end end
@full_name = full_name_with_optional_tap(name) @full_name = full_name_with_optional_tap(name)

View File

@ -59,7 +59,7 @@ module Formulary
def self.class_s(name) def self.class_s(name)
class_name = name.capitalize class_name = name.capitalize
class_name.gsub!(/[-_.\s]([a-zA-Z0-9])/) { $1.upcase } class_name.gsub!(/[-_.\s]([a-zA-Z0-9])/) { Regexp.last_match(1).upcase }
class_name.tr!("+", "x") class_name.tr!("+", "x")
class_name.sub!(/(.)@(\d)/, "\\1AT\\2") class_name.sub!(/(.)@(\d)/, "\\1AT\\2")
class_name class_name
@ -168,7 +168,7 @@ module Formulary
super super
rescue MethodDeprecatedError => e rescue MethodDeprecatedError => e
if url =~ %r{github.com/([\w-]+)/homebrew-([\w-]+)/} if url =~ %r{github.com/([\w-]+)/homebrew-([\w-]+)/}
e.issues_url = "https://github.com/#{$1}/homebrew-#{$2}/issues/new" e.issues_url = "https://github.com/#{Regexp.last_match(1)}/homebrew-#{Regexp.last_match(2)}/issues/new"
end end
raise raise
end end

View File

@ -61,7 +61,7 @@ class Requirement
if parent = satisfied_result_parent if parent = satisfied_result_parent
parent.to_s =~ %r{(#{Regexp.escape(HOMEBREW_CELLAR)}|#{Regexp.escape(HOMEBREW_PREFIX)}/opt)/([\w+-.@]+)} parent.to_s =~ %r{(#{Regexp.escape(HOMEBREW_CELLAR)}|#{Regexp.escape(HOMEBREW_PREFIX)}/opt)/([\w+-.@]+)}
@formula = $2 @formula = Regexp.last_match(2)
end end
true true

View File

@ -54,7 +54,7 @@ module RuboCop
problem "Please use https:// for #{homepage}" problem "Please use https:// for #{homepage}"
when %r{^http://([^/]*)\.(sf|sourceforge)\.net(/|$)} when %r{^http://([^/]*)\.(sf|sourceforge)\.net(/|$)}
problem "#{homepage} should be `https://#{$1}.sourceforge.io/`" problem "#{homepage} should be `https://#{Regexp.last_match(1)}.sourceforge.io/`"
# There's an auto-redirect here, but this mistake is incredibly common too. # There's an auto-redirect here, but this mistake is incredibly common too.
# Only applies to the homepage and subdomains for now, not the FTP URLs. # Only applies to the homepage and subdomains for now, not the FTP URLs.

View File

@ -43,8 +43,8 @@ class Tap
def self.from_path(path) def self.from_path(path)
path.to_s =~ HOMEBREW_TAP_PATH_REGEX path.to_s =~ HOMEBREW_TAP_PATH_REGEX
raise "Invalid tap path '#{path}'" unless $1 raise "Invalid tap path '#{path}'" unless Regexp.last_match(1)
fetch($1, $2) fetch(Regexp.last_match(1), Regexp.last_match(2))
rescue rescue
# No need to error as a nil tap is sufficient to show failure. # No need to error as a nil tap is sufficient to show failure.
nil nil

View File

@ -76,7 +76,7 @@ def odeprecated(method, replacement = nil, disable: false, disable_on: nil, call
tap_message = nil tap_message = nil
caller_message = backtrace.detect do |line| caller_message = backtrace.detect do |line|
next unless line =~ %r{^#{Regexp.escape(HOMEBREW_LIBRARY)}/Taps/([^/]+/[^/]+)/} next unless line =~ %r{^#{Regexp.escape(HOMEBREW_LIBRARY)}/Taps/([^/]+/[^/]+)/}
tap = Tap.fetch $1 tap = Tap.fetch Regexp.last_match(1)
tap_message = "\nPlease report this to the #{tap} tap!" tap_message = "\nPlease report this to the #{tap} tap!"
true true
end end