summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorHiroshi SHIBATA <hsbt@ruby-lang.org>2023-03-22 13:26:37 +0900
committerHiroshi SHIBATA <hsbt@ruby-lang.org>2023-03-23 17:18:49 +0900
commit0eef33e113e61f0d6efcf47f93602bd9d68f68d2 (patch)
tree1305402633da67630cf1ebfebbb6a630420108be /lib
parentbec069b0cae3934bb2caee3aad7fbf587ab95937 (diff)
[rubygems/rubygems] util/rubocop -A --only Style/Next
https://github.com/rubygems/rubygems/commit/e5868e92f7
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/7582
Diffstat (limited to 'lib')
-rw-r--r--lib/rubygems/command.rb23
-rw-r--r--lib/rubygems/commands/dependency_command.rb7
-rw-r--r--lib/rubygems/commands/uninstall_command.rb13
-rw-r--r--lib/rubygems/core_ext/kernel_warn.rb9
-rw-r--r--lib/rubygems/installer.rb20
-rw-r--r--lib/rubygems/resolver/index_set.rb9
-rw-r--r--lib/rubygems/source/local.rb17
-rw-r--r--lib/rubygems/specification.rb41
-rw-r--r--lib/rubygems/specification_policy.rb51
9 files changed, 88 insertions, 102 deletions
diff --git a/lib/rubygems/command.rb b/lib/rubygems/command.rb
index 8bcfe2eb83..9f933b68c7 100644
--- a/lib/rubygems/command.rb
+++ b/lib/rubygems/command.rb
@@ -395,22 +395,21 @@ class Gem::Command
def check_deprecated_options(options)
options.each do |option|
- if option_is_deprecated?(option)
- deprecation = @deprecated_options[command][option]
- version_to_expire = deprecation["rg_version_to_expire"]
+ next unless option_is_deprecated?(option)
+ deprecation = @deprecated_options[command][option]
+ version_to_expire = deprecation["rg_version_to_expire"]
- deprecate_option_msg = if version_to_expire
- "The \"#{option}\" option has been deprecated and will be removed in Rubygems #{version_to_expire}."
- else
- "The \"#{option}\" option has been deprecated and will be removed in future versions of Rubygems."
- end
+ deprecate_option_msg = if version_to_expire
+ "The \"#{option}\" option has been deprecated and will be removed in Rubygems #{version_to_expire}."
+ else
+ "The \"#{option}\" option has been deprecated and will be removed in future versions of Rubygems."
+ end
- extra_msg = deprecation["extra_msg"]
+ extra_msg = deprecation["extra_msg"]
- deprecate_option_msg += " #{extra_msg}" if extra_msg
+ deprecate_option_msg += " #{extra_msg}" if extra_msg
- alert_warning(deprecate_option_msg)
- end
+ alert_warning(deprecate_option_msg)
end
end
diff --git a/lib/rubygems/commands/dependency_command.rb b/lib/rubygems/commands/dependency_command.rb
index b258cd3349..d047cb631e 100644
--- a/lib/rubygems/commands/dependency_command.rb
+++ b/lib/rubygems/commands/dependency_command.rb
@@ -89,10 +89,9 @@ use with other commands.
def display_pipe(specs) # :nodoc:
specs.each do |spec|
- unless spec.dependencies.empty?
- spec.dependencies.sort_by(&:name).each do |dep|
- say "#{dep.name} --version '#{dep.requirement}'"
- end
+ next if spec.dependencies.empty?
+ spec.dependencies.sort_by(&:name).each do |dep|
+ say "#{dep.name} --version '#{dep.requirement}'"
end
end
end
diff --git a/lib/rubygems/commands/uninstall_command.rb b/lib/rubygems/commands/uninstall_command.rb
index 74c11dd64b..6d34dd0149 100644
--- a/lib/rubygems/commands/uninstall_command.rb
+++ b/lib/rubygems/commands/uninstall_command.rb
@@ -167,15 +167,14 @@ that is a dependency of an existing gem. You can use the
gems_to_uninstall = {}
deps.each do |dep|
- unless gems_to_uninstall[dep.name]
- gems_to_uninstall[dep.name] = true
+ next if gems_to_uninstall[dep.name]
+ gems_to_uninstall[dep.name] = true
- unless original_gem_version[dep.name] == Gem::Requirement.default
- options[:version] = dep.version
- end
-
- uninstall_gem(dep.name)
+ unless original_gem_version[dep.name] == Gem::Requirement.default
+ options[:version] = dep.version
end
+
+ uninstall_gem(dep.name)
end
end
diff --git a/lib/rubygems/core_ext/kernel_warn.rb b/lib/rubygems/core_ext/kernel_warn.rb
index 2dadf1fcd8..9dc9f2218c 100644
--- a/lib/rubygems/core_ext/kernel_warn.rb
+++ b/lib/rubygems/core_ext/kernel_warn.rb
@@ -35,11 +35,10 @@ module Kernel
start += 1
- if path = loc.path
- unless path.start_with?(rubygems_path, "<internal:")
- # Non-rubygems frames
- uplevel -= 1
- end
+ next unless path = loc.path
+ unless path.start_with?(rubygems_path, "<internal:")
+ # Non-rubygems frames
+ uplevel -= 1
end
end
kw[:uplevel] = start
diff --git a/lib/rubygems/installer.rb b/lib/rubygems/installer.rb
index c8ac76db2b..6d11f72478 100644
--- a/lib/rubygems/installer.rb
+++ b/lib/rubygems/installer.rb
@@ -354,25 +354,23 @@ class Gem::Installer
def run_pre_install_hooks # :nodoc:
Gem.pre_install_hooks.each do |hook|
- if hook.call(self) == false
- location = " at #{$1}" if hook.inspect =~ /[ @](.*:\d+)/
+ next unless hook.call(self) == false
+ location = " at #{$1}" if hook.inspect =~ /[ @](.*:\d+)/
- message = "pre-install hook#{location} failed for #{spec.full_name}"
- raise Gem::InstallError, message
- end
+ message = "pre-install hook#{location} failed for #{spec.full_name}"
+ raise Gem::InstallError, message
end
end
def run_post_build_hooks # :nodoc:
Gem.post_build_hooks.each do |hook|
- if hook.call(self) == false
- FileUtils.rm_rf gem_dir
+ next unless hook.call(self) == false
+ FileUtils.rm_rf gem_dir
- location = " at #{$1}" if hook.inspect =~ /[ @](.*:\d+)/
+ location = " at #{$1}" if hook.inspect =~ /[ @](.*:\d+)/
- message = "post-build hook#{location} failed for #{spec.full_name}"
- raise Gem::InstallError, message
- end
+ message = "post-build hook#{location} failed for #{spec.full_name}"
+ raise Gem::InstallError, message
end
end
diff --git a/lib/rubygems/resolver/index_set.rb b/lib/rubygems/resolver/index_set.rb
index 61f3c14e4f..a157482506 100644
--- a/lib/rubygems/resolver/index_set.rb
+++ b/lib/rubygems/resolver/index_set.rb
@@ -43,11 +43,10 @@ class Gem::Resolver::IndexSet < Gem::Resolver::Set
name = req.dependency.name
@all[name].each do |uri, n|
- if req.match? n, @prerelease
- res << Gem::Resolver::IndexSpecification.new(
- self, n.name, n.version, uri, n.platform
- )
- end
+ next unless req.match? n, @prerelease
+ res << Gem::Resolver::IndexSpecification.new(
+ self, n.name, n.version, uri, n.platform
+ )
end
res
diff --git a/lib/rubygems/source/local.rb b/lib/rubygems/source/local.rb
index 0007b39bee..4f910a771c 100644
--- a/lib/rubygems/source/local.rb
+++ b/lib/rubygems/source/local.rb
@@ -79,15 +79,14 @@ class Gem::Source::Local < Gem::Source
found = []
@specs.each do |n, data|
- if n.name == gem_name
- s = data[1].spec
-
- if version.satisfied_by?(s.version)
- if prerelease
- found << s
- elsif !s.version.prerelease? || version.prerelease?
- found << s
- end
+ next unless n.name == gem_name
+ s = data[1].spec
+
+ if version.satisfied_by?(s.version)
+ if prerelease
+ found << s
+ elsif !s.version.prerelease? || version.prerelease?
+ found << s
end
end
end
diff --git a/lib/rubygems/specification.rb b/lib/rubygems/specification.rb
index f6590cfada..36d60e3697 100644
--- a/lib/rubygems/specification.rb
+++ b/lib/rubygems/specification.rb
@@ -1808,13 +1808,12 @@ class Gem::Specification < Gem::BasicSpecification
Gem::Specification.each do |spec|
deps = check_dev ? spec.dependencies : spec.runtime_dependencies
deps.each do |dep|
- if satisfies_requirement?(dep)
- sats = []
- find_all_satisfiers(dep) do |sat|
- sats << sat
- end
- out << [spec, dep, sats]
+ next unless satisfies_requirement?(dep)
+ sats = []
+ find_all_satisfiers(dep) do |sat|
+ sats << sat
end
+ out << [spec, dep, sats]
end
end
out
@@ -2253,21 +2252,20 @@ class Gem::Specification < Gem::BasicSpecification
attributes.each do |attr_name|
current_value = send attr_name
current_value = current_value.sort if [:files, :test_files].include? attr_name
- if current_value != default_value(attr_name) ||
- self.class.required_attribute?(attr_name)
-
- q.text "s.#{attr_name} = "
+ next unless current_value != default_value(attr_name) ||
+ self.class.required_attribute?(attr_name)
- if attr_name == :date
- current_value = current_value.utc
+ q.text "s.#{attr_name} = "
- q.text "Time.utc(#{current_value.year}, #{current_value.month}, #{current_value.day})"
- else
- q.pp current_value
- end
+ if attr_name == :date
+ current_value = current_value.utc
- q.breakable
+ q.text "Time.utc(#{current_value.year}, #{current_value.month}, #{current_value.day})"
+ else
+ q.pp current_value
end
+
+ q.breakable
end
end
end
@@ -2609,11 +2607,10 @@ class Gem::Specification < Gem::BasicSpecification
ensure
trail.pop
end
- unless result == :next
- spec_name = dep_spec.name
- dep_spec.traverse(trail, visited, &block) unless
- trail.any? {|s| s.name == spec_name }
- end
+ next if result == :next
+ spec_name = dep_spec.name
+ dep_spec.traverse(trail, visited, &block) unless
+ trail.any? {|s| s.name == spec_name }
end
end
ensure
diff --git a/lib/rubygems/specification_policy.rb b/lib/rubygems/specification_policy.rb
index 2c7a874a80..ee88294b51 100644
--- a/lib/rubygems/specification_policy.rb
+++ b/lib/rubygems/specification_policy.rb
@@ -141,10 +141,9 @@ class Gem::SpecificationPolicy
error "#{entry} value is too large (#{value.size} > 1024)"
end
- if METADATA_LINK_KEYS.include? key
- if value !~ VALID_URI_PATTERN
- error "#{entry} has invalid link: #{value.inspect}"
- end
+ next unless METADATA_LINK_KEYS.include? key
+ if value !~ VALID_URI_PATTERN
+ error "#{entry} has invalid link: #{value.inspect}"
end
end
end
@@ -196,28 +195,27 @@ duplicate dependency on #{dep}, (#{prev.requirement}) use:
!version.prerelease? && [">", ">="].include?(op)
end
- if open_ended
- op, dep_version = dep.requirement.requirements.first
-
- segments = dep_version.segments
+ next unless open_ended
+ op, dep_version = dep.requirement.requirements.first
- base = segments.first 2
+ segments = dep_version.segments
- recommendation = if [">", ">="].include?(op) && segments == [0]
- " use a bounded requirement, such as '~> x.y'"
- else
- bugfix = if op == ">"
- ", '> #{dep_version}'"
- elsif op == ">=" && base != segments
- ", '>= #{dep_version}'"
- end
+ base = segments.first 2
- " if #{dep.name} is semantically versioned, use:\n" \
- " add_#{dep.type}_dependency '#{dep.name}', '~> #{base.join "."}'#{bugfix}"
+ recommendation = if [">", ">="].include?(op) && segments == [0]
+ " use a bounded requirement, such as '~> x.y'"
+ else
+ bugfix = if op == ">"
+ ", '> #{dep_version}'"
+ elsif op == ">=" && base != segments
+ ", '>= #{dep_version}'"
end
- warning_messages << ["open-ended dependency on #{dep} is not recommended", recommendation].join("\n") + "\n"
+ " if #{dep.name} is semantically versioned, use:\n" \
+ " add_#{dep.type}_dependency '#{dep.name}', '~> #{base.join "."}'#{bugfix}"
end
+
+ warning_messages << ["open-ended dependency on #{dep} is not recommended", recommendation].join("\n") + "\n"
end
if warning_messages.any?
warning_messages.each {|warning_message| warning warning_message }
@@ -368,15 +366,14 @@ duplicate dependency on #{dep}, (#{prev.requirement}) use:
licenses = @specification.licenses
licenses.each do |license|
- unless Gem::Licenses.match?(license)
- suggestions = Gem::Licenses.suggestions(license)
- message = <<-WARNING
+ next if Gem::Licenses.match?(license)
+ suggestions = Gem::Licenses.suggestions(license)
+ message = <<-WARNING
license value '#{license}' is invalid. Use a license identifier from
http://spdx.org/licenses or '#{Gem::Licenses::NONSTANDARD}' for a nonstandard license.
- WARNING
- message += "Did you mean #{suggestions.map {|s| "'#{s}'" }.join(", ")}?\n" unless suggestions.nil?
- warning(message)
- end
+ WARNING
+ message += "Did you mean #{suggestions.map {|s| "'#{s}'" }.join(", ")}?\n" unless suggestions.nil?
+ warning(message)
end
warning <<-WARNING if licenses.empty?