[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"
begin
Gem::DefaultUserInteraction.use_ui(ui) do
begin
Bundler.ui.silence do
@gemdeps = Bundler.setup
end
ensure
Gem::DefaultUserInteraction.ui.close
end
end
rescue Bundler::BundlerError => e
warn e.message
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.
def handles?(args)
begin
parser.parse!(args.dup)
return true
rescue StandardError
return false
end
end
##
# 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)
owners.each do |owner|
begin
response = send_owner_request(method, name, owner)
action = method == :delete ? "Removing" : "Adding"
@ -102,7 +101,6 @@ permission to.
# ignore
end
end
end
private

View File

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

View File

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

View File

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

View File

@ -44,7 +44,6 @@ class Gem::Security::TrustDir
glob = File.join @dir, "*.pem"
Dir[glob].each do |certificate_file|
begin
certificate = load_certificate certificate_file
yield certificate, certificate_file
@ -52,7 +51,6 @@ class Gem::Security::TrustDir
next # HACK: warn
end
end
end
##
# 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 = {}
Dir["*.gem"].each do |file|
begin
pkg = Gem::Package.new(file)
rescue SystemCallError, Gem::Package::FormatError
# ignore
@ -69,7 +68,6 @@ class Gem::Source::Local < Gem::Source
names << pkg.spec.name_tuple
end
end
end
names
end

View File

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

View File

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

View File

@ -109,7 +109,6 @@ class Gem::Validator
end
good.each do |entry, data|
begin
next unless data # HACK: `gem check -a mkrf`
source = File.join gem_directory, entry["path"]
@ -121,7 +120,6 @@ class Gem::Validator
end
end
end
end
installed_files = find_files_for_gem(gem_directory)
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
def capture_subprocess_io
_synchronize do
begin
require "tempfile"
captured_stdout = Tempfile.new("out")
@ -144,7 +143,6 @@ class Gem::TestCase < Test::Unit::TestCase
captured_stderr.close!
end
end
end
##
# Sets the ENABLE_SHARED entry in RbConfig::CONFIG to +value+ and restores

View File

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

View File

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

View File

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