rubocop: fix Lint/NoReturnInBeginEndBlocks

This commit is contained in:
Jonathan Chang 2020-11-10 00:11:22 +11:00
parent 20b8fcd726
commit 500908ee6f
8 changed files with 53 additions and 51 deletions

View File

@ -84,9 +84,11 @@ module Homebrew
formula = begin
Formulary.from_rack(HOMEBREW_CELLAR/formula_name)
rescue FormulaUnavailableError, TapFormulaAmbiguityError, TapFormulaWithOldnameAmbiguityError
return false
nil
end
return false if formula.blank?
resource_name = basename.to_s[/\A.*?--(.*?)--?(?:#{Regexp.escape(version)})/, 1]
if resource_name == "patch"
@ -113,9 +115,11 @@ module Homebrew
cask = begin
Cask::CaskLoader.load(name)
rescue Cask::CaskError
return false
nil
end
return false if cask.blank?
return true unless basename.to_s.match?(/\A#{Regexp.escape(name)}--#{Regexp.escape(cask.version)}\b/)
return true if scrub && !cask.versions.include?(cask.version)

View File

@ -111,15 +111,19 @@ module Homebrew
new_formula = begin
Formulary.from_contents(formula_name, formula_path, new_contents, :stable)
rescue FormulaUnavailableError
return "#{formula_name}: delete #{reason}".strip
nil
end
return "#{formula_name}: delete #{reason}".strip if new_formula.blank?
old_formula = begin
Formulary.from_contents(formula_name, formula_path, old_contents, :stable)
rescue FormulaUnavailableError
return "#{formula_name} #{new_formula.stable.version} (new formula)"
nil
end
return "#{formula_name} #{new_formula.stable.version} (new formula)" if old_formula.blank?
if old_formula.stable.version != new_formula.stable.version
"#{formula_name} #{new_formula.stable.version}"
elsif old_formula.revision != new_formula.revision

View File

@ -33,9 +33,11 @@ module UnpackStrategy
system_command! "ditto",
args: ["-x", "-k", path, unpack_dir],
verbose: verbose
return
nil
end
return if result.blank?
volumes = result.stderr.chomp
.split("\n")
.map { |l| l[/\A skipping: (.+) volume label\Z/, 1] }

View File

@ -36,9 +36,11 @@ module Utils
tag_version = begin
MacOS::Version.from_symbol(tag)
rescue MacOSVersionError
return
nil
end
return if tag_version.blank?
keys.find do |key|
MacOS::Version.from_symbol(key) <= tag_version
rescue MacOSVersionError

View File

@ -139,9 +139,11 @@ module RuboCop
URI(remove_non_ascii(host))
rescue URI::InvalidURIError
# Can't check if we can't parse.
return true
nil
end
return true if host_uri.blank?
host = if host.match?(/:\d/) && host_uri.port != 80
"#{host_uri.host}:#{host_uri.port}"
else

View File

@ -50,9 +50,11 @@ module Homebrew
)
rescue GitHub::Error => e
opoo "Error searching on GitHub: #{e}\n"
return results
nil
end
return results if matches.blank?
matches.each do |match|
name = File.basename(match["path"], ".rb")
tap = Tap.fetch(match["repository"]["full_name"])

View File

@ -141,43 +141,37 @@ module GitHub
end
end
# Given an API response from GitHub, warn the user if their credentials
# have insufficient permissions.
def api_credentials_error_message(response_headers, needed_scopes)
return if response_headers.empty?
@api_credentials_error_message ||= begin
unauthorized = (response_headers["http/1.1"] == "401 Unauthorized")
scopes = response_headers["x-accepted-oauth-scopes"].to_s.split(", ")
if unauthorized && scopes.blank?
needed_human_scopes = needed_scopes.join(", ")
credentials_scopes = response_headers["x-oauth-scopes"]
return if needed_human_scopes.blank? && credentials_scopes.blank?
unauthorized = (response_headers["http/1.1"] == "401 Unauthorized")
scopes = response_headers["x-accepted-oauth-scopes"].to_s.split(", ")
return unless unauthorized && scopes.blank?
needed_human_scopes = "none" if needed_human_scopes.blank?
credentials_scopes = "none" if credentials_scopes.blank?
needed_human_scopes = needed_scopes.join(", ")
credentials_scopes = response_headers["x-oauth-scopes"]
return if needed_human_scopes.blank? && credentials_scopes.blank?
case GitHub.api_credentials_type
when :keychain_username_password
onoe <<~EOS
Your macOS keychain GitHub credentials do not have sufficient scope!
Scopes they need: #{needed_human_scopes}
Scopes they have: #{credentials_scopes}
Create a personal access token:
#{ALL_SCOPES_URL}
#{Utils::Shell.set_variable_in_profile("HOMEBREW_GITHUB_API_TOKEN", "your_token_here")}
EOS
when :env_token
onoe <<~EOS
Your HOMEBREW_GITHUB_API_TOKEN does not have sufficient scope!
Scopes it needs: #{needed_human_scopes}
Scopes it has: #{credentials_scopes}
Create a new personal access token:
#{ALL_SCOPES_URL}
#{Utils::Shell.set_variable_in_profile("HOMEBREW_GITHUB_API_TOKEN", "your_token_here")}
EOS
end
end
true
needed_human_scopes = "none" if needed_human_scopes.blank?
credentials_scopes = "none" if credentials_scopes.blank?
what = case GitHub.api_credentials_type
when :keychain_username_password
"macOS keychain GitHub"
when :env_token
"HOMEBREW_GITHUB_API_TOKEN"
end
@api_credentials_error_message ||= onoe <<~EOS
Your #{what} credentials do not have sufficient scope!
Scopes required: #{needed_human_scopes}
Scopes present: #{credentials_scopes}
Create a personal access token:
#{ALL_SCOPES_URL}
#{Utils::Shell.set_variable_in_profile("HOMEBREW_GITHUB_API_TOKEN", "your_token_here")}
EOS
end
def open_api(url, data: nil, data_binary_path: nil, request_method: nil, scopes: [].freeze, parse_json: true)

View File

@ -70,28 +70,20 @@ module SharedAudits
def gitlab_repo_data(user, repo)
@gitlab_repo_data ||= {}
@gitlab_repo_data["#{user}/#{repo}"] ||= begin
out, _, status= curl_output("--request", "GET", "https://gitlab.com/api/v4/projects/#{user}%2F#{repo}")
return unless status.success?
JSON.parse(out)
out, _, status = curl_output("https://gitlab.com/api/v4/projects/#{user}%2F#{repo}")
JSON.parse(out) if status.success?
end
@gitlab_repo_data["#{user}/#{repo}"]
end
def gitlab_release_data(user, repo, tag)
id = "#{user}/#{repo}/#{tag}"
@gitlab_release_data ||= {}
@gitlab_release_data[id] ||= begin
out, _, status= curl_output(
out, _, status = curl_output(
"https://gitlab.com/api/v4/projects/#{user}%2F#{repo}/releases/#{tag}", "--fail"
)
return unless status.success?
JSON.parse(out)
JSON.parse(out) if status.success?
end
@gitlab_release_data[id]
end
GITLAB_PRERELEASE_ALLOWLIST = {}.freeze