From fa760a2f26ad9701ec41259815f341c83a3dc8ce Mon Sep 17 00:00:00 2001 From: Mike McQuaid Date: Tue, 7 Jul 2020 13:12:37 +0100 Subject: [PATCH] Fix `brew style`. --- Library/Homebrew/diagnostic.rb | 2 +- Library/Homebrew/extend/os/mac/diagnostic.rb | 3 ++- Library/Homebrew/language/python.rb | 2 +- Library/Homebrew/requirements/java_requirement.rb | 2 +- Library/Homebrew/rubocops/formula_desc.rb | 4 ++-- Library/Homebrew/rubocops/homepage.rb | 2 +- Library/Homebrew/rubocops/urls.rb | 2 +- Library/Homebrew/test/rubocops/homepage_spec.rb | 6 +++--- Library/Homebrew/test/rubocops/patches_spec.rb | 8 ++++---- 9 files changed, 16 insertions(+), 15 deletions(-) diff --git a/Library/Homebrew/diagnostic.rb b/Library/Homebrew/diagnostic.rb index c5832d9ecb2b2..eb1d44169299e 100644 --- a/Library/Homebrew/diagnostic.rb +++ b/Library/Homebrew/diagnostic.rb @@ -561,7 +561,7 @@ def check_coretap_git_branch return if !Utils.git_available? || !(coretap_path/".git").exist? branch = coretap_path.git_branch - return if branch.nil? || branch =~ /master/ + return if branch.blank? || branch.include?("master") <<~EOS #{CoreTap.instance.full_name} is not on the master branch. diff --git a/Library/Homebrew/extend/os/mac/diagnostic.rb b/Library/Homebrew/extend/os/mac/diagnostic.rb index 843196de9a1ab..a3498e0e2b943 100644 --- a/Library/Homebrew/extend/os/mac/diagnostic.rb +++ b/Library/Homebrew/extend/os/mac/diagnostic.rb @@ -191,7 +191,8 @@ def check_xcode_select_path def check_xcode_license_approved # If the user installs Xcode-only, they have to approve the # license or no "xc*" tool will work. - return unless `/usr/bin/xcrun clang 2>&1` =~ /license/ && !$CHILD_STATUS.success? + return unless `/usr/bin/xcrun clang 2>&1`.include?("license") + return if $CHILD_STATUS.success? <<~EOS You have not agreed to the Xcode license. diff --git a/Library/Homebrew/language/python.rb b/Library/Homebrew/language/python.rb index a80dd1bd89142..7c73980253a93 100644 --- a/Library/Homebrew/language/python.rb +++ b/Library/Homebrew/language/python.rb @@ -268,7 +268,7 @@ def pip_install(targets) t.stage { do_install Pathname.pwd } else - t = t.lines.map(&:strip) if t.respond_to?(:lines) && t =~ /\n/ + t = t.lines.map(&:strip) if t.respond_to?(:lines) && t.include?("\n") do_install t end end diff --git a/Library/Homebrew/requirements/java_requirement.rb b/Library/Homebrew/requirements/java_requirement.rb index 6d7c66c73ceae..a2e4fa2d9e5b1 100644 --- a/Library/Homebrew/requirements/java_requirement.rb +++ b/Library/Homebrew/requirements/java_requirement.rb @@ -86,7 +86,7 @@ def version_without_plus end def exact_version? - @version && @version.to_s.chars.last != "+" + @version && @version.to_s[-1] != "+" end def fits_latest? diff --git a/Library/Homebrew/rubocops/formula_desc.rb b/Library/Homebrew/rubocops/formula_desc.rb index fbd3ef9aacf29..3449ee43a8748 100644 --- a/Library/Homebrew/rubocops/formula_desc.rb +++ b/Library/Homebrew/rubocops/formula_desc.rb @@ -47,7 +47,7 @@ def audit_formula(_node, _class_node, _parent_class_node, body_node) # Check if command-line is wrongly used in formula's desc if match = regex_match_group(desc, /(command ?line)/i) - c = match.to_s.chars.first + c = match.to_s[0] problem "Description should use \"#{c}ommand-line\" instead of \"#{match}\"" end @@ -86,7 +86,7 @@ def autocorrect(node) correction = node.source first_word = string_content(node).split.first unless VALID_LOWERCASE_WORDS.include?(first_word) - first_char = first_word.to_s.chars.first + first_char = first_word.to_s[0] correction.sub!(/^(['"]?)([a-z])/, "\\1#{first_char.upcase}") if first_char end correction.sub!(/^(['"]?)an?\s/i, "\\1") diff --git a/Library/Homebrew/rubocops/homepage.rb b/Library/Homebrew/rubocops/homepage.rb index 8eb81cf0c642a..e8b8be8ada487 100644 --- a/Library/Homebrew/rubocops/homepage.rb +++ b/Library/Homebrew/rubocops/homepage.rb @@ -37,7 +37,7 @@ def audit_formula(_node, _class_node, _parent_class_node, body_node) # https://wiki.freedesktop.org/project_name. # "Software" is redirected to https://wiki.freedesktop.org/www/Software/project_name when %r{^http://((?:www|nice|libopenraw|liboil|telepathy|xorg)\.)?freedesktop\.org/(?:wiki/)?} - if homepage =~ /Software/ + if homepage.include?("Software") problem "#{homepage} should be styled `https://wiki.freedesktop.org/www/Software/project_name`" else problem "#{homepage} should be styled `https://wiki.freedesktop.org/project_name`" diff --git a/Library/Homebrew/rubocops/urls.rb b/Library/Homebrew/rubocops/urls.rb index d83bfd113be36..648d707bfa94c 100644 --- a/Library/Homebrew/rubocops/urls.rb +++ b/Library/Homebrew/rubocops/urls.rb @@ -247,7 +247,7 @@ def audit_formula(_node, _class_node, _parent_class_node, body_node) # 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 url.match?(%r{releases/download}) + next if url.include?("releases/download") problem "Use GitHub tarballs rather than zipballs (url is #{url})." end diff --git a/Library/Homebrew/test/rubocops/homepage_spec.rb b/Library/Homebrew/test/rubocops/homepage_spec.rb index 033cd0a0bbcf7..27de067d59a5e 100644 --- a/Library/Homebrew/test/rubocops/homepage_spec.rb +++ b/Library/Homebrew/test/rubocops/homepage_spec.rb @@ -73,8 +73,8 @@ class #{name.capitalize} < Formula RUBY inspect_source(source) - if homepage.match?(%r{http://www\.freedesktop\.org}) - if homepage.match?(/Software/) + if homepage.include?("http://www.freedesktop.org") + if homepage.include?("Software") expected_offenses = [{ message: "#{homepage} should be styled " \ "`https://wiki.freedesktop.org/www/Software/project_name`", severity: :convention, @@ -89,7 +89,7 @@ class #{name.capitalize} < Formula column: 2, source: source }] end - elsif homepage.match?(%r{https://code\.google\.com}) + elsif homepage.include?("https://code.google.com") expected_offenses = [{ message: "#{homepage} should end with a slash", severity: :convention, line: 2, diff --git a/Library/Homebrew/test/rubocops/patches_spec.rb b/Library/Homebrew/test/rubocops/patches_spec.rb index 42883c84588aa..0209a6a566fe1 100644 --- a/Library/Homebrew/test/rubocops/patches_spec.rb +++ b/Library/Homebrew/test/rubocops/patches_spec.rb @@ -48,7 +48,7 @@ def patches EOS inspect_source(source) - expected_offense = if patch_url.match?(%r{/raw\.github\.com/}) + expected_offense = if patch_url.include?("/raw.github.com/") [{ message: <<~EOS.chomp, GitHub/Gist patches should specify a revision: @@ -58,7 +58,7 @@ def patches line: 5, column: 12, source: source }] - elsif patch_url.match?(%r{macports/trunk}) + elsif patch_url.include?("macports/trunk") [{ message: <<~EOS.chomp, MacPorts patches should specify a revision instead of trunk: @@ -232,7 +232,7 @@ class Foo < Formula RUBY inspect_source(source) - expected_offense = if patch_url.match?(%r{/raw\.github\.com/}) + expected_offense = if patch_url.include?("/raw.github.com/") [{ message: <<~EOS.chomp, GitHub/Gist patches should specify a revision: @@ -242,7 +242,7 @@ class Foo < Formula line: 5, column: 16, source: source }] - elsif patch_url.match?(%r{macports/trunk}) + elsif patch_url.include?("macports/trunk") [{ message: <<~EOS.chomp, MacPorts patches should specify a revision instead of trunk: