From 58e36c73193befb57d351344cea2a4a33fef850d Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Fri, 23 Sep 2016 22:02:23 +0200 Subject: Fix Style/GuardClause. --- Library/Homebrew/dev-cmd/audit.rb | 46 +++++++++++++++--------------------- Library/Homebrew/dev-cmd/pull.rb | 22 ++++++++--------- Library/Homebrew/dev-cmd/test-bot.rb | 33 ++++++++++++-------------- 3 files changed, 45 insertions(+), 56 deletions(-) (limited to 'Library/Homebrew/dev-cmd') diff --git a/Library/Homebrew/dev-cmd/audit.rb b/Library/Homebrew/dev-cmd/audit.rb index 61d136daf..1a6e47dbe 100644 --- a/Library/Homebrew/dev-cmd/audit.rb +++ b/Library/Homebrew/dev-cmd/audit.rb @@ -284,9 +284,8 @@ class FormulaAuditor problem "Should not have both `head` and `head do`" end - if present.include?("bottle modifier") && present.include?("bottle block") - problem "Should not have `bottle :unneeded/:disable` and `bottle do`" - end + return unless present.include?("bottle modifier") && present.include?("bottle block") + problem "Should not have `bottle :unneeded/:disable` and `bottle do`" end def audit_class @@ -350,9 +349,8 @@ class FormulaAuditor same_name_tap_formulae.delete(full_name) - unless same_name_tap_formulae.empty? - problem "Formula name conflicts with #{same_name_tap_formulae.join ", "}" - end + return if same_name_tap_formulae.empty? + problem "Formula name conflicts with #{same_name_tap_formulae.join ", "}" end def audit_deps @@ -485,9 +483,8 @@ class FormulaAuditor problem "Description shouldn't start with an indefinite article (#{$1})" end - if desc.downcase.start_with? "#{formula.name} " - problem "Description shouldn't include the formula name" - end + return unless desc.downcase.start_with? "#{formula.name} " + problem "Description shouldn't include the formula name" end def audit_homepage @@ -564,9 +561,9 @@ class FormulaAuditor end def audit_bottle_spec - if formula.bottle_disabled? && !formula.bottle_disable_reason.valid? - problem "Unrecognized bottle modifier" - end + return unless formula.bottle_disabled? + return if formula.bottle_disable_reason.valid? + problem "Unrecognized bottle modifier" end def audit_github_repository @@ -594,9 +591,8 @@ class FormulaAuditor problem "GitHub repository not notable enough (<20 forks, <20 watchers and <50 stars)" end - if Date.parse(metadata["created_at"]) > (Date.today - 30) - problem "GitHub repository too new (<30 days old)" - end + return if Date.parse(metadata["created_at"]) <= (Date.today - 30) + problem "GitHub repository too new (<30 days old)" end def audit_specs @@ -736,9 +732,8 @@ class FormulaAuditor problem "Please set plist_options when using a formula-defined plist." end - if text.include?('require "language/go"') && !text.include?("go_resource") - problem "require \"language/go\" is unnecessary unless using `go_resource`s" - end + return unless text.include?('require "language/go"') && !text.include?("go_resource") + problem "require \"language/go\" is unnecessary unless using `go_resource`s" end def audit_line(line, lineno) @@ -983,9 +978,8 @@ class FormulaAuditor problem "Use \#{pkgshare} instead of \#{share}/#{formula.name}" end - if line =~ %r{share(\s*[/+]\s*)(['"])#{Regexp.escape(formula.name)}(?:\2|/)} - problem "Use pkgshare instead of (share#{$1}\"#{formula.name}\")" - end + return unless line =~ %r{share(\s*[/+]\s*)(['"])#{Regexp.escape(formula.name)}(?:\2|/)} + problem "Use pkgshare instead of (share#{$1}\"#{formula.name}\")" end def audit_caveats @@ -1115,9 +1109,8 @@ class ResourceAuditor problem "version #{version} should not have a leading 'v'" end - if version.to_s =~ /_\d+$/ - problem "version #{version} should not end with an underline and a number" - end + return unless version.to_s =~ /_\d+$/ + problem "version #{version} should not end with an underline and a number" end def audit_checksum @@ -1183,9 +1176,8 @@ class ResourceAuditor end end - if url_strategy == DownloadStrategyDetector.detect("", using) - problem "Redundant :using value in URL" - end + return unless url_strategy == DownloadStrategyDetector.detect("", using) + problem "Redundant :using value in URL" end def audit_urls diff --git a/Library/Homebrew/dev-cmd/pull.rb b/Library/Homebrew/dev-cmd/pull.rb index b06719fb1..857c55993 100644 --- a/Library/Homebrew/dev-cmd/pull.rb +++ b/Library/Homebrew/dev-cmd/pull.rb @@ -531,19 +531,19 @@ module Homebrew req = Net::HTTP::Head.new bottle_info.url req.initialize_http_header "User-Agent" => HOMEBREW_USER_AGENT_RUBY res = http.request req - if res.is_a?(Net::HTTPSuccess) - break - elsif res.is_a?(Net::HTTPClientError) - if retry_count >= max_retries - raise "Failed to find published #{f} bottle at #{url}!" - end - print(wrote_dots ? "." : "Waiting on Bintray.") - wrote_dots = true - sleep poll_retry_delay_seconds - retry_count += 1 - else + break if res.is_a?(Net::HTTPSuccess) + + unless res.is_a?(Net::HTTPClientError) raise "Failed to find published #{f} bottle at #{url} (#{res.code} #{res.message})!" end + + if retry_count >= max_retries + raise "Failed to find published #{f} bottle at #{url}!" + end + print(wrote_dots ? "." : "Waiting on Bintray.") + wrote_dots = true + sleep poll_retry_delay_seconds + retry_count += 1 end end diff --git a/Library/Homebrew/dev-cmd/test-bot.rb b/Library/Homebrew/dev-cmd/test-bot.rb index abf0235e5..935a40731 100644 --- a/Library/Homebrew/dev-cmd/test-bot.rb +++ b/Library/Homebrew/dev-cmd/test-bot.rb @@ -123,13 +123,12 @@ module Homebrew end end - if git_url = ENV["UPSTREAM_GIT_URL"] || ENV["GIT_URL"] - # Also can get tap from Jenkins GIT_URL. - url_path = git_url.sub(%r{^https?://github\.com/}, "").chomp("/").sub(/\.git$/, "") - begin - return Tap.fetch(url_path) if url_path =~ HOMEBREW_TAP_REGEX - rescue - end + return unless git_url = ENV["UPSTREAM_GIT_URL"] || ENV["GIT_URL"] + # Also can get tap from Jenkins GIT_URL. + url_path = git_url.sub(%r{^https?://github\.com/}, "").chomp("/").sub(/\.git$/, "") + begin + return Tap.fetch(url_path) if url_path =~ HOMEBREW_TAP_REGEX + rescue end end @@ -1001,10 +1000,9 @@ module Homebrew end end - if git_tag - safe_system "git", "tag", "--force", git_tag - safe_system "git", "push", "--force", remote, "master:master", "refs/tags/#{git_tag}" - end + return unless git_tag + safe_system "git", "tag", "--force", git_tag + safe_system "git", "push", "--force", remote, "master:master", "refs/tags/#{git_tag}" end def sanitize_argv_and_env @@ -1053,13 +1051,12 @@ module Homebrew ARGV << "--fast" if ARGV.include?("--ci-master") - if ARGV.include? "--local" - ENV["HOMEBREW_CACHE"] = "#{ENV["HOME"]}/Library/Caches/Homebrew" - mkdir_p ENV["HOMEBREW_CACHE"] - ENV["HOMEBREW_HOME"] = ENV["HOME"] = "#{Dir.pwd}/home" - mkdir_p ENV["HOME"] - ENV["HOMEBREW_LOGS"] = "#{Dir.pwd}/logs" - end + return unless ARGV.include?("--local") + ENV["HOMEBREW_CACHE"] = "#{ENV["HOME"]}/Library/Caches/Homebrew" + mkdir_p ENV["HOMEBREW_CACHE"] + ENV["HOMEBREW_HOME"] = ENV["HOME"] = "#{Dir.pwd}/home" + mkdir_p ENV["HOME"] + ENV["HOMEBREW_LOGS"] = "#{Dir.pwd}/logs" end def test_bot -- cgit v1.2.3