summaryrefslogtreecommitdiff
path: root/lib/rubygems/specification_policy.rb
diff options
context:
space:
mode:
authorDavid Rodríguez <[email protected]>2020-05-29 15:57:45 +0200
committerHiroshi SHIBATA <[email protected]>2020-06-05 07:32:42 +0900
commite9c8066bd965634475f4273406fd0e0f6f5e5988 ()
tree722135430d8444a7a96683d8c972785caad250d4 /lib/rubygems/specification_policy.rb
parent455330143aed490f867cde2c1a5d0db81c2b7c76 (diff)
[rubygems/rubygems] Split validations into required and optional
https://.com/rubygems/rubygems/commit/55b09a7aa2
Notes: Merged: https://.com/ruby/ruby/pull/3184
-rw-r--r--lib/rubygems/specification_policy.rb60
1 files changed, 47 insertions, 13 deletions
@@ -42,6 +42,23 @@ class Gem::SpecificationPolicy
# messages instead.
def validate(strict = false)
validate_nil_attributes
validate_rubygems_version
@@ -68,12 +85,18 @@ class Gem::SpecificationPolicy
validate_metadata
validate_licenses
validate_permissions
- validate_lazy_metadata
-
validate_values
validate_dependencies
@@ -89,8 +112,6 @@ class Gem::SpecificationPolicy
alert_warning help_text
end
end
-
- true
end
##
@@ -129,16 +150,13 @@ class Gem::SpecificationPolicy
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:
# 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:
end
seen[dep.type][dep.name] = 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:
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:
error "authors may not be empty"
end
- def validate_licenses
licenses = @specification.licenses
licenses.each do |license|
if license.length > 64
error "each license must be 64 characters or less"
end
if !Gem::Licenses.match?(license)
suggestions = Gem::Licenses.suggestions(license)
message = <<-WARNING