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

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,13 +1090,11 @@ 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
Bundler.ui.silence do
@gemdeps = Bundler.setup
end
ensure
Gem::DefaultUserInteraction.ui.close
end
rescue Bundler::BundlerError => e
warn e.message

View file

@ -429,12 +429,10 @@ 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
parser.parse!(args.dup)
return true
rescue StandardError
return false
end
##

View file

@ -93,14 +93,12 @@ 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"
response = send_owner_request(method, name, owner)
action = method == :delete ? "Removing" : "Adding"
with_response response, "#{action} #{owner}"
rescue StandardError
# ignore
end
with_response response, "#{action} #{owner}"
rescue StandardError
# ignore
end
end

View file

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

View file

@ -162,13 +162,11 @@ 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
spec = source.fetch_spec(tup)
rescue Gem::RemoteFetcher::FetchError => e
errors << Gem::SourceFetchProblem.new(source, e)
else
specs << [spec, source]
end
if @errors
@ -294,11 +292,9 @@ 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
src = Gem::Source::SpecificFile.new name
installer_set.add_local dep_or_name, src.spec, src
rescue Gem::Package::FormatError
end
# else This is a dependency. InstallerSet handles this case
end

View file

@ -58,10 +58,8 @@ 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
source.download full_spec, path
rescue exception
end
return path if path
raise exception if exception

View file

@ -44,13 +44,11 @@ class Gem::Security::TrustDir
glob = File.join @dir, "*.pem"
Dir[glob].each do |certificate_file|
begin
certificate = load_certificate certificate_file
certificate = load_certificate certificate_file
yield certificate, certificate_file
rescue OpenSSL::X509::CertificateError
next # HACK: warn
end
yield certificate, certificate_file
rescue OpenSSL::X509::CertificateError
next # HACK: warn
end
end

View file

@ -38,36 +38,34 @@ class Gem::Source::Local < Gem::Source
@specs = {}
Dir["*.gem"].each do |file|
begin
pkg = Gem::Package.new(file)
rescue SystemCallError, Gem::Package::FormatError
# ignore
else
tup = pkg.spec.name_tuple
@specs[tup] = [File.expand_path(file), pkg]
pkg = Gem::Package.new(file)
rescue SystemCallError, Gem::Package::FormatError
# ignore
else
tup = pkg.spec.name_tuple
@specs[tup] = [File.expand_path(file), pkg]
case type
when :released
unless pkg.spec.version.prerelease?
names << pkg.spec.name_tuple
end
when :prerelease
if pkg.spec.version.prerelease?
names << pkg.spec.name_tuple
end
when :latest
tup = pkg.spec.name_tuple
cur = names.find {|x| x.name == tup.name }
if !cur
names << tup
elsif cur.version < tup.version
names.delete cur
names << tup
end
else
case type
when :released
unless pkg.spec.version.prerelease?
names << pkg.spec.name_tuple
end
when :prerelease
if pkg.spec.version.prerelease?
names << pkg.spec.name_tuple
end
when :latest
tup = pkg.spec.name_tuple
cur = names.find {|x| x.name == tup.name }
if !cur
names << tup
elsif cur.version < tup.version
names.delete cur
names << tup
end
else
names << pkg.spec.name_tuple
end
end

View file

@ -154,13 +154,11 @@ 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
spec = source.fetch_spec(tup)
rescue Gem::RemoteFetcher::FetchError => e
errors << Gem::SourceFetchProblem.new(source, e)
else
specs << [spec, source]
end
return [specs, errors]
@ -214,34 +212,32 @@ class Gem::SpecFetcher
list = {}
@sources.each_source do |source|
begin
names = case type
when :latest
tuples_for source, :latest
when :released
tuples_for source, :released
when :complete
names =
tuples_for(source, :prerelease, true) +
tuples_for(source, :released)
names = case type
when :latest
tuples_for source, :latest
when :released
tuples_for source, :released
when :complete
names =
tuples_for(source, :prerelease, true) +
tuples_for(source, :released)
names.sort
when :abs_latest
names =
tuples_for(source, :prerelease, true) +
tuples_for(source, :latest)
names.sort
when :abs_latest
names =
tuples_for(source, :prerelease, true) +
tuples_for(source, :latest)
names.sort
when :prerelease
tuples_for(source, :prerelease)
else
raise Gem::Exception, "Unknown type - :#{type}"
end
rescue Gem::RemoteFetcher::FetchError => e
errors << Gem::SourceFetchProblem.new(source, e)
else
list[source] = names
names.sort
when :prerelease
tuples_for(source, :prerelease)
else
raise Gem::Exception, "Unknown type - :#{type}"
end
rescue Gem::RemoteFetcher::FetchError => e
errors << Gem::SourceFetchProblem.new(source, e)
else
list[source] = names
end
[list, errors]

View file

@ -111,20 +111,18 @@ 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)
extensions = if /\A#{PREFIX}/ =~ file.readline.chomp
$'.split "\0"
else
StubLine::NO_EXTENSIONS
end
@data = StubLine.new stubline, extensions
file.readline # discard encoding line
stubline = file.readline.chomp
if stubline.start_with?(PREFIX)
extensions = if /\A#{PREFIX}/ =~ file.readline.chomp
$'.split "\0"
else
StubLine::NO_EXTENSIONS
end
rescue EOFError
@data = StubLine.new stubline, extensions
end
rescue EOFError
end
ensure
$. = saved_lineno

View file

@ -270,7 +270,7 @@ class Gem::StreamUI
when /^y/i then true
when /^n/i then false
when /^$/ then default
end
end
end
return result

View file

@ -109,15 +109,13 @@ class Gem::Validator
end
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"]
File.open source, Gem.binary_mode do |f|
unless f.read == data
errors[gem_name][entry["path"]] = "Modified from original"
end
File.open source, Gem.binary_mode do |f|
unless f.read == data
errors[gem_name][entry["path"]] = "Modified from original"
end
end
end