Auto-fix Performance/RegexpMatch offenses

This commit is contained in:
Issy Long 2019-10-13 10:01:31 +01:00
parent 6d7ef5c94d
commit b78028b9c2
No known key found for this signature in database
GPG Key ID: 8247C390DADC67D4
25 changed files with 54 additions and 54 deletions

View File

@ -91,7 +91,7 @@ module Cask
args: ["list", service], args: ["list", service],
sudo: with_sudo, print_stderr: false sudo: with_sudo, print_stderr: false
).stdout ).stdout
if plist_status =~ /^\{/ if /^\{/.match?(plist_status)
command.run!("/bin/launchctl", args: ["remove", service], sudo: with_sudo) command.run!("/bin/launchctl", args: ["remove", service], sudo: with_sudo)
sleep 1 sleep 1
end end

View File

@ -246,7 +246,7 @@ module Cask
end end
def bad_url_format?(regex, valid_formats_array) def bad_url_format?(regex, valid_formats_array)
return false unless cask.url.to_s =~ regex return false unless cask.url.to_s.match?(regex)
valid_formats_array.none? { |format| cask.url.to_s =~ format } valid_formats_array.none? { |format| cask.url.to_s =~ format }
end end

View File

@ -400,7 +400,7 @@ module Homebrew
path.extend(ObserverPathnameExtension) path.extend(ObserverPathnameExtension)
if path.symlink? if path.symlink?
unless path.resolved_path_exists? unless path.resolved_path_exists?
if path.to_s =~ Keg::INFOFILE_RX if Keg::INFOFILE_RX.match?(path.to_s)
path.uninstall_info unless dry_run? path.uninstall_info unless dry_run?
end end

View File

@ -109,7 +109,7 @@ class DependencyCollector
end end
def parse_string_spec(spec, tags) def parse_string_spec(spec, tags)
if spec =~ HOMEBREW_TAP_FORMULA_REGEX if HOMEBREW_TAP_FORMULA_REGEX.match?(spec)
TapDependency.new(spec, tags) TapDependency.new(spec, tags)
elsif tags.empty? elsif tags.empty?
Dependency.new(spec, tags) Dependency.new(spec, tags)

View File

@ -264,7 +264,7 @@ module Homebrew
problem "'__END__' was found, but 'DATA' is not used" if text.end? && !text.data? problem "'__END__' was found, but 'DATA' is not used" if text.end? && !text.data?
if text =~ /inreplace [^\n]* do [^\n]*\n[^\n]*\.gsub![^\n]*\n\ *end/m if /inreplace [^\n]* do [^\n]*\n[^\n]*\.gsub![^\n]*\n\ *end/m.match?(text)
problem "'inreplace ... do' was used for a single substitution (use the non-block form instead)." problem "'inreplace ... do' was used for a single substitution (use the non-block form instead)."
end end
@ -890,7 +890,7 @@ module Homebrew
end end
bin_names.each do |name| bin_names.each do |name|
["system", "shell_output", "pipe_output"].each do |cmd| ["system", "shell_output", "pipe_output"].each do |cmd|
if text =~ /test do.*#{cmd}[\(\s]+['"]#{Regexp.escape(name)}[\s'"]/m if /test do.*#{cmd}[\(\s]+['"]#{Regexp.escape(name)}[\s'"]/m.match?(text)
problem %Q(fully scope test #{cmd} calls, e.g. #{cmd} "\#{bin}/#{name}") problem %Q(fully scope test #{cmd} calls, e.g. #{cmd} "\#{bin}/#{name}")
end end
end end
@ -942,7 +942,7 @@ module Homebrew
problem "`#{Regexp.last_match(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 %r{#\{share\}/#{Regexp.escape(formula.name)}[/'"]}.match?(line)
problem "Use \#{pkgshare} instead of \#{share}/#{formula.name}" problem "Use \#{pkgshare} instead of \#{share}/#{formula.name}"
end end
@ -1069,7 +1069,7 @@ module Homebrew
problem "version #{version} should not have a leading 'v'" if version.to_s.start_with?("v") problem "version #{version} should not have a leading 'v'" if version.to_s.start_with?("v")
return unless version.to_s =~ /_\d+$/ return unless /_\d+$/.match?(version.to_s)
problem "version #{version} should not end with an underline and a number" problem "version #{version} should not end with an underline and a number"
end end
@ -1092,7 +1092,7 @@ module Homebrew
problem "Redundant :module value in URL" if mod == name problem "Redundant :module value in URL" if mod == name
if url =~ %r{:[^/]+$} if %r{:[^/]+$}.match?(url)
mod = url.split(":").last mod = url.split(":").last
if mod == name if mod == name
@ -1131,7 +1131,7 @@ module Homebrew
if strategy <= CurlDownloadStrategy && !url.start_with?("file") if strategy <= CurlDownloadStrategy && !url.start_with?("file")
# A `brew mirror`'ed URL is usually not yet reachable at the time of # A `brew mirror`'ed URL is usually not yet reachable at the time of
# pull request. # pull request.
next if url =~ %r{^https://dl.bintray.com/homebrew/mirror/} next if %r{^https://dl.bintray.com/homebrew/mirror/}.match?(url)
if http_content_problem = curl_check_http_content(url) if http_content_problem = curl_check_http_content(url)
problem http_content_problem problem http_content_problem

View File

@ -156,7 +156,7 @@ module Homebrew
gnu_tar_gtar_path = HOMEBREW_PREFIX/"opt/gnu-tar/bin/gtar" gnu_tar_gtar_path = HOMEBREW_PREFIX/"opt/gnu-tar/bin/gtar"
gnu_tar_gtar = gnu_tar_gtar_path if gnu_tar_gtar_path.executable? gnu_tar_gtar = gnu_tar_gtar_path if gnu_tar_gtar_path.executable?
tar = which("gtar") || gnu_tar_gtar || which("tar") tar = which("gtar") || gnu_tar_gtar || which("tar")
if Utils.popen_read(tar, "-tf", resource_path) =~ %r{/.*\.} if %r{/.*\.}.match?(Utils.popen_read(tar, "-tf", resource_path))
new_hash = resource_path.sha256 new_hash = resource_path.sha256
else else
odie "#{resource_path} is not a valid tar file!" odie "#{resource_path} is not a valid tar file!"
@ -310,7 +310,7 @@ module Homebrew
end end
username = response.fetch("owner").fetch("login") username = response.fetch("owner").fetch("login")
rescue GitHub::AuthenticationFailedError => e rescue GitHub::AuthenticationFailedError => e
raise unless e.github_message =~ /forking is disabled/ raise unless /forking is disabled/.match?(e.github_message)
# If the repository is private, forking might be disabled. # If the repository is private, forking might be disabled.
# Create branches in the repository itself instead. # Create branches in the repository itself instead.

View File

@ -203,7 +203,7 @@ module Homebrew
end end
# Omit the common global_options documented separately in the man page. # Omit the common global_options documented separately in the man page.
next if line =~ /--(debug|force|help|quiet|verbose) / next if /--(debug|force|help|quiet|verbose) /.match?(line)
# Format one option or a comma-separated pair of short and long options. # Format one option or a comma-separated pair of short and long options.
lines << line.gsub(/^ +(-+[a-z-]+), (-+[a-z-]+) +/, "* `\\1`, `\\2`:\n ") lines << line.gsub(/^ +(-+[a-z-]+), (-+[a-z-]+) +/, "* `\\1`, `\\2`:\n ")

View File

@ -122,7 +122,7 @@ module Homebrew
properly. You can solve this by adding the remote: properly. You can solve this by adding the remote:
git -C "#{repository_path}" remote add origin #{Formatter.url("https://github.com/#{desired_origin}.git")} git -C "#{repository_path}" remote add origin #{Formatter.url("https://github.com/#{desired_origin}.git")}
EOS EOS
elsif current_origin !~ %r{#{desired_origin}(\.git|/)?$}i elsif !%r{#{desired_origin}(\.git|/)?$}i.match?(current_origin)
<<~EOS <<~EOS
Suspicious #{desired_origin} git origin remote found. Suspicious #{desired_origin} git origin remote found.
The current git origin is: The current git origin is:

View File

@ -242,7 +242,7 @@ class AbstractFileDownloadStrategy < AbstractDownloadStrategy
end end
def parse_basename(url) def parse_basename(url)
uri_path = if URI::DEFAULT_PARSER.make_regexp =~ url uri_path = if URI::DEFAULT_PARSER.make_regexp&.match?(url)
uri = URI(url) uri = URI(url)
if uri.query if uri.query
@ -860,7 +860,7 @@ class CVSDownloadStrategy < VCSDownloadStrategy
if meta.key?(:module) if meta.key?(:module)
@module = meta.fetch(:module) @module = meta.fetch(:module)
elsif @url !~ %r{:[^/]+$} elsif !%r{:[^/]+$}.match?(@url)
@module = name @module = name
else else
@module, @url = split_url(@url) @module, @url = split_url(@url)

View File

@ -344,7 +344,7 @@ module SharedEnvExtension
end end
def check_for_compiler_universal_support def check_for_compiler_universal_support
return unless homebrew_cc =~ GNU_GCC_REGEXP return unless GNU_GCC_REGEXP.match?(homebrew_cc)
raise "Non-Apple GCC can't build universal binaries" raise "Non-Apple GCC can't build universal binaries"
end end

View File

@ -9,7 +9,7 @@ module FormulaCellarChecks
formula.name.start_with?(formula_name) formula.name.start_with?(formula_name)
end end
return if formula.name =~ Version.formula_optionally_versioned_regex(:php) return if formula.name&.match?(Version.formula_optionally_versioned_regex(:php))
return if MacOS.version < :mavericks && formula.name.start_with?("postgresql") return if MacOS.version < :mavericks && formula.name.start_with?("postgresql")
return if MacOS.version < :yosemite && formula.name.start_with?("memcached") return if MacOS.version < :yosemite && formula.name.start_with?("memcached")

View File

@ -22,7 +22,7 @@ class SystemConfig
def describe_homebrew_ruby def describe_homebrew_ruby
s = describe_homebrew_ruby_version s = describe_homebrew_ruby_version
if RUBY_PATH.to_s !~ %r{^/System/Library/Frameworks/Ruby\.framework/Versions/[12]\.[089]/usr/bin/ruby} if !%r{^/System/Library/Frameworks/Ruby\.framework/Versions/[12]\.[089]/usr/bin/ruby}.match?(RUBY_PATH.to_s)
"#{s} => #{RUBY_PATH}" "#{s} => #{RUBY_PATH}"
else else
s s

View File

@ -266,7 +266,7 @@ class Formula
# and is specified to this instance. # and is specified to this instance.
def installed_alias_path def installed_alias_path
path = build.source["path"] if build.is_a?(Tab) path = build.source["path"] if build.is_a?(Tab)
return unless path =~ %r{#{HOMEBREW_TAP_DIR_REGEX}/Aliases} return unless %r{#{HOMEBREW_TAP_DIR_REGEX}/Aliases}.match?(path)
return unless File.symlink?(path) return unless File.symlink?(path)
path path

View File

@ -270,7 +270,7 @@ class Keg
aliases.each do |a| aliases.each do |a|
# versioned aliases are handled below # versioned aliases are handled below
next if a =~ /.+@./ next if /.+@./.match?(a)
alias_symlink = opt/a alias_symlink = opt/a
if alias_symlink.symlink? && alias_symlink.exist? if alias_symlink.symlink? && alias_symlink.exist?
@ -340,7 +340,7 @@ class Keg
next next
end end
dst.uninstall_info if dst.to_s =~ INFOFILE_RX dst.uninstall_info if INFOFILE_RX.match?(dst.to_s)
dst.unlink dst.unlink
remove_old_aliases remove_old_aliases
Find.prune if src.directory? Find.prune if src.directory?
@ -492,7 +492,7 @@ class Keg
# the :link strategy. However, for Foo.framework and # the :link strategy. However, for Foo.framework and
# Foo.framework/Versions we have to use :mkpath so that multiple formulae # Foo.framework/Versions we have to use :mkpath so that multiple formulae
# can link their versions into it and `brew [un]link` works. # can link their versions into it and `brew [un]link` works.
if relative_path.to_s =~ %r{[^/]*\.framework(/Versions)?$} if %r{[^/]*\.framework(/Versions)?$}.match?(relative_path.to_s)
:mkpath :mkpath
else else
:link :link

View File

@ -13,7 +13,7 @@ class Locale
def self.parse(string) def self.parse(string)
string = string.to_s string = string.to_s
raise ParserError, "'#{string}' cannot be parsed to a #{self}" if string !~ LOCALE_REGEX raise ParserError, "'#{string}' cannot be parsed to a #{self}" if !LOCALE_REGEX.match?(string)
scan = proc do |regex| scan = proc do |regex|
string.scan(/(?:\-|^)(#{regex})(?:\-|$)/).flatten.first string.scan(/(?:\-|^)(#{regex})(?:\-|$)/).flatten.first
@ -39,7 +39,7 @@ class Locale
next if value.nil? next if value.nil?
regex = self.class.const_get("#{key.upcase}_REGEX") regex = self.class.const_get("#{key.upcase}_REGEX")
raise ParserError, "'#{value}' does not match #{regex}" unless value =~ regex raise ParserError, "'#{value}' does not match #{regex}" unless value&.match?(regex)
instance_variable_set(:"@#{key}", value) instance_variable_set(:"@#{key}", value)
end end

View File

@ -28,7 +28,7 @@ class JavaRequirement < Requirement
end end
def initialize(tags = []) def initialize(tags = [])
@version = tags.shift if /^\d/ =~ tags.first @version = tags.shift if /^\d/.match?(tags.first)
super(tags) super(tags)
@cask = suggestion.token @cask = suggestion.token
end end

View File

@ -17,7 +17,7 @@ module RuboCop
url_node = stanza.stanza_node.first_argument url_node = stanza.stanza_node.first_argument
url = url_node.str_content url = url_node.str_content
return if url !~ %r{^.+://[^/]+$} return if !%r{^.+://[^/]+$}.match?(url)
add_offense(url_node, location: :expression, add_offense(url_node, location: :expression,
message: format(MSG_NO_SLASH, url: url)) message: format(MSG_NO_SLASH, url: url))

View File

@ -17,7 +17,7 @@ module RuboCop
problem "Formula should have a homepage." if homepage_node.nil? || homepage.empty? problem "Formula should have a homepage." if homepage_node.nil? || homepage.empty?
unless homepage =~ %r{^https?://} unless %r{^https?://}.match?(homepage)
problem "The homepage should start with http or https (URL is #{homepage})." problem "The homepage should start with http or https (URL is #{homepage})."
end end

View File

@ -335,7 +335,7 @@ module RuboCop
find_every_method_call_by_name(body_node, :system).each do |method_node| find_every_method_call_by_name(body_node, :system).each do |method_node|
# Skip Kibana: npm cache edge (see formula for more details) # Skip Kibana: npm cache edge (see formula for more details)
next if @formula_name =~ /^kibana(@\d[\d.]*)?$/ next if /^kibana(@\d[\d.]*)?$/.match?(@formula_name)
first_param, second_param = parameters(method_node) first_param, second_param = parameters(method_node)
next if !node_equals?(first_param, "npm") || next if !node_equals?(first_param, "npm") ||

View File

@ -30,7 +30,7 @@ module RuboCop
patch_url = string_content(patch) patch_url = string_content(patch)
gh_patch_param_pattern = %r{https?://github\.com/.+/.+/(?:commit|pull)/[a-fA-F0-9]*.(?:patch|diff)} 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) if regex_match_group(patch, gh_patch_param_pattern)
if patch_url !~ /\?full_index=\w+$/ if !/\?full_index=\w+$/.match?(patch_url)
problem <<~EOS problem <<~EOS
GitHub patches should use the full_index parameter: GitHub patches should use the full_index parameter:
#{patch_url}?full_index=1 #{patch_url}?full_index=1
@ -43,7 +43,7 @@ module RuboCop
%r{gist\.github\.com/.+/raw}, %r{gist\.github\.com/.+/raw},
%r{gist\.githubusercontent\.com/.+/raw}]) %r{gist\.githubusercontent\.com/.+/raw}])
if regex_match_group(patch, gh_patch_patterns) if regex_match_group(patch, gh_patch_patterns)
if patch_url !~ /[a-fA-F0-9]{40}/ if !/[a-fA-F0-9]{40}/.match?(patch_url)
problem <<~EOS.chomp problem <<~EOS.chomp
GitHub/Gist patches should specify a revision: GitHub/Gist patches should specify a revision:
#{patch_url} #{patch_url}

View File

@ -123,18 +123,18 @@ module RuboCop
problem "Don't use /download in SourceForge urls (url is #{url})." if url.end_with?("/download") problem "Don't use /download in SourceForge urls (url is #{url})." if url.end_with?("/download")
if url =~ %r{^https?://sourceforge\.} if %r{^https?://sourceforge\.}.match?(url)
problem "Use https://downloads.sourceforge.net to get geolocation (url is #{url})." problem "Use https://downloads.sourceforge.net to get geolocation (url is #{url})."
end end
if url =~ %r{^https?://prdownloads\.} if %r{^https?://prdownloads\.}.match?(url)
problem <<~EOS.chomp problem <<~EOS.chomp
Don't use prdownloads in SourceForge urls (url is #{url}). Don't use prdownloads in SourceForge urls (url is #{url}).
See: http://librelist.com/browser/homebrew/2011/1/12/prdownloads-is-bad/ See: http://librelist.com/browser/homebrew/2011/1/12/prdownloads-is-bad/
EOS EOS
end end
if url =~ %r{^http://\w+\.dl\.} if %r{^http://\w+\.dl\.}.match?(url)
problem "Don't use specific dl mirrors in SourceForge urls (url is #{url})." problem "Don't use specific dl mirrors in SourceForge urls (url is #{url})."
end end
@ -195,7 +195,7 @@ module RuboCop
# Use new-style archive downloads # Use new-style archive downloads
archive_gh_pattern = %r{https://.*github.*/(?:tar|zip)ball/} archive_gh_pattern = %r{https://.*github.*/(?:tar|zip)ball/}
audit_urls(urls, archive_gh_pattern) do |_, url| audit_urls(urls, archive_gh_pattern) do |_, url|
next unless url !~ /\.git$/ next unless !/\.git$/.match?(url)
problem "Use /archive/ URLs for GitHub tarballs (url is #{url})." problem "Use /archive/ URLs for GitHub tarballs (url is #{url})."
end end
@ -203,7 +203,7 @@ module RuboCop
# Don't use GitHub .zip files # Don't use GitHub .zip files
zip_gh_pattern = %r{https://.*github.*/(archive|releases)/.*\.zip$} zip_gh_pattern = %r{https://.*github.*/(archive|releases)/.*\.zip$}
audit_urls(urls, zip_gh_pattern) do |_, url| audit_urls(urls, zip_gh_pattern) do |_, url|
next unless url !~ %r{releases/download} next unless !%r{releases/download}.match?(url)
problem "Use GitHub tarballs rather than zipballs (url is #{url})." problem "Use GitHub tarballs rather than zipballs (url is #{url})."
end end

View File

@ -225,7 +225,7 @@ class SystemCommand
def warn_plist_garbage(garbage) def warn_plist_garbage(garbage)
return unless ARGV.verbose? return unless ARGV.verbose?
return unless garbage =~ /\S/ return unless /\S/.match?(garbage)
opoo "Received non-XML output from #{Formatter.identifier(command.first)}:" opoo "Received non-XML output from #{Formatter.identifier(command.first)}:"
$stderr.puts garbage.strip $stderr.puts garbage.strip

View File

@ -73,8 +73,8 @@ describe RuboCop::Cop::FormulaAudit::Homepage do
RUBY RUBY
inspect_source(source) inspect_source(source)
if homepage =~ %r{http:\/\/www\.freedesktop\.org} if %r{http:\/\/www\.freedesktop\.org}.match?(homepage)
if homepage =~ /Software/ if /Software/.match?(homepage)
expected_offenses = [{ message: "#{homepage} should be styled " \ expected_offenses = [{ message: "#{homepage} should be styled " \
"`https://wiki.freedesktop.org/www/Software/project_name`", "`https://wiki.freedesktop.org/www/Software/project_name`",
severity: :convention, severity: :convention,
@ -89,13 +89,13 @@ describe RuboCop::Cop::FormulaAudit::Homepage do
column: 2, column: 2,
source: source }] source: source }]
end end
elsif homepage =~ %r{https:\/\/code\.google\.com} elsif %r{https:\/\/code\.google\.com}.match?(homepage)
expected_offenses = [{ message: "#{homepage} should end with a slash", expected_offenses = [{ message: "#{homepage} should end with a slash",
severity: :convention, severity: :convention,
line: 2, line: 2,
column: 2, column: 2,
source: source }] source: source }]
elsif homepage =~ /foo\.(sf|sourceforge)\.net/ elsif /foo\.(sf|sourceforge)\.net/.match?(homepage)
expected_offenses = [{ message: "#{homepage} should be `https://foo.sourceforge.io/`", expected_offenses = [{ message: "#{homepage} should be `https://foo.sourceforge.io/`",
severity: :convention, severity: :convention,
line: 2, line: 2,

View File

@ -48,7 +48,7 @@ describe RuboCop::Cop::FormulaAudit::Patches do
EOS EOS
inspect_source(source) inspect_source(source)
expected_offense = if patch_url =~ %r{/raw\.github\.com/} expected_offense = if %r{/raw\.github\.com/}.match?(patch_url)
[{ message: [{ message:
<<~EOS.chomp, <<~EOS.chomp,
GitHub/Gist patches should specify a revision: GitHub/Gist patches should specify a revision:
@ -58,7 +58,7 @@ describe RuboCop::Cop::FormulaAudit::Patches do
line: 5, line: 5,
column: 12, column: 12,
source: source }] source: source }]
elsif patch_url =~ %r{macports/trunk} elsif %r{macports/trunk}.match?(patch_url)
[{ message: [{ message:
<<~EOS.chomp, <<~EOS.chomp,
MacPorts patches should specify a revision instead of trunk: MacPorts patches should specify a revision instead of trunk:
@ -68,7 +68,7 @@ describe RuboCop::Cop::FormulaAudit::Patches do
line: 5, line: 5,
column: 33, column: 33,
source: source }] source: source }]
elsif patch_url =~ %r{^http://trac\.macports\.org} elsif %r{^http://trac\.macports\.org}.match?(patch_url)
[{ message: [{ message:
<<~EOS.chomp, <<~EOS.chomp,
Patches from MacPorts Trac should be https://, not http: Patches from MacPorts Trac should be https://, not http:
@ -78,7 +78,7 @@ describe RuboCop::Cop::FormulaAudit::Patches do
line: 5, line: 5,
column: 5, column: 5,
source: source }] source: source }]
elsif patch_url =~ %r{^http://bugs\.debian\.org} elsif %r{^http://bugs\.debian\.org}.match?(patch_url)
[{ message: [{ message:
<<~EOS.chomp, <<~EOS.chomp,
Patches from Debian should be https://, not http: Patches from Debian should be https://, not http:
@ -88,7 +88,7 @@ describe RuboCop::Cop::FormulaAudit::Patches do
line: 5, line: 5,
column: 5, column: 5,
source: source }] source: source }]
elsif patch_url =~ %r{https?://patch-diff\.githubusercontent\.com/raw/(.+)/(.+)/pull/(.+)\.(?:diff|patch)} elsif %r{https?://patch-diff\.githubusercontent\.com/raw/(.+)/(.+)/pull/(.+)\.(?:diff|patch)}.match?(patch_url)
[{ message: [{ message:
<<~EOS, <<~EOS,
use GitHub pull request URLs: use GitHub pull request URLs:
@ -100,7 +100,7 @@ describe RuboCop::Cop::FormulaAudit::Patches do
line: 5, line: 5,
column: 5, column: 5,
source: source }] source: source }]
elsif patch_url =~ %r{https?://github\.com/.+/.+/(?:commit|pull)/[a-fA-F0-9]*.(?:patch|diff)} elsif %r{https?://github\.com/.+/.+/(?:commit|pull)/[a-fA-F0-9]*.(?:patch|diff)}.match?(patch_url)
[{ message: [{ message:
<<~EOS, <<~EOS,
GitHub patches should use the full_index parameter: GitHub patches should use the full_index parameter:
@ -183,7 +183,7 @@ describe RuboCop::Cop::FormulaAudit::Patches do
RUBY RUBY
inspect_source(source) inspect_source(source)
expected_offense = if patch_url =~ %r{/raw\.github\.com/} expected_offense = if %r{/raw\.github\.com/}.match?(patch_url)
[{ message: [{ message:
<<~EOS.chomp, <<~EOS.chomp,
GitHub/Gist patches should specify a revision: GitHub/Gist patches should specify a revision:
@ -193,7 +193,7 @@ describe RuboCop::Cop::FormulaAudit::Patches do
line: 5, line: 5,
column: 16, column: 16,
source: source }] source: source }]
elsif patch_url =~ %r{macports/trunk} elsif %r{macports/trunk}.match?(patch_url)
[{ message: [{ message:
<<~EOS.chomp, <<~EOS.chomp,
MacPorts patches should specify a revision instead of trunk: MacPorts patches should specify a revision instead of trunk:
@ -203,7 +203,7 @@ describe RuboCop::Cop::FormulaAudit::Patches do
line: 5, line: 5,
column: 37, column: 37,
source: source }] source: source }]
elsif patch_url =~ %r{^http://trac\.macports\.org} elsif %r{^http://trac\.macports\.org}.match?(patch_url)
[{ message: [{ message:
<<~EOS.chomp, <<~EOS.chomp,
Patches from MacPorts Trac should be https://, not http: Patches from MacPorts Trac should be https://, not http:
@ -213,7 +213,7 @@ describe RuboCop::Cop::FormulaAudit::Patches do
line: 5, line: 5,
column: 9, column: 9,
source: source }] source: source }]
elsif patch_url =~ %r{^http://bugs\.debian\.org} elsif %r{^http://bugs\.debian\.org}.match?(patch_url)
[{ message: [{ message:
<<~EOS.chomp, <<~EOS.chomp,
Patches from Debian should be https://, not http: Patches from Debian should be https://, not http:
@ -223,7 +223,7 @@ describe RuboCop::Cop::FormulaAudit::Patches do
line: 5, line: 5,
column: 9, column: 9,
source: source }] source: source }]
elsif patch_url =~ %r{https?://patch-diff\.githubusercontent\.com/raw/(.+)/(.+)/pull/(.+)\.(?:diff|patch)} elsif %r{https?://patch-diff\.githubusercontent\.com/raw/(.+)/(.+)/pull/(.+)\.(?:diff|patch)}.match?(patch_url)
[{ message: [{ message:
<<~EOS, <<~EOS,
use GitHub pull request URLs: use GitHub pull request URLs:

View File

@ -229,9 +229,9 @@ class Version
stem = if spec.directory? stem = if spec.directory?
spec.basename spec.basename
elsif %r{((?:sourceforge\.net|sf\.net)/.*)/download$} =~ spec_s elsif %r{((?:sourceforge\.net|sf\.net)/.*)/download$}.match?(spec_s)
Pathname.new(spec.dirname).stem Pathname.new(spec.dirname).stem
elsif /\.[^a-zA-Z]+$/ =~ spec_s elsif /\.[^a-zA-Z]+$/.match?(spec_s)
Pathname.new(spec_s).basename Pathname.new(spec_s).basename
else else
spec.stem spec.stem