Skip to content

Commit

Permalink
Use require instead
Browse files Browse the repository at this point in the history
  • Loading branch information
sambostock committed Feb 12, 2024
1 parent 9daa1e7 commit 3f20dbb
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 7 deletions.
28 changes: 28 additions & 0 deletions lib/rubocop/shopify/gem_version_string_comparable_backport.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# frozen_string_literal: true

# This is true for Ruby 3.2+, so once support for 3.1 is dropped, we can remove this.
# Until then, some installations may have a recent enough version of RubyGems, but it is not guaranteed.
return if Gem::Version.new(Gem::VERSION) >= Gem::Version.new("3.5.6")

module RuboCop
module Shopify
# Backport rubygems/rubygems#5275, so we can compare `Gem::Version`s directly against `String`s.
#
# Gem::Version.new("1.2.3") > "1.2"
#
# Without this, to support Ruby < 3.2, we would have to create a new `Gem::Version` instance ourselves.
#
# Gem::Version.new("1.2.3") > Gem::Version.new("1.2")
#
# This would get very verbose in our RuboCop config files.
module GemVersionStringComparableBackport
def <=>(other)
return self <=> self.class.new(other) if (String === other) && self.class.correct?(other)

super
end

Gem::Version.prepend(self)
end
end
end
8 changes: 1 addition & 7 deletions rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
<%
module GemVersionComparableToStringBackport # Backport rubygems#5275
def <=>(other)
return self <=> self.class.new(other) if (String === other) && self.class.correct?(other)
super
end
Gem::Version.prepend(self)
end if Gem::Version.new(Gem::VERSION) < Gem::Version.new("3.5.6") # Until Ruby 3.1 support is dropped.
require "rubocop/shopify/gem_version_string_comparable_backport"
rubocop_version = Gem.loaded_specs.fetch("rubocop").version
%>
Expand Down

0 comments on commit 3f20dbb

Please sign in to comment.