[rubygems/rubygems] util/rubocop -A --only Style/RedundantBegin

https://github.com/rubygems/rubygems/commit/b595d3cf0f
This commit is contained in:
Hiroshi SHIBATA 2023-03-16 14:10:30 +09:00
parent a532e9dc37
commit 72d09a568f
16 changed files with 148 additions and 188 deletions

View File

@ -1090,14 +1090,12 @@ An Array (#{env.inspect}) was passed in from #{caller[3]}
require "bundler" require "bundler"
begin begin
Gem::DefaultUserInteraction.use_ui(ui) do Gem::DefaultUserInteraction.use_ui(ui) do
begin
Bundler.ui.silence do Bundler.ui.silence do
@gemdeps = Bundler.setup @gemdeps = Bundler.setup
end end
ensure ensure
Gem::DefaultUserInteraction.ui.close Gem::DefaultUserInteraction.ui.close
end end
end
rescue Bundler::BundlerError => e rescue Bundler::BundlerError => e
warn e.message warn e.message
warn "You may need to `bundle install` to install missing gems" warn "You may need to `bundle install` to install missing gems"

View File

@ -429,13 +429,11 @@ class Gem::Command
# True if the command handles the given argument list. # True if the command handles the given argument list.
def handles?(args) def handles?(args)
begin
parser.parse!(args.dup) parser.parse!(args.dup)
return true return true
rescue StandardError rescue StandardError
return false return false
end end
end
## ##
# Handle the given list of arguments by parsing them and recording the # Handle the given list of arguments by parsing them and recording the

View File

@ -93,7 +93,6 @@ permission to.
def manage_owners(method, name, owners) def manage_owners(method, name, owners)
owners.each do |owner| owners.each do |owner|
begin
response = send_owner_request(method, name, owner) response = send_owner_request(method, name, owner)
action = method == :delete ? "Removing" : "Adding" action = method == :delete ? "Removing" : "Adding"
@ -102,7 +101,6 @@ permission to.
# ignore # ignore
end end
end end
end
private private

View File

@ -95,13 +95,11 @@ command help for an example.
FileUtils.mkdir_p @options[:target] if @options[:target] FileUtils.mkdir_p @options[:target] if @options[:target]
destination = begin destination = if @options[:target]
if @options[:target]
File.join @options[:target], spec_file File.join @options[:target], spec_file
else else
spec_file spec_file
end end
end
File.open destination, "w" do |io| File.open destination, "w" do |io|
io.write metadata io.write metadata

View File

@ -162,14 +162,12 @@ class Gem::DependencyInstaller
specs = [] specs = []
tuples.each do |tup, source| tuples.each do |tup, source|
begin
spec = source.fetch_spec(tup) spec = source.fetch_spec(tup)
rescue Gem::RemoteFetcher::FetchError => e rescue Gem::RemoteFetcher::FetchError => e
errors << Gem::SourceFetchProblem.new(source, e) errors << Gem::SourceFetchProblem.new(source, e)
else else
specs << [spec, source] specs << [spec, source]
end end
end
if @errors if @errors
@errors += errors @errors += errors
@ -294,12 +292,10 @@ class Gem::DependencyInstaller
version = src.spec.version if version == Gem::Requirement.default version = src.spec.version if version == Gem::Requirement.default
elsif dep_or_name =~ /\.gem$/ elsif dep_or_name =~ /\.gem$/
Dir[dep_or_name].each do |name| Dir[dep_or_name].each do |name|
begin
src = Gem::Source::SpecificFile.new name src = Gem::Source::SpecificFile.new name
installer_set.add_local dep_or_name, src.spec, src installer_set.add_local dep_or_name, src.spec, src
rescue Gem::Package::FormatError rescue Gem::Package::FormatError
end end
end
# else This is a dependency. InstallerSet handles this case # else This is a dependency. InstallerSet handles this case
end end
end end

View File

@ -58,11 +58,9 @@ class Gem::Resolver::ActivationRequest
if @spec.respond_to? :sources if @spec.respond_to? :sources
exception = nil exception = nil
path = @spec.sources.find do |source| path = @spec.sources.find do |source|
begin
source.download full_spec, path source.download full_spec, path
rescue exception rescue exception
end end
end
return path if path return path if path
raise exception if exception raise exception if exception

View File

@ -44,7 +44,6 @@ class Gem::Security::TrustDir
glob = File.join @dir, "*.pem" glob = File.join @dir, "*.pem"
Dir[glob].each do |certificate_file| Dir[glob].each do |certificate_file|
begin
certificate = load_certificate certificate_file certificate = load_certificate certificate_file
yield certificate, certificate_file yield certificate, certificate_file
@ -52,7 +51,6 @@ class Gem::Security::TrustDir
next # HACK: warn next # HACK: warn
end end
end end
end
## ##
# Returns the issuer certificate of the given +certificate+ if it exists in # Returns the issuer certificate of the given +certificate+ if it exists in

View File

@ -38,7 +38,6 @@ class Gem::Source::Local < Gem::Source
@specs = {} @specs = {}
Dir["*.gem"].each do |file| Dir["*.gem"].each do |file|
begin
pkg = Gem::Package.new(file) pkg = Gem::Package.new(file)
rescue SystemCallError, Gem::Package::FormatError rescue SystemCallError, Gem::Package::FormatError
# ignore # ignore
@ -69,7 +68,6 @@ class Gem::Source::Local < Gem::Source
names << pkg.spec.name_tuple names << pkg.spec.name_tuple
end end
end end
end
names names
end end

View File

@ -154,14 +154,12 @@ class Gem::SpecFetcher
specs = [] specs = []
tuples.each do |tup, source| tuples.each do |tup, source|
begin
spec = source.fetch_spec(tup) spec = source.fetch_spec(tup)
rescue Gem::RemoteFetcher::FetchError => e rescue Gem::RemoteFetcher::FetchError => e
errors << Gem::SourceFetchProblem.new(source, e) errors << Gem::SourceFetchProblem.new(source, e)
else else
specs << [spec, source] specs << [spec, source]
end end
end
return [specs, errors] return [specs, errors]
end end
@ -214,7 +212,6 @@ class Gem::SpecFetcher
list = {} list = {}
@sources.each_source do |source| @sources.each_source do |source|
begin
names = case type names = case type
when :latest when :latest
tuples_for source, :latest tuples_for source, :latest
@ -242,7 +239,6 @@ class Gem::SpecFetcher
else else
list[source] = names list[source] = names
end end
end
[list, errors] [list, errors]
end end

View File

@ -111,7 +111,6 @@ class Gem::StubSpecification < Gem::BasicSpecification
saved_lineno = $. saved_lineno = $.
Gem.open_file loaded_from, OPEN_MODE do |file| Gem.open_file loaded_from, OPEN_MODE do |file|
begin
file.readline # discard encoding line file.readline # discard encoding line
stubline = file.readline.chomp stubline = file.readline.chomp
if stubline.start_with?(PREFIX) if stubline.start_with?(PREFIX)
@ -125,7 +124,6 @@ class Gem::StubSpecification < Gem::BasicSpecification
end end
rescue EOFError rescue EOFError
end end
end
ensure ensure
$. = saved_lineno $. = saved_lineno
end end

View File

@ -109,7 +109,6 @@ class Gem::Validator
end end
good.each do |entry, data| good.each do |entry, data|
begin
next unless data # HACK: `gem check -a mkrf` next unless data # HACK: `gem check -a mkrf`
source = File.join gem_directory, entry["path"] source = File.join gem_directory, entry["path"]
@ -121,7 +120,6 @@ class Gem::Validator
end end
end end
end end
end
installed_files = find_files_for_gem(gem_directory) installed_files = find_files_for_gem(gem_directory)
extras = installed_files - good - unreadable extras = installed_files - good - unreadable

View File

@ -117,7 +117,6 @@ class Gem::TestCase < Test::Unit::TestCase
# https://github.com/seattlerb/minitest/blob/21d9e804b63c619f602f3f4ece6c71b48974707a/lib/minitest/assertions.rb#L546 # https://github.com/seattlerb/minitest/blob/21d9e804b63c619f602f3f4ece6c71b48974707a/lib/minitest/assertions.rb#L546
def capture_subprocess_io def capture_subprocess_io
_synchronize do _synchronize do
begin
require "tempfile" require "tempfile"
captured_stdout = Tempfile.new("out") captured_stdout = Tempfile.new("out")
@ -144,7 +143,6 @@ class Gem::TestCase < Test::Unit::TestCase
captured_stderr.close! captured_stderr.close!
end end
end end
end
## ##
# Sets the ENABLE_SHARED entry in RbConfig::CONFIG to +value+ and restores # Sets the ENABLE_SHARED entry in RbConfig::CONFIG to +value+ and restores

View File

@ -1159,7 +1159,6 @@ PeIQQkFng2VVot/WAQbv3ePqWq07g1BBcwIBAg==
end end
server.ssl_context.tmp_dh_callback = proc { TEST_KEY_DH2048 } server.ssl_context.tmp_dh_callback = proc { TEST_KEY_DH2048 }
t = Thread.new do t = Thread.new do
begin
server.start server.start
rescue Exception => ex rescue Exception => ex
puts "ERROR during server thread: #{ex.message}" puts "ERROR during server thread: #{ex.message}"
@ -1167,7 +1166,6 @@ PeIQQkFng2VVot/WAQbv3ePqWq07g1BBcwIBAg==
ensure ensure
server.shutdown server.shutdown
end end
end
while server.status != :Running while server.status != :Running
sleep 0.1 sleep 0.1
unless t.alive? unless t.alive?
@ -1213,14 +1211,12 @@ PeIQQkFng2VVot/WAQbv3ePqWq07g1BBcwIBAg==
end end
end end
th = Thread.new do th = Thread.new do
begin
s.start s.start
rescue Exception => ex rescue Exception => ex
abort "ERROR during server thread: #{ex.message}" abort "ERROR during server thread: #{ex.message}"
ensure ensure
s.shutdown s.shutdown
end end
end
th[:server] = s th[:server] = s
th th
end end

View File

@ -145,7 +145,6 @@ class TestUpdateSuggestion < Gem::TestCase
def test_eglible_for_update_prevent_config def test_eglible_for_update_prevent_config
with_eglible_environment(cmd: @cmd) do with_eglible_environment(cmd: @cmd) do
begin
original_config = Gem.configuration[:prevent_update_suggestion] original_config = Gem.configuration[:prevent_update_suggestion]
Gem.configuration[:prevent_update_suggestion] = true Gem.configuration[:prevent_update_suggestion] = true
refute @cmd.eglible_for_update? refute @cmd.eglible_for_update?
@ -153,11 +152,9 @@ class TestUpdateSuggestion < Gem::TestCase
Gem.configuration[:prevent_update_suggestion] = original_config Gem.configuration[:prevent_update_suggestion] = original_config
end end
end end
end
def test_eglible_for_update_prevent_env def test_eglible_for_update_prevent_env
with_eglible_environment(cmd: @cmd) do with_eglible_environment(cmd: @cmd) do
begin
original_env = ENV["RUBYGEMS_PREVENT_UPDATE_SUGGESTION"] original_env = ENV["RUBYGEMS_PREVENT_UPDATE_SUGGESTION"]
ENV["RUBYGEMS_PREVENT_UPDATE_SUGGESTION"] = "yes" ENV["RUBYGEMS_PREVENT_UPDATE_SUGGESTION"] = "yes"
refute @cmd.eglible_for_update? refute @cmd.eglible_for_update?
@ -165,7 +162,6 @@ class TestUpdateSuggestion < Gem::TestCase
ENV["RUBYGEMS_PREVENT_UPDATE_SUGGESTION"] = original_env ENV["RUBYGEMS_PREVENT_UPDATE_SUGGESTION"] = original_env
end end
end end
end
def test_eglible_for_update_non_tty def test_eglible_for_update_non_tty
with_eglible_environment(tty: false, cmd: @cmd) do with_eglible_environment(tty: false, cmd: @cmd) do
@ -181,7 +177,6 @@ class TestUpdateSuggestion < Gem::TestCase
def test_eglible_for_update_disabled_update def test_eglible_for_update_disabled_update
with_eglible_environment(cmd: @cmd) do with_eglible_environment(cmd: @cmd) do
begin
original_disable = Gem.disable_system_update_message original_disable = Gem.disable_system_update_message
Gem.disable_system_update_message = "disabled" Gem.disable_system_update_message = "disabled"
refute @cmd.eglible_for_update? refute @cmd.eglible_for_update?
@ -189,7 +184,6 @@ class TestUpdateSuggestion < Gem::TestCase
Gem.disable_system_update_message = original_disable Gem.disable_system_update_message = original_disable
end end
end end
end
def test_eglible_for_update_on_ci def test_eglible_for_update_on_ci
with_eglible_environment(ci: true, cmd: @cmd) do with_eglible_environment(ci: true, cmd: @cmd) do

View File

@ -91,14 +91,12 @@ class TestGemRequire < Gem::TestCase
def create_sync_thread def create_sync_thread
Thread.new do Thread.new do
begin
yield yield
ensure ensure
FILE_ENTERED_LATCH.release FILE_ENTERED_LATCH.release
FILE_EXIT_LATCH.await FILE_EXIT_LATCH.await
end end
end end
end
# Providing -I on the commandline should always beat gems # Providing -I on the commandline should always beat gems
def test_dash_i_beats_default_gems def test_dash_i_beats_default_gems