Auto-fix Style/RedundantBegin offenses

- This also required auto-fixes for Layout/EmptyLinesAroundBlockBody and
  Layout/InconsistentIndentation once the auto-fixer had got rid of the
  "redundant begin"s.
This commit is contained in:
Issy Long 2019-10-13 10:03:26 +01:00
parent b78028b9c2
commit 341ea60807
No known key found for this signature in database
GPG Key ID: 8247C390DADC67D4
40 changed files with 376 additions and 479 deletions

View File

@ -142,7 +142,6 @@ class BottlePublisher
retry_count = 0
# We're in the cache; make sure to force re-download
loop do
begin
curl_download url, to: filename
break
rescue
@ -153,7 +152,6 @@ class BottlePublisher
curl_retry_delay_seconds *= 2
retry_count += 1
end
end
checksum = Checksum.new(:sha256, bottle_info["sha256"])
Pathname.new(filename).verify_checksum(checksum)
end

View File

@ -65,7 +65,6 @@ module Cask
return yield nil if choices.empty?
Tempfile.open(["choices", ".xml"]) do |file|
begin
file.write Plist::Emit.dump(choices)
file.close
yield file.path
@ -75,5 +74,4 @@ module Cask
end
end
end
end
end

View File

@ -19,13 +19,11 @@ module Cask
return to_enum unless block_given?
Tap.flat_map(&:cask_files).each do |f|
begin
yield CaskLoader::FromTapPathLoader.new(f).load
rescue CaskUnreadableError => e
opoo e.message
end
end
end
def tap
return super if block_given? # Object#tap

View File

@ -200,12 +200,10 @@ module Cask
end
remaining = all_args.select do |arg|
begin
!process_arguments([arg]).empty?
rescue OptionParser::InvalidOption, OptionParser::MissingArgument, OptionParser::AmbiguousOption
true
end
end
remaining + non_options
end

View File

