1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

[rubygems/rubygems] Split validations into required and optional

https://github.com/rubygems/rubygems/commit/55b09a7aa2
This commit is contained in:
David Rodríguez 2020-05-29 15:57:45 +02:00 committed by Hiroshi SHIBATA
parent 455330143a
commit e9c8066bd9
Notes: git 2020-06-05 07:33:35 +09:00

View file

@ -42,6 +42,23 @@ class Gem::SpecificationPolicy
# 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
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
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.
# 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:
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:
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
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