Change regexp.match?(string) to string.match?(regexp) everywhere
- Only try to call `.match?` on strings that aren't nil.
This commit is contained in:
parent
18e684fad7
commit
1f6168fe8a
@ -91,7 +91,7 @@ module Cask
|
||||
args: ["list", service],
|
||||
sudo: with_sudo, print_stderr: false
|
||||
).stdout
|
||||
if /^\{/.match?(plist_status)
|
||||
if plist_status.match?(/^\{/)
|
||||
command.run!("/bin/launchctl", args: ["remove", service], sudo: with_sudo)
|
||||
sleep 1
|
||||
end
|
||||
|
@ -400,7 +400,7 @@ module Homebrew
|
||||
path.extend(ObserverPathnameExtension)
|
||||
if path.symlink?
|
||||
unless path.resolved_path_exists?
|
||||
if Keg::INFOFILE_RX.match?(path.to_s)
|
||||
if path.to_s.match?(Keg::INFOFILE_RX)
|
||||
path.uninstall_info unless dry_run?
|
||||
end
|
||||
|
||||
|
@ -109,7 +109,7 @@ class DependencyCollector
|
||||
end
|
||||
|
||||
def parse_string_spec(spec, tags)
|
||||
if HOMEBREW_TAP_FORMULA_REGEX.match?(spec)
|
||||
if spec.match?(HOMEBREW_TAP_FORMULA_REGEX)
|
||||
TapDependency.new(spec, tags)
|
||||
elsif tags.empty?
|
||||
Dependency.new(spec, tags)
|
||||
|
@ -264,7 +264,7 @@ module Homebrew
|
||||
|
||||
problem "'__END__' was found, but 'DATA' is not used" if text.end? && !text.data?
|
||||
|
||||
if /inreplace [^\n]* do [^\n]*\n[^\n]*\.gsub![^\n]*\n\ *end/m.match?(text.to_s)
|
||||
if text.to_s.match?(/inreplace [^\n]* do [^\n]*\n[^\n]*\.gsub![^\n]*\n\ *end/m)
|
||||
problem "'inreplace ... do' was used for a single substitution (use the non-block form instead)."
|
||||
end
|
||||
|
||||
@ -888,7 +888,7 @@ module Homebrew
|
||||
end
|
||||
bin_names.each do |name|
|
||||
["system", "shell_output", "pipe_output"].each do |cmd|
|
||||
if /test do.*#{cmd}[\(\s]+['"]#{Regexp.escape(name)}[\s'"]/m.match?(text.to_s)
|
||||
if text.to_s.match?(/test do.*#{cmd}[\(\s]+['"]#{Regexp.escape(name)}[\s'"]/m)
|
||||
problem %Q(fully scope test #{cmd} calls, e.g. #{cmd} "\#{bin}/#{name}")
|
||||
end
|
||||
end
|
||||
@ -940,7 +940,7 @@ module Homebrew
|
||||
|
||||
problem "`#{Regexp.last_match(1)}` is now unnecessary" if line =~ /(require ["']formula["'])/
|
||||
|
||||
if %r{#\{share\}/#{Regexp.escape(formula.name)}[/'"]}.match?(line)
|
||||
if line.match?(%r{#\{share\}/#{Regexp.escape(formula.name)}[/'"]})
|
||||
problem "Use \#{pkgshare} instead of \#{share}/#{formula.name}"
|
||||
end
|
||||
|
||||
@ -1067,7 +1067,7 @@ module Homebrew
|
||||
|
||||
problem "version #{version} should not have a leading 'v'" if version.to_s.start_with?("v")
|
||||
|
||||
return unless /_\d+$/.match?(version.to_s)
|
||||
return unless version.to_s.match?(/_\d+$/)
|
||||
|
||||
problem "version #{version} should not end with an underline and a number"
|
||||
end
|
||||
@ -1090,7 +1090,7 @@ module Homebrew
|
||||
|
||||
problem "Redundant :module value in URL" if mod == name
|
||||
|
||||
if %r{:[^/]+$}.match?(url)
|
||||
if url.match?(%r{:[^/]+$})
|
||||
mod = url.split(":").last
|
||||
|
||||
if mod == name
|
||||
@ -1129,7 +1129,7 @@ module Homebrew
|
||||
if strategy <= CurlDownloadStrategy && !url.start_with?("file")
|
||||
# A `brew mirror`'ed URL is usually not yet reachable at the time of
|
||||
# pull request.
|
||||
next if %r{^https://dl.bintray.com/homebrew/mirror/}.match?(url)
|
||||
next if url.match?(%r{^https://dl.bintray.com/homebrew/mirror/})
|
||||
|
||||
if http_content_problem = curl_check_http_content(url)
|
||||
problem http_content_problem
|
||||
|
@ -156,7 +156,7 @@ module Homebrew
|
||||
gnu_tar_gtar_path = HOMEBREW_PREFIX/"opt/gnu-tar/bin/gtar"
|
||||
gnu_tar_gtar = gnu_tar_gtar_path if gnu_tar_gtar_path.executable?
|
||||
tar = which("gtar") || gnu_tar_gtar || which("tar")
|
||||
if %r{/.*\.}.match?(Utils.popen_read(tar, "-tf", resource_path))
|
||||
if Utils.popen_read(tar, "-tf", resource_path).match?(%r{/.*\.})
|
||||
new_hash = resource_path.sha256
|
||||
else
|
||||
odie "#{resource_path} is not a valid tar file!"
|
||||
@ -310,7 +310,7 @@ module Homebrew
|
||||
end
|
||||
username = response.fetch("owner").fetch("login")
|
||||
rescue GitHub::AuthenticationFailedError => e
|
||||
raise unless /forking is disabled/.match?(e.github_message)
|
||||
raise unless e.github_message.match?(/forking is disabled/)
|
||||
|
||||
# If the repository is private, forking might be disabled.
|
||||
# Create branches in the repository itself instead.
|
||||
|
@ -203,7 +203,7 @@ module Homebrew
|
||||
end
|
||||
|
||||
# Omit the common global_options documented separately in the man page.
|
||||
next if /--(debug|force|help|quiet|verbose) /.match?(line)
|
||||
next if line.match?(/--(debug|force|help|quiet|verbose) /)
|
||||
|
||||
# Format one option or a comma-separated pair of short and long options.
|
||||
lines << line.gsub(/^ +(-+[a-z-]+), (-+[a-z-]+) +/, "* `\\1`, `\\2`:\n ")
|
||||
|
@ -122,7 +122,7 @@ module Homebrew
|
||||
properly. You can solve this by adding the remote:
|
||||
git -C "#{repository_path}" remote add origin #{Formatter.url("https://github.com/#{desired_origin}.git")}
|
||||
EOS
|
||||
elsif !%r{#{desired_origin}(\.git|/)?$}i.match?(current_origin)
|
||||
elsif !current_origin.match?(%r{#{desired_origin}(\.git|/)?$}i)
|
||||
<<~EOS
|
||||
Suspicious #{desired_origin} git origin remote found.
|
||||
The current git origin is:
|
||||
|
@ -242,7 +242,7 @@ class AbstractFileDownloadStrategy < AbstractDownloadStrategy
|
||||
end
|
||||
|
||||
def parse_basename(url)
|
||||
uri_path = if URI::DEFAULT_PARSER.make_regexp&.match?(url)
|
||||
uri_path = if url.match?(URI::DEFAULT_PARSER.make_regexp)
|
||||
uri = URI(url)
|
||||
|
||||
if uri.query
|
||||
@ -860,7 +860,7 @@ class CVSDownloadStrategy < VCSDownloadStrategy
|
||||
|
||||
if meta.key?(:module)
|
||||
@module = meta.fetch(:module)
|
||||
elsif !%r{:[^/]+$}.match?(@url)
|
||||
elsif !@url.match?(%r{:[^/]+$})
|
||||
@module = name
|
||||
else
|
||||
@module, @url = split_url(@url)
|
||||
|
@ -342,7 +342,7 @@ module SharedEnvExtension
|
||||
end
|
||||
|
||||
def check_for_compiler_universal_support
|
||||
return unless GNU_GCC_REGEXP.match?(homebrew_cc)
|
||||
return unless homebrew_cc.match?(GNU_GCC_REGEXP)
|
||||
|
||||
raise "Non-Apple GCC can't build universal binaries"
|
||||
end
|
||||
|
@ -22,7 +22,7 @@ class SystemConfig
|
||||
def describe_homebrew_ruby
|
||||
s = describe_homebrew_ruby_version
|
||||
|
||||
if !%r{^/System/Library/Frameworks/Ruby\.framework/Versions/[12]\.[089]/usr/bin/ruby}.match?(RUBY_PATH.to_s)
|
||||
if !RUBY_PATH.to_s.match?(%r{^/System/Library/Frameworks/Ruby\.framework/Versions/[12]\.[089]/usr/bin/ruby})
|
||||
"#{s} => #{RUBY_PATH}"
|
||||
else
|
||||
s
|
||||
|
@ -266,7 +266,7 @@ class Formula
|
||||
# and is specified to this instance.
|
||||
def installed_alias_path
|
||||
path = build.source["path"] if build.is_a?(Tab)
|
||||
return unless %r{#{HOMEBREW_TAP_DIR_REGEX}/Aliases}.match?(path)
|
||||
return unless path&.match?(%r{#{HOMEBREW_TAP_DIR_REGEX}/Aliases})
|
||||
return unless File.symlink?(path)
|
||||
|
||||
path
|
||||
|
@ -268,7 +268,7 @@ class Keg
|
||||
|
||||
aliases.each do |a|
|
||||
# versioned aliases are handled below
|
||||
next if /.+@./.match?(a)
|
||||
next if a.match?(/.+@./)
|
||||
|
||||
alias_symlink = opt/a
|
||||
if alias_symlink.symlink? && alias_symlink.exist?
|
||||
@ -338,7 +338,7 @@ class Keg
|
||||
next
|
||||
end
|
||||
|
||||
dst.uninstall_info if INFOFILE_RX.match?(dst.to_s)
|
||||
dst.uninstall_info if dst.to_s.match?(INFOFILE_RX)
|
||||
dst.unlink
|
||||
remove_old_aliases
|
||||
Find.prune if src.directory?
|
||||
@ -490,7 +490,7 @@ class Keg
|
||||
# the :link strategy. However, for Foo.framework and
|
||||
# Foo.framework/Versions we have to use :mkpath so that multiple formulae
|
||||
# can link their versions into it and `brew [un]link` works.
|
||||
if %r{[^/]*\.framework(/Versions)?$}.match?(relative_path.to_s)
|
||||
if relative_path.to_s.match?(%r{[^/]*\.framework(/Versions)?$})
|
||||
:mkpath
|
||||
else
|
||||
:link
|
||||
|
@ -13,7 +13,7 @@ class Locale
|
||||
def self.parse(string)
|
||||
string = string.to_s
|
||||
|
||||
raise ParserError, "'#{string}' cannot be parsed to a #{self}" unless LOCALE_REGEX.match?(string)
|
||||
raise ParserError, "'#{string}' cannot be parsed to a #{self}" unless string.match?(LOCALE_REGEX)
|
||||
|
||||
scan = proc do |regex|
|
||||
string.scan(/(?:\-|^)(#{regex})(?:\-|$)/).flatten.first
|
||||
|
@ -28,7 +28,7 @@ class JavaRequirement < Requirement
|
||||
end
|
||||
|
||||
def initialize(tags = [])
|
||||
@version = tags.shift if /^\d/.match?(tags.first)
|
||||
@version = tags.shift if tags.first&.match?(/^\d/)
|
||||
super(tags)
|
||||
@cask = suggestion.token
|
||||
end
|
||||
|
@ -17,7 +17,7 @@ module RuboCop
|
||||
url_node = stanza.stanza_node.first_argument
|
||||
url = url_node.str_content
|
||||
|
||||
return unless %r{^.+://[^/]+$}.match?(url)
|
||||
return unless url.match?(%r{^.+://[^/]+$})
|
||||
|
||||
add_offense(url_node, location: :expression,
|
||||
message: format(MSG_NO_SLASH, url: url))
|
||||
|
@ -17,7 +17,7 @@ module RuboCop
|
||||
|
||||
problem "Formula should have a homepage." if homepage_node.nil? || homepage.empty?
|
||||
|
||||
unless %r{^https?://}.match?(homepage)
|
||||
unless homepage.match?(%r{^https?://})
|
||||
problem "The homepage should start with http or https (URL is #{homepage})."
|
||||
end
|
||||
|
||||
|
@ -335,7 +335,7 @@ module RuboCop
|
||||
|
||||
find_every_method_call_by_name(body_node, :system).each do |method_node|
|
||||
# Skip Kibana: npm cache edge (see formula for more details)
|
||||
next if /^kibana(@\d[\d.]*)?$/.match?(@formula_name)
|
||||
next if @formula_name.match?(/^kibana(@\d[\d.]*)?$/)
|
||||
|
||||
first_param, second_param = parameters(method_node)
|
||||
next if !node_equals?(first_param, "npm") ||
|
||||
|
@ -30,7 +30,7 @@ module RuboCop
|
||||
patch_url = string_content(patch)
|
||||
gh_patch_param_pattern = %r{https?://github\.com/.+/.+/(?:commit|pull)/[a-fA-F0-9]*.(?:patch|diff)}
|
||||
if regex_match_group(patch, gh_patch_param_pattern)
|
||||
unless /\?full_index=\w+$/.match?(patch_url)
|
||||
unless patch_url.match?(/\?full_index=\w+$/)
|
||||
problem <<~EOS
|
||||
GitHub patches should use the full_index parameter:
|
||||
#{patch_url}?full_index=1
|
||||
@ -43,7 +43,7 @@ module RuboCop
|
||||
%r{gist\.github\.com/.+/raw},
|
||||
%r{gist\.githubusercontent\.com/.+/raw}])
|
||||
if regex_match_group(patch, gh_patch_patterns)
|
||||
unless /[a-fA-F0-9]{40}/.match?(patch_url)
|
||||
unless patch_url.match?(/[a-fA-F0-9]{40}/)
|
||||
problem <<~EOS.chomp
|
||||
GitHub/Gist patches should specify a revision:
|
||||
#{patch_url}
|
||||
|
@ -123,18 +123,18 @@ module RuboCop
|
||||
|
||||
problem "Don't use /download in SourceForge urls (url is #{url})." if url.end_with?("/download")
|
||||
|
||||
if %r{^https?://sourceforge\.}.match?(url)
|
||||
if url.match?(%r{^https?://sourceforge\.})
|
||||
problem "Use https://downloads.sourceforge.net to get geolocation (url is #{url})."
|
||||
end
|
||||
|
||||
if %r{^https?://prdownloads\.}.match?(url)
|
||||
if url.match?(%r{^https?://prdownloads\.})
|
||||
problem <<~EOS.chomp
|
||||
Don't use prdownloads in SourceForge urls (url is #{url}).
|
||||
See: http://librelist.com/browser/homebrew/2011/1/12/prdownloads-is-bad/
|
||||
EOS
|
||||
end
|
||||
|
||||
if %r{^http://\w+\.dl\.}.match?(url)
|
||||
if url.match?(%r{^http://\w+\.dl\.})
|
||||
problem "Don't use specific dl mirrors in SourceForge urls (url is #{url})."
|
||||
end
|
||||
|
||||
@ -195,7 +195,7 @@ module RuboCop
|
||||
# Use new-style archive downloads
|
||||
archive_gh_pattern = %r{https://.*github.*/(?:tar|zip)ball/}
|
||||
audit_urls(urls, archive_gh_pattern) do |_, url|
|
||||
next if /\.git$/.match?(url)
|
||||
next if url.match?(/\.git$/)
|
||||
|
||||
problem "Use /archive/ URLs for GitHub tarballs (url is #{url})."
|
||||
end
|
||||
@ -203,7 +203,7 @@ module RuboCop
|
||||
# Don't use GitHub .zip files
|
||||
zip_gh_pattern = %r{https://.*github.*/(archive|releases)/.*\.zip$}
|
||||
audit_urls(urls, zip_gh_pattern) do |_, url|
|
||||
next if %r{releases/download}.match?(url)
|
||||
next if url.match?(%r{releases/download})
|
||||
|
||||
problem "Use GitHub tarballs rather than zipballs (url is #{url})."
|
||||
end
|
||||
|
@ -223,7 +223,7 @@ class SystemCommand
|
||||
|
||||
def warn_plist_garbage(garbage)
|
||||
return unless ARGV.verbose?
|
||||
return unless /\S/.match?(garbage)
|
||||
return unless garbage.match?(/\S/)
|
||||
|
||||
opoo "Received non-XML output from #{Formatter.identifier(command.first)}:"
|
||||
$stderr.puts garbage.strip
|
||||
|
@ -73,8 +73,8 @@ describe RuboCop::Cop::FormulaAudit::Homepage do
|
||||
RUBY
|
||||
|
||||
inspect_source(source)
|
||||
if %r{http:\/\/www\.freedesktop\.org}.match?(homepage)
|
||||
if /Software/.match?(homepage)
|
||||
if homepage.match?(%r{http:\/\/www\.freedesktop\.org})
|
||||
if homepage.match?(/Software/)
|
||||
expected_offenses = [{ message: "#{homepage} should be styled " \
|
||||
"`https://wiki.freedesktop.org/www/Software/project_name`",
|
||||
severity: :convention,
|
||||
@ -89,13 +89,13 @@ describe RuboCop::Cop::FormulaAudit::Homepage do
|
||||
column: 2,
|
||||
source: source }]
|
||||
end
|
||||
elsif %r{https:\/\/code\.google\.com}.match?(homepage)
|
||||
elsif homepage.match?(%r{https:\/\/code\.google\.com})
|
||||
expected_offenses = [{ message: "#{homepage} should end with a slash",
|
||||
severity: :convention,
|
||||
line: 2,
|
||||
column: 2,
|
||||
source: source }]
|
||||
elsif /foo\.(sf|sourceforge)\.net/.match?(homepage)
|
||||
elsif homepage.match?(/foo\.(sf|sourceforge)\.net/)
|
||||
expected_offenses = [{ message: "#{homepage} should be `https://foo.sourceforge.io/`",
|
||||
severity: :convention,
|
||||
line: 2,
|
||||
|
@ -48,7 +48,7 @@ describe RuboCop::Cop::FormulaAudit::Patches do
|
||||
EOS
|
||||
|
||||
inspect_source(source)
|
||||
expected_offense = if %r{/raw\.github\.com/}.match?(patch_url)
|
||||
expected_offense = if patch_url.match?(%r{/raw\.github\.com/})
|
||||
[{ message:
|
||||
<<~EOS.chomp,
|
||||
GitHub/Gist patches should specify a revision:
|
||||
@ -58,7 +58,7 @@ describe RuboCop::Cop::FormulaAudit::Patches do
|
||||
line: 5,
|
||||
column: 12,
|
||||
source: source }]
|
||||
elsif %r{macports/trunk}.match?(patch_url)
|
||||
elsif patch_url.match?(%r{macports/trunk})
|
||||
[{ message:
|
||||
<<~EOS.chomp,
|
||||
MacPorts patches should specify a revision instead of trunk:
|
||||
@ -68,7 +68,7 @@ describe RuboCop::Cop::FormulaAudit::Patches do
|
||||
line: 5,
|
||||
column: 33,
|
||||
source: source }]
|
||||
elsif %r{^http://trac\.macports\.org}.match?(patch_url)
|
||||
elsif patch_url.match?(%r{^http://trac\.macports\.org})
|
||||
[{ message:
|
||||
<<~EOS.chomp,
|
||||
Patches from MacPorts Trac should be https://, not http:
|
||||
@ -78,7 +78,7 @@ describe RuboCop::Cop::FormulaAudit::Patches do
|
||||
line: 5,
|
||||
column: 5,
|
||||
source: source }]
|
||||
elsif %r{^http://bugs\.debian\.org}.match?(patch_url)
|
||||
elsif patch_url.match?(%r{^http://bugs\.debian\.org})
|
||||
[{ message:
|
||||
<<~EOS.chomp,
|
||||
Patches from Debian should be https://, not http:
|
||||
@ -89,7 +89,7 @@ describe RuboCop::Cop::FormulaAudit::Patches do
|
||||
column: 5,
|
||||
source: source }]
|
||||
# rubocop:disable Metrics/LineLength
|
||||
elsif %r{https?://patch-diff\.githubusercontent\.com/raw/(.+)/(.+)/pull/(.+)\.(?:diff|patch)}.match?(patch_url)
|
||||
elsif patch_url.match?(%r{https?://patch-diff\.githubusercontent\.com/raw/(.+)/(.+)/pull/(.+)\.(?:diff|patch)})
|
||||
# rubocop:enable Metrics/LineLength
|
||||
[{ message:
|
||||
<<~EOS,
|
||||
@ -102,7 +102,7 @@ describe RuboCop::Cop::FormulaAudit::Patches do
|
||||
line: 5,
|
||||
column: 5,
|
||||
source: source }]
|
||||
elsif %r{https?://github\.com/.+/.+/(?:commit|pull)/[a-fA-F0-9]*.(?:patch|diff)}.match?(patch_url)
|
||||
elsif patch_url.match?(%r{https?://github\.com/.+/.+/(?:commit|pull)/[a-fA-F0-9]*.(?:patch|diff)})
|
||||
[{ message:
|
||||
<<~EOS,
|
||||
GitHub patches should use the full_index parameter:
|
||||
@ -185,7 +185,7 @@ describe RuboCop::Cop::FormulaAudit::Patches do
|
||||
RUBY
|
||||
|
||||
inspect_source(source)
|
||||
expected_offense = if %r{/raw\.github\.com/}.match?(patch_url)
|
||||
expected_offense = if patch_url.match?(%r{/raw\.github\.com/})
|
||||
[{ message:
|
||||
<<~EOS.chomp,
|
||||
GitHub/Gist patches should specify a revision:
|
||||
@ -195,7 +195,7 @@ describe RuboCop::Cop::FormulaAudit::Patches do
|
||||
line: 5,
|
||||
column: 16,
|
||||
source: source }]
|
||||
elsif %r{macports/trunk}.match?(patch_url)
|
||||
elsif patch_url.match?(%r{macports/trunk})
|
||||
[{ message:
|
||||
<<~EOS.chomp,
|
||||
MacPorts patches should specify a revision instead of trunk:
|
||||
@ -205,7 +205,7 @@ describe RuboCop::Cop::FormulaAudit::Patches do
|
||||
line: 5,
|
||||
column: 37,
|
||||
source: source }]
|
||||
elsif %r{^http://trac\.macports\.org}.match?(patch_url)
|
||||
elsif patch_url.match?(%r{^http://trac\.macports\.org})
|
||||
[{ message:
|
||||
<<~EOS.chomp,
|
||||
Patches from MacPorts Trac should be https://, not http:
|
||||
@ -215,7 +215,7 @@ describe RuboCop::Cop::FormulaAudit::Patches do
|
||||
line: 5,
|
||||
column: 9,
|
||||
source: source }]
|
||||
elsif %r{^http://bugs\.debian\.org}.match?(patch_url)
|
||||
elsif patch_url.match?(%r{^http://bugs\.debian\.org})
|
||||
[{ message:
|
||||
<<~EOS.chomp,
|
||||
Patches from Debian should be https://, not http:
|
||||
@ -226,7 +226,7 @@ describe RuboCop::Cop::FormulaAudit::Patches do
|
||||
column: 9,
|
||||
source: source }]
|
||||
# rubocop:disable Metrics/LineLength
|
||||
elsif %r{https?://patch-diff\.githubusercontent\.com/raw/(.+)/(.+)/pull/(.+)\.(?:diff|patch)}.match?(patch_url)
|
||||
elsif patch_url.match?(%r{https?://patch-diff\.githubusercontent\.com/raw/(.+)/(.+)/pull/(.+)\.(?:diff|patch)})
|
||||
# rubocop:enable Metrics/LineLength
|
||||
[{ message:
|
||||
<<~EOS,
|
||||
|
@ -229,9 +229,9 @@ class Version
|
||||
|
||||
stem = if spec.directory?
|
||||
spec.basename
|
||||
elsif %r{((?:sourceforge\.net|sf\.net)/.*)/download$}.match?(spec_s)
|
||||
elsif spec_s.match?(%r{((?:sourceforge\.net|sf\.net)/.*)/download$})
|
||||
Pathname.new(spec.dirname).stem
|
||||
elsif /\.[^a-zA-Z]+$/.match?(spec_s)
|
||||
elsif spec_s.match?(/\.[^a-zA-Z]+$/)
|
||||
Pathname.new(spec_s).basename
|
||||
else
|
||||
spec.stem
|
||||
|
Loading…
x
Reference in New Issue
Block a user