[前][次][番号順一覧][スレッド一覧]

ruby-changes:61543

From: David <ko1@a...>
Date: Fri, 5 Jun 2020 07:34:23 +0900 (JST)
Subject: [ruby-changes:61543] e9c8066bd9 (master): [rubygems/rubygems] Split validations into required and optional

https://git.ruby-lang.org/ruby.git/commit/?id=e9c8066bd9

From e9c8066bd965634475f4273406fd0e0f6f5e5988 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?David=20Rodr=C3=ADguez?= <deivid.rodriguez@r...>
Date: Fri, 29 May 2020 15:57:45 +0200
Subject: [rubygems/rubygems] Split validations into required and optional

https://github.com/rubygems/rubygems/commit/55b09a7aa2

diff --git a/lib/rubygems/specification_policy.rb b/lib/rubygems/specification_policy.rb
index f752240..f96e95b 100644
--- a/lib/rubygems/specification_policy.rb
+++ b/lib/rubygems/specification_policy.rb
@@ -42,6 +42,23 @@ class Gem::SpecificationPolicy https://github.com/ruby/ruby/blob/trunk/lib/rubygems/specification_policy.rb#L42
   # messages instead.
 
   def validate(strict = false)
+    validate_required!
+
+    validate_optional(strict)
+
+    true
+  end
+
+  ##
+  # Does a sanity check on the specification.
+  #
+  # Raises InvalidSpecificationException if the spec does not pass the
+  # checks.
+  #
+  # Only runs checks that are considered necessary for the specification to be
+  # functional.
+
+  def validate_required!
     validate_nil_attributes
 
     validate_rubygems_version
@@ -68,12 +85,18 @@ class Gem::SpecificationPolicy https://github.com/ruby/ruby/blob/trunk/lib/rubygems/specification_policy.rb#L85
 
     validate_metadata
 
+    validate_licenses_length
+
+    validate_lazy_metadata
+
+    validate_duplicate_dependencies
+  end
+
+  def validate_optional(strict)
     validate_licenses
 
     validate_permissions
 
-    validate_lazy_metadata
-
     validate_values
 
     validate_dependencies
@@ -89,8 +112,6 @@ class Gem::SpecificationPolicy https://github.com/ruby/ruby/blob/trunk/lib/rubygems/specification_policy.rb#L112
         alert_warning help_text
       end
     end
-
-    true
   end
 
   ##
@@ -129,16 +150,13 @@ class Gem::SpecificationPolicy https://github.com/ruby/ruby/blob/trunk/lib/rubygems/specification_policy.rb#L150
   end
 
   ##
-  # Checks that dependencies use requirements as we recommend.  Warnings are
-  # issued when dependencies are open-ended or overly strict for semantic
-  # versioning.
+  # Checks that no duplicate dependencies are specified.
 
-  def validate_dependencies # :nodoc:
+  def validate_duplicate_dependencies # :nodoc:
     # NOTE: see REFACTOR note in Gem::Dependency about types - this might be brittle
     seen = Gem::Dependency::TYPES.inject({}) { |types, type| types.merge({ type => {}}) }
 
     error_messages = []
-    warning_messages = []
     @specification.dependencies.each do |dep|
       if prev = seen[dep.type][dep.name]
         error_messages << <<-MESSAGE
@@ -148,7 +166,20 @@ duplicate dependency on #{dep}, (#{prev.requirement}) use: https://github.com/ruby/ruby/blob/trunk/lib/rubygems/specification_policy.rb#L166
       end
 
       seen[dep.type][dep.name] = dep
+    end
+    if error_messages.any?
+      error error_messages.join
+    end
+  end
 
+  ##
+  # Checks that dependencies use requirements as we recommend.  Warnings are
+  # issued when dependencies are open-ended or overly strict for semantic
+  # versioning.
+
+  def validate_dependencies # :nodoc:
+    warning_messages = []
+    @specification.dependencies.each do |dep|
       prerelease_dep = dep.requirements_list.any? do |req|
         Gem::Requirement.new(req).prerelease?
       end
@@ -183,9 +214,6 @@ duplicate dependency on #{dep}, (#{prev.requirement}) use: https://github.com/ruby/ruby/blob/trunk/lib/rubygems/specification_policy.rb#L214
         warning_messages << ["open-ended dependency on #{dep} is not recommended", recommendation].join("\n") + "\n"
       end
     end
-    if error_messages.any?
-      error error_messages.join
-    end
     if warning_messages.any?
       warning_messages.each { |warning_message| warning warning_message }
     end
@@ -321,14 +349,20 @@ duplicate dependency on #{dep}, (#{prev.requirement}) use: https://github.com/ruby/ruby/blob/trunk/lib/rubygems/specification_policy.rb#L349
     error "authors may not be empty"
   end
 
-  def validate_licenses
+  def validate_licenses_length
     licenses = @specification.licenses
 
     licenses.each do |license|
       if license.length > 64
         error "each license must be 64 characters or less"
       end
+    end
+  end
+
+  def validate_licenses
+    licenses = @specification.licenses
 
+    licenses.each do |license|
       if !Gem::Licenses.match?(license)
         suggestions = Gem::Licenses.suggestions(license)
         message = <<-WARNING
-- 
cgit v0.10.2


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]