Skip to content

Commit 069dad7

Browse files
authored
Merge pull request #612 from Shopify/reduce-required-rubocop-version
2 parents 8616e05 + f1d087c commit 069dad7

File tree

4 files changed

+54
-9
lines changed

4 files changed

+54
-9
lines changed

Gemfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ PATH
22
remote: .
33
specs:
44
rubocop-shopify (2.14.0)
5-
rubocop (~> 1.53)
5+
rubocop (~> 1.51)
66

77
GEM
88
remote: https://rubygems.org/
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# frozen_string_literal: true
2+
3+
# This is true for Ruby 3.2+, so once support for 3.1 is dropped, we can remove this.
4+
# Until then, some installations may have a recent enough version of RubyGems, but it is not guaranteed.
5+
return if Gem::Version.new(Gem::VERSION) >= Gem::Version.new("3.5.6")
6+
7+
module RuboCop
8+
module Shopify
9+
# Backport rubygems/rubygems#5275, so we can compare `Gem::Version`s directly against `String`s.
10+
#
11+
# Gem::Version.new("1.2.3") > "1.2"
12+
#
13+
# Without this, to support Ruby < 3.2, we would have to create a new `Gem::Version` instance ourselves.
14+
#
15+
# Gem::Version.new("1.2.3") > Gem::Version.new("1.2")
16+
#
17+
# This would get very verbose in our RuboCop config files.
18+
module GemVersionStringComparableBackport
19+
def <=>(other)
20+
return self <=> self.class.new(other) if (String === other) && self.class.correct?(other)
21+
22+
super
23+
end
24+
25+
Gem::Version.prepend(self)
26+
end
27+
end
28+
end

rubocop-shopify.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,5 @@ Gem::Specification.new do |s|
2323

2424
s.required_ruby_version = ">= 2.7.0"
2525

26-
s.add_dependency("rubocop", "~> 1.53")
26+
s.add_dependency("rubocop", "~> 1.51")
2727
end

rubocop.yml

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
<%
2+
require "rubocop/shopify/gem_version_string_comparable_backport"
3+
24
rubocop_version = Gem.loaded_specs.fetch("rubocop").version
3-
v1_57 = Gem::Version.new("1.57")
4-
v1_58 = Gem::Version.new("1.58")
5-
v1_59 = Gem::Version.new("1.59")
65
%>
76

87
inherit_mode:
@@ -190,21 +189,23 @@ Lint/IncompatibleIoSelectWithFiberScheduler:
190189
Lint/InterpolationCheck:
191190
Enabled: false
192191

193-
<% if rubocop_version >= v1_59 %>
192+
<% if rubocop_version >= "1.59" %>
194193
Lint/ItWithoutArgumentsInBlock:
195194
Enabled: true
196195
<% end %>
197196

198197
Lint/LambdaWithoutLiteralBlock:
199198
Enabled: false
200199

201-
<% if rubocop_version >= v1_58 %>
200+
<% if rubocop_version >= "1.58" %>
202201
Lint/LiteralAssignmentInCondition:
203202
Enabled: true
204203
<% end %>
205204

205+
<% if rubocop_version >= "1.53" %>
206206
Lint/MixedCaseRange:
207207
Enabled: true
208+
<% end %>
208209

209210
Lint/MixedRegexpCaptureTypes:
210211
Enabled: false
@@ -239,8 +240,10 @@ Lint/RaiseException:
239240
Lint/RedundantDirGlobSort:
240241
Enabled: false
241242

243+
<% if rubocop_version >= "1.53" %>
242244
Lint/RedundantRegexpQuantifiers:
243245
Enabled: true
246+
<% end %>
244247

245248
Lint/RedundantRequireStatement:
246249
Enabled: false
@@ -727,8 +730,10 @@ Style/RandomWithOffset:
727730
Style/RedundantArgument:
728731
Enabled: false
729732

733+
<% if rubocop_version >= "1.52" %>
730734
Style/RedundantArrayConstructor:
731735
Enabled: true
736+
<% end %>
732737

733738
Style/RedundantAssignment:
734739
Enabled: false
@@ -742,8 +747,10 @@ Style/RedundantConditional:
742747
Style/RedundantConstantBase:
743748
Enabled: true
744749

750+
<% if rubocop_version >= "1.53" %>
745751
Style/RedundantCurrentDirectoryInPath:
746752
Enabled: true
753+
<% end %>
747754

748755
Style/RedundantDoubleSplatHashBraces:
749756
Enabled: true
@@ -757,8 +764,10 @@ Style/RedundantFetchBlock:
757764
Style/RedundantFileExtensionInRequire:
758765
Enabled: false
759766

767+
<% if rubocop_version >= "1.52" %>
760768
Style/RedundantFilterChain:
761769
Enabled: true
770+
<% end %>
762771

763772
Style/RedundantHeredocDelimiterQuotes:
764773
Enabled: true
@@ -769,14 +778,18 @@ Style/RedundantInitialize:
769778
Style/RedundantLineContinuation:
770779
Enabled: true
771780

781+
<% if rubocop_version >= "1.53" %>
772782
Style/RedundantRegexpArgument:
773783
Enabled: true
784+
<% end %>
774785

775786
Style/RedundantRegexpCharacterClass:
776787
Enabled: false
777788

789+
<% if rubocop_version >= "1.52" %>
778790
Style/RedundantRegexpConstructor:
779791
Enabled: true
792+
<% end %>
780793

781794
Style/RedundantRegexpEscape:
782795
Enabled: false
@@ -802,16 +815,18 @@ Style/RescueStandardError:
802815
Style/ReturnNil:
803816
Enabled: true
804817

818+
<% if rubocop_version >= "1.53" %>
805819
Style/ReturnNilInPredicateMethodDefinition:
806820
Enabled: true
821+
<% end %>
807822

808823
Style/SelectByRegexp:
809824
Enabled: false
810825

811826
Style/SingleArgumentDig:
812827
Enabled: false
813828

814-
<% if rubocop_version >= v1_57 %>
829+
<% if rubocop_version >= "1.57" %>
815830
Style/SingleLineDoEndBlock:
816831
Enabled: true
817832
<% end %>
@@ -840,7 +855,7 @@ Style/StringLiteralsInInterpolation:
840855
Style/StructInheritance:
841856
Enabled: false
842857

843-
<% if rubocop_version >= v1_58 %>
858+
<% if rubocop_version >= "1.58" %>
844859
Style/SuperWithArgsParentheses:
845860
Enabled: true
846861
<% end %>
@@ -875,8 +890,10 @@ Style/UnpackFirst:
875890
Style/WordArray:
876891
EnforcedStyle: brackets
877892

893+
<% if rubocop_version >= "1.53" %>
878894
Style/YAMLFileRead:
879895
Enabled: true
896+
<% end %>
880897

881898
Style/YodaCondition:
882899
Enabled: false

0 commit comments

Comments
 (0)