@ -14,7 +14,6 @@ module Cask
def run
odie "Installing casks is supported only on macOS" unless OS.mac?
casks.each do |cask|
begin
Installer.new(cask, binaries: binaries?,
verbose: verbose?,
force: force?,
@ -25,7 +24,6 @@ module Cask
opoo e.message
end
end
end
def self.help
"installs the given Cask"

View File

@ -45,13 +45,11 @@ module Cask
return if dry_run?
upgradable_casks.each do |(old_cask, new_cask)|
begin
upgrade_cask(old_cask, new_cask)
rescue CaskError => e
caught_exceptions << e
next
end
end
return if caught_exceptions.empty?
raise MultipleCaskErrors, caught_exceptions if caught_exceptions.count > 1

View File

@ -137,12 +137,10 @@ module Cask
locales = MacOS.languages
.map do |language|
begin
Locale.parse(language)
rescue Locale::ParserError
nil
end
end
.compact
locales.each do |locale|
@ -255,7 +253,6 @@ module Cask
ORDINARY_ARTIFACT_CLASSES.each do |klass|
define_method(klass.dsl_key) do |*args|
begin
if [*artifacts.map(&:class), klass].include?(Artifact::StageOnly) &&
(artifacts.map(&:class) & ACTIVATABLE_ARTIFACT_CLASSES).any?
raise CaskInvalidError.new(cask, "'stage_only' must be the only activatable artifact.")
@ -268,7 +265,6 @@ module Cask
raise CaskInvalidError.new(cask, "invalid '#{klass.dsl_key}' stanza: #{e}")
end
end
end
ARTIFACT_BLOCK_CLASSES.each do |klass|
[klass.dsl_key, klass.uninstall_dsl_key].each do |dsl_key|

View File

@ -111,14 +111,12 @@ module Cask
return unless @cask.conflicts_with
@cask.conflicts_with[:cask].each do |conflicting_cask|
begin
conflicting_cask = CaskLoader.load(conflicting_cask)
raise CaskConflictError.new(@cask, conflicting_cask) if conflicting_cask.installed?
rescue CaskUnavailableError
next # Ignore conflicting Casks that do not exist.
end
end
end
def reinstall
odebug "Cask::Installer#reinstall"

View File

@ -86,11 +86,9 @@ class Caveats
def keg
@keg ||= [f.prefix, f.opt_prefix, f.linked_keg].map do |d|
begin
Keg.new(d.resolved_path)
rescue
nil
end
end.compact.first
end

View File

@ -25,13 +25,11 @@ module Homebrew
deps_of_installed = installed.flat_map do |f|
f.runtime_dependencies.map do |dep|
begin
dep.to_formula.full_name
rescue FormulaUnavailableError
dep.name
end
end
end
leaves = installed.map(&:full_name) - deps_of_installed
leaves.each(&method(:puts))

View File

@ -382,7 +382,6 @@ module Homebrew
end
reinstallable.each do |f|
begin
reinstall_formula(f, build_from_source: true)
rescue FormulaInstallationAlreadyAttemptedError
# We already attempted to reinstall f as part of the dependency tree of
@ -398,5 +397,4 @@ module Homebrew
ofail e
end
end
end
end

View File

@ -68,7 +68,6 @@ module Homebrew
uses = formulae.select do |f|
used_formulae.all? do |ff|
begin
deps = f.runtime_dependencies if only_installed_arg
deps ||= if recursive
recursive_includes(Dependency, f, includes, ignores)
@ -77,19 +76,16 @@ module Homebrew
end
deps.any? do |dep|
begin
dep.to_formula.full_name == ff.full_name
rescue
dep.name == ff.name
end
end
rescue FormulaUnavailableError
# Silently ignore this case as we don't care about things used in
# taps that aren't currently tapped.
next
end
end
end
return if uses.empty?

View File

@ -63,13 +63,11 @@ class DescriptionCacheStore < CacheStore
return populate_if_empty! if database.empty?
formula_names.each do |name|
begin
update!(name, Formula[name].desc)
rescue FormulaUnavailableError, *FormulaVersions::IGNORED_EXCEPTIONS
delete!(name)
end
end
end
# Use an array of formulae names to delete them from the `DescriptionCacheStore`.
#

View File

@ -434,7 +434,6 @@ module Homebrew
def audit_conflicts
formula.conflicts.each do |c|
begin
Formulary.factory(c.name)
rescue TapFormulaUnavailableError
# Don't complain about missing cross-tap conflicts.
@ -445,7 +444,6 @@ module Homebrew
problem "Ambiguous conflicting formula #{c.name.inspect}."
end
end
end
def audit_keg_only_style
return unless formula.keg_only?

View File

@ -718,7 +718,6 @@ module Homebrew
def check_for_unreadable_installed_formula
formula_unavailable_exceptions = []
Formula.racks.each do |rack|
begin
Formulary.from_rack(rack)
rescue FormulaUnreadableError, FormulaClassUnavailableError,
TapFormulaUnreadableError, TapFormulaClassUnavailableError => e
@ -727,7 +726,6 @@ module Homebrew
TapFormulaAmbiguityError, TapFormulaWithOldnameAmbiguityError
nil
end
end
return if formula_unavailable_exceptions.empty?
<<~EOS

View File

@ -213,11 +213,9 @@ module SharedEnvExtension
path.append(
# user paths
ORIGINAL_PATHS.map do |p|
begin
p.realpath.to_s
rescue
nil
end
end - %w[/usr/X11/bin /opt/X11/bin],
)
self["PATH"] = path

View File

@ -17,12 +17,10 @@ module Superenv
def homebrew_extra_paths
paths = []
paths += %w[binutils make].map do |f|
begin
bin = Formula[f].opt_bin
bin if bin.directory?
rescue FormulaUnavailableError
nil
end
end.compact
paths
end

View File

@ -387,11 +387,9 @@ class Formula
return [] if versioned_formula?
Pathname.glob(path.to_s.gsub(/\.rb$/, "@*.rb")).map do |path|
begin
Formula[path.basename(".rb").to_s]
rescue FormulaUnavailableError
nil
end
end.compact.sort
end
@ -1387,7 +1385,6 @@ class Formula
# @private
def self.each
files.each do |file|
begin
yield Formulary.factory(file)
rescue => e
# Don't let one broken formula break commands. But do complain.
@ -1396,7 +1393,6 @@ class Formula
next
end
end
end
# Clear cache of .racks
def self.clear_racks_cache
@ -1425,11 +1421,9 @@ class Formula
# @private
def self.installed
@installed ||= racks.flat_map do |rack|
begin
Formulary.from_rack(rack)
rescue
[]
end
end.uniq(&:name)
end
@ -1568,11 +1562,9 @@ class Formula
read_from_tab: read_from_tab,
undeclared: undeclared,
).map do |d|
begin
d.to_formula
rescue FormulaUnavailableError
nil
end
end.compact
end

