From b78028b9c2a13ebe51cbeecbd562b37f80c3f127 Mon Sep 17 00:00:00 2001 From: Issy Long Date: Sun, 13 Oct 2019 10:01:31 +0100 Subject: [PATCH] Auto-fix Performance/RegexpMatch offenses --- .../cask/artifact/abstract_uninstall.rb | 2 +- Library/Homebrew/cask/audit.rb | 2 +- Library/Homebrew/cleanup.rb | 2 +- Library/Homebrew/dependency_collector.rb | 2 +- Library/Homebrew/dev-cmd/audit.rb | 12 +++++----- Library/Homebrew/dev-cmd/bump-formula-pr.rb | 4 ++-- Library/Homebrew/dev-cmd/man.rb | 2 +- Library/Homebrew/diagnostic.rb | 2 +- Library/Homebrew/download_strategy.rb | 4 ++-- Library/Homebrew/extend/ENV/shared.rb | 2 +- .../extend/os/mac/formula_cellar_checks.rb | 2 +- .../Homebrew/extend/os/mac/system_config.rb | 2 +- Library/Homebrew/formula.rb | 2 +- Library/Homebrew/keg.rb | 6 ++--- Library/Homebrew/locale.rb | 4 ++-- .../Homebrew/requirements/java_requirement.rb | 2 +- .../cask/homepage_url_trailing_slash.rb | 2 +- Library/Homebrew/rubocops/homepage.rb | 2 +- Library/Homebrew/rubocops/lines.rb | 2 +- Library/Homebrew/rubocops/patches.rb | 4 ++-- Library/Homebrew/rubocops/urls.rb | 10 ++++----- Library/Homebrew/system_command.rb | 2 +- .../Homebrew/test/rubocops/homepage_spec.rb | 8 +++---- .../Homebrew/test/rubocops/patches_spec.rb | 22 +++++++++---------- Library/Homebrew/version.rb | 4 ++-- 25 files changed, 54 insertions(+), 54 deletions(-) diff --git a/Library/Homebrew/cask/artifact/abstract_uninstall.rb b/Library/Homebrew/cask/artifact/abstract_uninstall.rb index 19d8476b7e..48bc84250f 100644 --- a/Library/Homebrew/cask/artifact/abstract_uninstall.rb +++ b/Library/Homebrew/cask/artifact/abstract_uninstall.rb @@ -91,7 +91,7 @@ module Cask args: ["list", service], sudo: with_sudo, print_stderr: false ).stdout - if plist_status =~ /^\{/ + if /^\{/.match?(plist_status) command.run!("/bin/launchctl", args: ["remove", service], sudo: with_sudo) sleep 1 end diff --git a/Library/Homebrew/cask/audit.rb b/Library/Homebrew/cask/audit.rb index 6bb7739e3a..f97d3cab17 100644 --- a/Library/Homebrew/cask/audit.rb +++ b/Library/Homebrew/cask/audit.rb @@ -246,7 +246,7 @@ module Cask end 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 } end diff --git a/Library/Homebrew/cleanup.rb b/Library/Homebrew/cleanup.rb index e916737eeb..fcb2ce18e5 100644 --- a/Library/Homebrew/cleanup.rb +++ b/Library/Homebrew/cleanup.rb @@ -400,7 +400,7 @@ module Homebrew path.extend(ObserverPathnameExtension) if path.symlink? 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? end diff --git a/Library/Homebrew/dependency_collector.rb b/Library/Homebrew/dependency_collector.rb index 5fc7d90888..78b095c1e2 100644 --- a/Library/Homebrew/dependency_collector.rb +++ b/Library/Homebrew/dependency_collector.rb @@ -109,7 +109,7 @@ class DependencyCollector end def parse_string_spec(spec, tags) - if spec =~ HOMEBREW_TAP_FORMULA_REGEX + if HOMEBREW_TAP_FORMULA_REGEX.match?(spec) TapDependency.new(spec, tags) elsif tags.empty? Dependency.new(spec, tags) diff --git a/Library/Homebrew/dev-cmd/audit.rb b/Library/Homebrew/dev-cmd/audit.rb index 9d0d31b866..b93cd0846e 100644 --- a/Library/Homebrew/dev-cmd/audit.rb +++ b/Library/Homebrew/dev-cmd/audit.rb @@ -264,7 +264,7 @@ module Homebrew 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)." end @@ -890,7 +890,7 @@ module Homebrew end bin_names.each do |name| ["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}") end end @@ -942,7 +942,7 @@ module Homebrew 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}" end @@ -1069,7 +1069,7 @@ module Homebrew 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" end @@ -1092,7 +1092,7 @@ module Homebrew problem "Redundant :module value in URL" if mod == name - if url =~ %r{:[^/]+$} + if %r{:[^/]+$}.match?(url) mod = url.split(":").last if mod == name @@ -1131,7 +1131,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 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) problem http_content_problem diff --git a/Library/Homebrew/dev-cmd/bump-formula-pr.rb b/Library/Homebrew/dev-cmd/bump-formula-pr.rb index f9302b96dd..93d48fdb92 100644 --- a/Library/Homebrew/dev-cmd/bump-formula-pr.rb +++ b/Library/Homebrew/dev-cmd/bump-formula-pr.rb @@ -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 Utils.popen_read(tar, "-tf", resource_path) =~ %r{/.*\.} + if %r{/.*\.}.match?(Utils.popen_read(tar, "-tf", resource_path)) 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 e.github_message =~ /forking is disabled/ + raise unless /forking is disabled/.match?(e.github_message) # If the repository is private, forking might be disabled. # Create branches in the repository itself instead. diff --git a/Library/Homebrew/dev-cmd/man.rb b/Library/Homebrew/dev-cmd/man.rb index 147a34ef9a..0486365b7c 100644 --- a/Library/Homebrew/dev-cmd/man.rb +++ b/Library/Homebrew/dev-cmd/man.rb @@ -203,7 +203,7 @@ module Homebrew end # 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. lines << line.gsub(/^ +(-+[a-z-]+), (-+[a-z-]+) +/, "* `\\1`, `\\2`:\n ") diff --git a/Library/Homebrew/diagnostic.rb b/Library/Homebrew/diagnostic.rb index 17079ddefc..94f412e9a5 100644 --- a/Library/Homebrew/diagnostic.rb +++ b/Library/Homebrew/diagnostic.rb @@ -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 current_origin !~ %r{#{desired_origin}(\.git|/)?$}i + elsif !%r{#{desired_origin}(\.git|/)?$}i.match?(current_origin) <<~EOS Suspicious #{desired_origin} git origin remote found. The current git origin is: diff --git a/Library/Homebrew/download_strategy.rb b/Library/Homebrew/download_strategy.rb index 017d365c6f..671d283328 100644 --- a/Library/Homebrew/download_strategy.rb +++ b/Library/Homebrew/download_strategy.rb @@ -242,7 +242,7 @@ class AbstractFileDownloadStrategy < AbstractDownloadStrategy end 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) if uri.query @@ -860,7 +860,7 @@ class CVSDownloadStrategy < VCSDownloadStrategy if meta.key?(:module) @module = meta.fetch(:module) - elsif @url !~ %r{:[^/]+$} + elsif !%r{:[^/]+$}.match?(@url) @module = name else @module, @url = split_url(@url) diff --git a/Library/Homebrew/extend/ENV/shared.rb b/Library/Homebrew/extend/ENV/shared.rb index 067deee696..2ff175cde5 100644 --- a/Library/Homebrew/extend/ENV/shared.rb +++ b/Library/Homebrew/extend/ENV/shared.rb @@ -344,7 +344,7 @@ module SharedEnvExtension end 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" end diff --git a/Library/Homebrew/extend/os/mac/formula_cellar_checks.rb b/Library/Homebrew/extend/os/mac/formula_cellar_checks.rb index 9f0805404a..975311ca78 100644 --- a/Library/Homebrew/extend/os/mac/formula_cellar_checks.rb +++ b/Library/Homebrew/extend/os/mac/formula_cellar_checks.rb @@ -9,7 +9,7 @@ module FormulaCellarChecks formula.name.start_with?(formula_name) 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 < :yosemite && formula.name.start_with?("memcached") diff --git a/Library/Homebrew/extend/os/mac/system_config.rb b/Library/Homebrew/extend/os/mac/system_config.rb index 6d92ee2d60..b2a4d87dd8 100644 --- a/Library/Homebrew/extend/os/mac/system_config.rb +++ b/Library/Homebrew/extend/os/mac/system_config.rb @@ -22,7 +22,7 @@ class SystemConfig def describe_homebrew_ruby 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}" else s diff --git a/Library/Homebrew/formula.rb b/Library/Homebrew/formula.rb index 8c28a3f48e..6c96550ac2 100644 --- a/Library/Homebrew/formula.rb +++ b/Library/Homebrew/formula.rb @@ -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 path =~ %r{#{HOMEBREW_TAP_DIR_REGEX}/Aliases} + return unless %r{#{HOMEBREW_TAP_DIR_REGEX}/Aliases}.match?(path) return unless File.symlink?(path) path diff --git a/Library/Homebrew/keg.rb b/Library/Homebrew/keg.rb index bafea64514..4187ad6445 100644 --- a/Library/Homebrew/keg.rb +++ b/Library/Homebrew/keg.rb @@ -270,7 +270,7 @@ class Keg aliases.each do |a| # versioned aliases are handled below - next if a =~ /.+@./ + next if /.+@./.match?(a) alias_symlink = opt/a if alias_symlink.symlink? && alias_symlink.exist? @@ -340,7 +340,7 @@ class Keg next end - dst.uninstall_info if dst.to_s =~ INFOFILE_RX + dst.uninstall_info if INFOFILE_RX.match?(dst.to_s) dst.unlink remove_old_aliases Find.prune if src.directory? @@ -492,7 +492,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 relative_path.to_s =~ %r{[^/]*\.framework(/Versions)?$} + if %r{[^/]*\.framework(/Versions)?$}.match?(relative_path.to_s) :mkpath else :link diff --git a/Library/Homebrew/locale.rb b/Library/Homebrew/locale.rb index d9c520959c..854e1df8f2 100644 --- a/Library/Homebrew/locale.rb +++ b/Library/Homebrew/locale.rb @@ -13,7 +13,7 @@ class Locale def self.parse(string) 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| string.scan(/(?:\-|^)(#{regex})(?:\-|$)/).flatten.first @@ -39,7 +39,7 @@ class Locale next if value.nil? 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) end diff --git a/Library/Homebrew/requirements/java_requirement.rb b/Library/Homebrew/requirements/java_requirement.rb index 2d7e0594d8..05e88180ae 100644 --- a/Library/Homebrew/requirements/java_requirement.rb +++ b/Library/Homebrew/requirements/java_requirement.rb @@ -28,7 +28,7 @@ class JavaRequirement < Requirement end def initialize(tags = []) - @version = tags.shift if /^\d/ =~ tags.first + @version = tags.shift if /^\d/.match?(tags.first) super(tags) @cask = suggestion.token end diff --git a/Library/Homebrew/rubocops/cask/homepage_url_trailing_slash.rb b/Library/Homebrew/rubocops/cask/homepage_url_trailing_slash.rb index c6c7f2c1fe..9f00a07d84 100644 --- a/Library/Homebrew/rubocops/cask/homepage_url_trailing_slash.rb +++ b/Library/Homebrew/rubocops/cask/homepage_url_trailing_slash.rb @@ -17,7 +17,7 @@ module RuboCop url_node = stanza.stanza_node.first_argument url = url_node.str_content - return if url !~ %r{^.+://[^/]+$} + return if !%r{^.+://[^/]+$}.match?(url) add_offense(url_node, location: :expression, message: format(MSG_NO_SLASH, url: url)) diff --git a/Library/Homebrew/rubocops/homepage.rb b/Library/Homebrew/rubocops/homepage.rb index 53f06405c9..8f2fd2c36b 100644 --- a/Library/Homebrew/rubocops/homepage.rb +++ b/Library/Homebrew/rubocops/homepage.rb @@ -17,7 +17,7 @@ module RuboCop 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})." end diff --git a/Library/Homebrew/rubocops/lines.rb b/Library/Homebrew/rubocops/lines.rb index 31f84d57b9..7c097a1d37 100644 --- a/Library/Homebrew/rubocops/lines.rb +++ b/Library/Homebrew/rubocops/lines.rb @@ -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 @formula_name =~ /^kibana(@\d[\d.]*)?$/ + next if /^kibana(@\d[\d.]*)?$/.match?(@formula_name) first_param, second_param = parameters(method_node) next if !node_equals?(first_param, "npm") || diff --git a/Library/Homebrew/rubocops/patches.rb b/Library/Homebrew/rubocops/patches.rb index c5494b0377..03f2e72997 100644 --- a/Library/Homebrew/rubocops/patches.rb +++ b/Library/Homebrew/rubocops/patches.rb @@ -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) - if patch_url !~ /\?full_index=\w+$/ + if !/\?full_index=\w+$/.match?(patch_url) 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) - if patch_url !~ /[a-fA-F0-9]{40}/ + if !/[a-fA-F0-9]{40}/.match?(patch_url) problem <<~EOS.chomp GitHub/Gist patches should specify a revision: #{patch_url} diff --git a/Library/Homebrew/rubocops/urls.rb b/Library/Homebrew/rubocops/urls.rb index f5e2d65521..4d2ae1974c 100644 --- a/Library/Homebrew/rubocops/urls.rb +++ b/Library/Homebrew/rubocops/urls.rb @@ -123,18 +123,18 @@ module RuboCop 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})." end - if url =~ %r{^https?://prdownloads\.} + if %r{^https?://prdownloads\.}.match?(url) 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 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})." 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 unless url !~ /\.git$/ + next unless !/\.git$/.match?(url) 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 unless url !~ %r{releases/download} + next unless !%r{releases/download}.match?(url) problem "Use GitHub tarballs rather than zipballs (url is #{url})." end diff --git a/Library/Homebrew/system_command.rb b/Library/Homebrew/system_command.rb index e524359a10..f7ccf88331 100644 --- a/Library/Homebrew/system_command.rb +++ b/Library/Homebrew/system_command.rb @@ -225,7 +225,7 @@ class SystemCommand def warn_plist_garbage(garbage) return unless ARGV.verbose? - return unless garbage =~ /\S/ + return unless /\S/.match?(garbage) opoo "Received non-XML output from #{Formatter.identifier(command.first)}:" $stderr.puts garbage.strip diff --git a/Library/Homebrew/test/rubocops/homepage_spec.rb b/Library/Homebrew/test/rubocops/homepage_spec.rb index 284d501df3..65d621b74d 100644 --- a/Library/Homebrew/test/rubocops/homepage_spec.rb +++ b/Library/Homebrew/test/rubocops/homepage_spec.rb @@ -73,8 +73,8 @@ describe RuboCop::Cop::FormulaAudit::Homepage do RUBY inspect_source(source) - if homepage =~ %r{http:\/\/www\.freedesktop\.org} - if homepage =~ /Software/ + if %r{http:\/\/www\.freedesktop\.org}.match?(homepage) + if /Software/.match?(homepage) 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 homepage =~ %r{https:\/\/code\.google\.com} + elsif %r{https:\/\/code\.google\.com}.match?(homepage) expected_offenses = [{ message: "#{homepage} should end with a slash", severity: :convention, line: 2, column: 2, 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/`", severity: :convention, line: 2, diff --git a/Library/Homebrew/test/rubocops/patches_spec.rb b/Library/Homebrew/test/rubocops/patches_spec.rb index efb899d946..9e8826ce1d 100644 --- a/Library/Homebrew/test/rubocops/patches_spec.rb +++ b/Library/Homebrew/test/rubocops/patches_spec.rb @@ -48,7 +48,7 @@ describe RuboCop::Cop::FormulaAudit::Patches do EOS inspect_source(source) - expected_offense = if patch_url =~ %r{/raw\.github\.com/} + expected_offense = if %r{/raw\.github\.com/}.match?(patch_url) [{ 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 patch_url =~ %r{macports/trunk} + elsif %r{macports/trunk}.match?(patch_url) [{ 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 patch_url =~ %r{^http://trac\.macports\.org} + elsif %r{^http://trac\.macports\.org}.match?(patch_url) [{ 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 patch_url =~ %r{^http://bugs\.debian\.org} + elsif %r{^http://bugs\.debian\.org}.match?(patch_url) [{ message: <<~EOS.chomp, Patches from Debian should be https://, not http: @@ -88,7 +88,7 @@ describe RuboCop::Cop::FormulaAudit::Patches do line: 5, column: 5, 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: <<~EOS, use GitHub pull request URLs: @@ -100,7 +100,7 @@ describe RuboCop::Cop::FormulaAudit::Patches do line: 5, column: 5, 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: <<~EOS, GitHub patches should use the full_index parameter: @@ -183,7 +183,7 @@ describe RuboCop::Cop::FormulaAudit::Patches do RUBY inspect_source(source) - expected_offense = if patch_url =~ %r{/raw\.github\.com/} + expected_offense = if %r{/raw\.github\.com/}.match?(patch_url) [{ message: <<~EOS.chomp, GitHub/Gist patches should specify a revision: @@ -193,7 +193,7 @@ describe RuboCop::Cop::FormulaAudit::Patches do line: 5, column: 16, source: source }] - elsif patch_url =~ %r{macports/trunk} + elsif %r{macports/trunk}.match?(patch_url) [{ message: <<~EOS.chomp, MacPorts patches should specify a revision instead of trunk: @@ -203,7 +203,7 @@ describe RuboCop::Cop::FormulaAudit::Patches do line: 5, column: 37, source: source }] - elsif patch_url =~ %r{^http://trac\.macports\.org} + elsif %r{^http://trac\.macports\.org}.match?(patch_url) [{ message: <<~EOS.chomp, Patches from MacPorts Trac should be https://, not http: @@ -213,7 +213,7 @@ describe RuboCop::Cop::FormulaAudit::Patches do line: 5, column: 9, source: source }] - elsif patch_url =~ %r{^http://bugs\.debian\.org} + elsif %r{^http://bugs\.debian\.org}.match?(patch_url) [{ message: <<~EOS.chomp, Patches from Debian should be https://, not http: @@ -223,7 +223,7 @@ describe RuboCop::Cop::FormulaAudit::Patches do line: 5, column: 9, 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: <<~EOS, use GitHub pull request URLs: diff --git a/Library/Homebrew/version.rb b/Library/Homebrew/version.rb index b24d340838..f7cedc7396 100644 --- a/Library/Homebrew/version.rb +++ b/Library/Homebrew/version.rb @@ -229,9 +229,9 @@ class Version stem = if spec.directory? 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 - elsif /\.[^a-zA-Z]+$/ =~ spec_s + elsif /\.[^a-zA-Z]+$/.match?(spec_s) Pathname.new(spec_s).basename else spec.stem