Skip to content

Commit beba8dd

Browse files
committed
Remove open-ended and prerelease dependency warnings when building gems
In general, rubygems should provide mechanism and not policy. Pessimistic versioning is not universally better, and in many cases, it can cause more problems than it solves. Rubygems should not be warning against open-ended versioning when building gems. The majority of the default gems with dependencies do not use pessimistic versioning, which indicates that Ruby itself recognizes that open-ended versioning is generally better. In some cases, depending on a prerelease gem is the only choice other than not releasing a gem. If you are building an extension gem for a feature in a prerelease version of another gem, then depending on the prerelease version is the only way to ensure a compatible dependency is installed.
1 parent ff9c659 commit beba8dd

File tree

2 files changed

+1
-57
lines changed

2 files changed

+1
-57
lines changed

lib/rubygems/specification_policy.rb

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -190,49 +190,13 @@ def validate_duplicate_dependencies # :nodoc:
190190

191191
##
192192
# Checks that the gem does not depend on itself.
193-
# Checks that dependencies use requirements as we recommend. Warnings are
194-
# issued when dependencies are open-ended or overly strict for semantic
195-
# versioning.
196193

197194
def validate_dependencies # :nodoc:
198195
warning_messages = []
199196
@specification.dependencies.each do |dep|
200197
if dep.name == @specification.name # warn on self reference
201198
warning_messages << "Self referencing dependency is unnecessary and strongly discouraged."
202199
end
203-
204-
prerelease_dep = dep.requirements_list.any? do |req|
205-
Gem::Requirement.new(req).prerelease?
206-
end
207-
208-
warning_messages << "prerelease dependency on #{dep} is not recommended" if
209-
prerelease_dep && !@specification.version.prerelease?
210-
211-
open_ended = dep.requirement.requirements.all? do |op, version|
212-
!version.prerelease? && [">", ">="].include?(op)
213-
end
214-
215-
next unless open_ended
216-
op, dep_version = dep.requirement.requirements.first
217-
218-
segments = dep_version.segments
219-
220-
base = segments.first 2
221-
222-
recommendation = if [">", ">="].include?(op) && segments == [0]
223-
" use a bounded requirement, such as \"~> x.y\""
224-
else
225-
bugfix = if op == ">"
226-
", \"> #{dep_version}\""
227-
elsif op == ">=" && base != segments
228-
", \">= #{dep_version}\""
229-
end
230-
231-
" if #{dep.name} is semantically versioned, use:\n" \
232-
" add_#{dep.type}_dependency \"#{dep.name}\", \"~> #{base.join "."}\"#{bugfix}"
233-
end
234-
235-
warning_messages << ["open-ended dependency on #{dep} is not recommended", recommendation].join("\n") + "\n"
236200
end
237201
if warning_messages.any?
238202
warning_messages.each {|warning_message| warning warning_message }

test/rubygems/test_gem_specification.rb

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2671,27 +2671,7 @@ def test_validate_dependencies
26712671
@a1.validate
26722672
end
26732673

2674-
expected = <<-EXPECTED
2675-
#{w}: prerelease dependency on b (>= 1.0.rc1) is not recommended
2676-
#{w}: prerelease dependency on c (>= 2.0.rc2, development) is not recommended
2677-
#{w}: open-ended dependency on i (>= 1.2) is not recommended
2678-
if i is semantically versioned, use:
2679-
add_runtime_dependency "i", "~> 1.2"
2680-
#{w}: open-ended dependency on j (>= 1.2.3) is not recommended
2681-
if j is semantically versioned, use:
2682-
add_runtime_dependency "j", "~> 1.2", ">= 1.2.3"
2683-
#{w}: open-ended dependency on k (> 1.2) is not recommended
2684-
if k is semantically versioned, use:
2685-
add_runtime_dependency "k", "~> 1.2", "> 1.2"
2686-
#{w}: open-ended dependency on l (> 1.2.3) is not recommended
2687-
if l is semantically versioned, use:
2688-
add_runtime_dependency "l", "~> 1.2", "> 1.2.3"
2689-
#{w}: open-ended dependency on o (>= 0) is not recommended
2690-
use a bounded requirement, such as "~> x.y"
2691-
#{w}: See https://guides.rubygems.org/specification-reference/ for help
2692-
EXPECTED
2693-
2694-
assert_equal expected, @ui.error, "warning"
2674+
assert_equal "", @ui.error, "warning"
26952675
end
26962676
end
26972677

0 commit comments

Comments
 (0)