View File

@ -351,7 +351,6 @@ class FormulaInstaller
return if ARGV.force?
conflicts = formula.conflicts.select do |c|
begin
f = Formulary.factory(c.name)
rescue TapFormulaUnavailableError
# If the formula name is a fully-qualified name let's silently
@ -373,7 +372,6 @@ class FormulaInstaller
else
f.linked_keg.exist? && f.opt_prefix.exist?
end
end
raise FormulaConflictError.new(formula, conflicts) unless conflicts.empty?
end

View File

@ -106,11 +106,9 @@ require "PATH"
ENV["HOMEBREW_PATH"] ||= ENV["PATH"]
ORIGINAL_PATHS = PATH.new(ENV["HOMEBREW_PATH"]).map do |p|
begin
Pathname.new(p).expand_path
rescue
rescue
nil
end
end.compact.freeze
HOMEBREW_INTERNAL_COMMAND_ALIASES = {

View File

@ -22,7 +22,6 @@ module Homebrew
def attempt_directory_creation
Keg::MUST_EXIST_DIRECTORIES.each do |dir|
begin
FileUtils.mkdir_p(dir) unless dir.exist?
# Create these files to ensure that these directories aren't removed
@ -34,7 +33,6 @@ module Homebrew
nil
end
end
end
def check_cc_argv
return unless ARGV.cc

View File

@ -128,7 +128,6 @@ class Keg
keg_names = kegs.select(&:optlinked?).map(&:name)
keg_formulae = []
kegs_by_source = kegs.group_by do |keg|
begin
# First, attempt to resolve the keg to a formula
# to get up-to-date name and tap information.
f = keg.to_formula
@ -139,7 +138,6 @@ class Keg
# fall back to the information in the tab.
[keg.name, keg.tab.tap]
end
end
all_required_kegs = Set.new
all_dependents = []

View File

@ -37,7 +37,6 @@ module Readall
def valid_formulae?(formulae)
failed = false
formulae.each do |file|
begin
Formulary.factory(file)
rescue Interrupt
raise
@ -46,7 +45,6 @@ module Readall
puts e
failed = true
end
end
!failed
end

View File

@ -184,13 +184,11 @@ class SoftwareSpec
def recursive_dependencies
deps_f = []
recursive_dependencies = deps.map do |dep|
begin
deps_f << dep.to_formula
dep
rescue TapFormulaUnavailableError
# Don't complain about missing cross-tap dependencies
next
end
end.compact.uniq
deps_f.compact.each do |f|
f.recursive_dependencies.each do |dep|
@ -386,12 +384,11 @@ class BottleSpecification
def checksums
tags = collector.keys.sort_by do |tag|
# Sort non-MacOS tags below MacOS tags.
begin
OS::Mac::Version.from_symbol tag
rescue ArgumentError
"0.#{tag}"
end
end
checksums = {}
tags.reverse_each do |tag|
checksum = collector[tag]

View File

@ -148,7 +148,6 @@ class SystemCommand
break if readable_sources.empty?
readable_sources.each do |source|
begin
line = source.readline_nonblock || ""
type = (source == sources[0]) ? :stdout : :stderr
yield(type, line)
@ -156,7 +155,6 @@ class SystemCommand
next
end
end
end
sources.each(&:close_read)
end

View File

@ -199,7 +199,6 @@ shared_examples "#uninstall_phase or #zap_phase" do
let(:cask) { Cask::CaskLoader.load(cask_path("with-#{artifact_dsl_key}-#{directive}")) }
around do |example|
begin
ENV["HOME"] = dir
FileUtils.touch paths
@ -208,7 +207,6 @@ shared_examples "#uninstall_phase or #zap_phase" do
ensure
FileUtils.rm_f paths
end
end
before do
allow_any_instance_of(Cask::Artifact::AbstractUninstall).to receive(:trash_paths)

View File

@ -5,14 +5,12 @@ require_relative "shared_examples/invalid_option"
describe Cask::Cmd::Create, :cask do
around do |example|
begin
example.run
ensure
%w[new-cask additional-cask another-cask yet-another-cask local-caff].each do |cask|
FileUtils.rm_f Cask::CaskLoader.path(cask)
end
end
end
before do
allow_any_instance_of(described_class).to receive(:exec_editor)

View File

@ -473,7 +473,6 @@ describe Cask::DSL, :cask do
end
it "does not include a trailing slash" do
begin
original_appdir = Cask::Config.global.appdir
Cask::Config.global.appdir = "#{original_appdir}/"
@ -486,7 +485,6 @@ describe Cask::DSL, :cask do
Cask::Config.global.appdir = original_appdir
end
end
end
describe "#artifacts" do
it "sorts artifacts according to the preferable installation order" do

View File

@ -34,7 +34,6 @@ describe Homebrew::Cleanup do
let(:lock_file) { Pathname.new("#{HOMEBREW_LOCKS}/foo") }
around do |example|
begin
FileUtils.touch ds_store
FileUtils.touch lock_file
@ -43,7 +42,6 @@ describe Homebrew::Cleanup do
FileUtils.rm_f ds_store
FileUtils.rm_f lock_file
end
end
describe "::cleanup" do
it "removes .DS_Store and lock files" do

View File

@ -33,7 +33,6 @@ RSpec.shared_context "custom internal commands" do
end
around do |example|
begin
cmds.each do |f|
FileUtils.touch f
end
@ -42,7 +41,6 @@ RSpec.shared_context "custom internal commands" do
ensure
FileUtils.rm_f cmds
end
end
end
describe Homebrew do

View File

@ -9,7 +9,6 @@ end
describe "brew style" do
around do |example|
begin
FileUtils.ln_s HOMEBREW_LIBRARY_PATH, HOMEBREW_LIBRARY/"Homebrew"
FileUtils.ln_s HOMEBREW_LIBRARY_PATH.parent/".rubocop.yml", HOMEBREW_LIBRARY/".rubocop_audit.yml"
FileUtils.ln_s HOMEBREW_LIBRARY_PATH.parent/".rubocop_shared.yml", HOMEBREW_LIBRARY/".rubocop_shared.yml"
@ -20,7 +19,6 @@ describe "brew style" do
FileUtils.rm_f HOMEBREW_LIBRARY/".rubocop_audit.yml"
FileUtils.rm_f HOMEBREW_LIBRARY/".rubocop_shared.yml"
end
end
before do
allow(Homebrew).to receive(:install_bundler_gems!)

View File

@ -73,7 +73,6 @@ describe Homebrew::Diagnostic::Checks do
end
specify "#check_user_path_3" do
begin
sbin = HOMEBREW_PREFIX/"sbin"
ENV["HOMEBREW_PATH"] =
"#{HOMEBREW_PREFIX}/bin#{File::PATH_SEPARATOR}" +
@ -87,7 +86,6 @@ describe Homebrew::Diagnostic::Checks do
ensure
sbin.rmtree
end
end
specify "#check_for_config_scripts" do
mktmpdir do |path|
@ -103,7 +101,6 @@ describe Homebrew::Diagnostic::Checks do
end
specify "#check_for_symlinked_cellar" do
begin
HOMEBREW_CELLAR.rmtree
mktmpdir do |path|
@ -115,7 +112,6 @@ describe Homebrew::Diagnostic::Checks do
HOMEBREW_CELLAR.unlink
HOMEBREW_CELLAR.mkpath
end
end
specify "#check_ld_vars catches LD vars" do
ENV["LD_LIBRARY_PATH"] = "foo"

View File

@ -1266,7 +1266,6 @@ describe Formula do
let(:testball_repo) { HOMEBREW_PREFIX/"testball_repo" }
example do
begin
outdated_stable_prefix = HOMEBREW_CELLAR/"testball/1.0"
head_prefix_a = HOMEBREW_CELLAR/"testball/HEAD"
head_prefix_b = HOMEBREW_CELLAR/"testball/HEAD-aaaaaaa_1"
@ -1303,7 +1302,6 @@ describe Formula do
testball_repo.rmtree if testball_repo.exist?
end
end
end
describe "#mkdir" do
let(:dst) { mktmpdir }

View File

@ -217,11 +217,9 @@ RSpec::Matchers.alias_matcher :a_string_containing, :include
RSpec::Matchers.define :a_json_string do
match do |actual|
begin
JSON.parse(actual)
true
rescue JSON::ParserError
false
end
end
end

View File

@ -66,10 +66,8 @@ end
RSpec.configure do |config|
config.after do
begin
FakeSystemCommand.verify_expectations!
ensure
FakeSystemCommand.clear
end
end
end

View File

@ -41,7 +41,6 @@ RSpec.shared_context "integration test" do
end
around do |example|
begin
(HOMEBREW_PREFIX/"bin").mkpath
FileUtils.touch HOMEBREW_PREFIX/"bin/brew"
@ -49,7 +48,6 @@ RSpec.shared_context "integration test" do
ensure
FileUtils.rm_r HOMEBREW_PREFIX/"bin"
end
end
# Generate unique ID to be able to
# properly merge coverage results.
@ -94,12 +92,10 @@ RSpec.shared_context "integration test" do
simplecov_spec = Gem.loaded_specs["simplecov"]
specs = [simplecov_spec]
simplecov_spec.runtime_dependencies.each do |dep|
begin
specs += dep.to_specs
rescue Gem::LoadError => e
onoe e
end
end
libs = specs.flat_map do |spec|
full_gem_path = spec.full_gem_path
# full_require_paths isn't available in RubyGems < 2.2.

View File

@ -267,14 +267,12 @@ describe SystemCommand do
it "does not leak the secrets set by environment" do
redacted_msg = /#{Regexp.escape("username:******")}/
expect do
begin
ENV["PASSWORD"] = "hunter2"
described_class.run! "curl",
args: %w[--user username:hunter2],
verbose: true
ensure
ENV.delete "PASSWORD"
end
end.to raise_error.with_message(redacted_msg).and output(redacted_msg).to_stdout
end
end

View File

@ -61,7 +61,6 @@ describe Tap do
end
specify "::fetch" do
begin
expect(described_class.fetch("Homebrew", "core")).to be_kind_of(CoreTap)
expect(described_class.fetch("Homebrew", "homebrew")).to be_kind_of(CoreTap)
tap = described_class.fetch("Homebrew", "foo")
@ -82,7 +81,6 @@ describe Tap do
ensure
described_class.clear_cache
end
end
describe "::from_path" do
let(:tap) { described_class.fetch("Homebrew", "core") }
@ -113,7 +111,6 @@ describe Tap do
end
specify "#issues_url" do
begin
t = described_class.new("someone", "foo")
path = Tap::TAP_DIRECTORY/"someone/homebrew-foo"
path.mkpath
@ -130,7 +127,6 @@ describe Tap do
ensure
path.parent.rmtree
end
end
specify "files" do
setup_tap_files
@ -272,7 +268,6 @@ describe Tap do
end
specify "#install and #uninstall" do
begin
setup_tap_files
setup_git_repo
@ -297,10 +292,8 @@ describe Tap do
(HOMEBREW_PREFIX/"etc").rmtree if (HOMEBREW_PREFIX/"etc").exist?
(HOMEBREW_PREFIX/"share").rmtree if (HOMEBREW_PREFIX/"share").exist?
end
end
specify "#link_completions_and_manpages" do
begin
setup_tap_files
setup_git_repo
tap = described_class.new("Homebrew", "baz")
@ -319,7 +312,6 @@ describe Tap do
(HOMEBREW_PREFIX/"etc").rmtree if (HOMEBREW_PREFIX/"etc").exist?
(HOMEBREW_PREFIX/"share").rmtree if (HOMEBREW_PREFIX/"share").exist?
end
end
specify "#pin and #unpin" do
expect(subject).not_to be_pinned

View File

@ -50,7 +50,6 @@ module Homebrew
method = instance_method(name)
define_method(name) do |*args, &block|
begin
time = Time.now
method.bind(self).call(*args, &block)
ensure
@ -59,7 +58,6 @@ module Homebrew
end
end
end
end
return unless $times.nil?
@ -388,11 +386,9 @@ module Kernel
def paths
@paths ||= PATH.new(ENV["HOMEBREW_PATH"]).map do |p|
begin
File.expand_path(p).chomp("/")
rescue ArgumentError
onoe "The following PATH component is invalid: #{p}"
end
end.uniq.compact
end

View File

@ -32,7 +32,6 @@ module Utils
read, write = IO.pipe
pid = fork do
begin
ENV["HOMEBREW_ERROR_PIPE"] = server.path
server.close
read.close
@ -57,7 +56,6 @@ module Utils
else
exit!(true)
end
end
ignore_interrupts(:quietly) do # the child will receive the interrupt and marshal it back
begin