Skip to content

Commit 3aa83df

Browse files
authored
Merge pull request #701 from Shopify/no-redundant-version-checks
Ensure no leftover RuboCop version checks
2 parents 21492fb + a288883 commit 3aa83df

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

test/config_test.rb

+26
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,32 @@ def test_no_cops_are_configured_as_pending
9090
ERROR_MESSAGE
9191
end
9292

93+
def test_config_does_not_check_for_rubocop_versions_below_minimum_version
94+
rubocop_version_requirement = Gem
95+
.loaded_specs.fetch('rubocop-shopify')
96+
.dependencies.find { _1.name == 'rubocop' }
97+
.requirement
98+
99+
# RuboCop version checks are done in ERB, so we need to read the raw file
100+
redundant_rubocop_version_checks = File.read('rubocop.yml').each_line.with_index.filter_map do |line, index|
101+
match = line.match(/<% if rubocop_version >= "(?<version>.*)" %>/)
102+
next unless match
103+
104+
minimum_version_for_config = Gem::Version.new(match[1])
105+
next if rubocop_version_requirement.satisfied_by?(minimum_version_for_config)
106+
107+
[index, line.chomp]
108+
end
109+
110+
assert(redundant_rubocop_version_checks.empty?, <<~ERROR_MESSAGE.chomp)
111+
The following RuboCop version check(s) are redundant given the gemspec's version requirement (#{rubocop_version_requirement}):
112+
113+
#{redundant_rubocop_version_checks.map { " #{_1.to_s.rjust(4)}: #{_2}" }.join("\n")}
114+
115+
Please remove these check(s), or (if you intend to maintain compatibility) loosen the `rubocop` requirement in the gemspec.
116+
ERROR_MESSAGE
117+
end
118+
93119
private
94120

95121
def checking_rubocop_version_compatibility?

0 commit comments

Comments
 (0)