Skip to content

Commit d1386b5

Browse files
committed
Ensure no leftover RuboCop version checks
As we may increase the minimum RuboCop version requirement soon, we should make sure that if we do, we don't leave behind redundant version checks. This adds a test to enforce they are cleaned up.
1 parent 21492fb commit d1386b5

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

test/config_test.rb

+28
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,34 @@ 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+
redundant_rubocop_version_checks = []
100+
101+
# RuboCop version checks are done in ERB, so we need to read the raw file
102+
File.read('rubocop.yml').each_line.with_index do |line, index|
103+
match = line.match(/<% if rubocop_version >= "(?<version>.*)" %>/)
104+
next unless match
105+
106+
minimum_version_for_config = Gem::Version.new(match[1])
107+
next if rubocop_version_requirement.satisfied_by?(minimum_version_for_config)
108+
109+
redundant_rubocop_version_checks << [index, line.chomp]
110+
end
111+
112+
assert(redundant_rubocop_version_checks.empty?, <<~ERROR_MESSAGE.chomp)
113+
Error: The following RuboCop version check(s) are redundant given the required version in the gemspec:
114+
115+
#{redundant_rubocop_version_checks.map { " #{_1.to_s.rjust(4)}: #{_2}" }.join("\n")}
116+
117+
Please remove these check(s), or (if you intend to maintain compatibility) loosen the `rubocop` requirement in the gemspec.
118+
ERROR_MESSAGE
119+
end
120+
93121
private
94122

95123
def checking_rubocop_version_compatibility?

0 commit comments

Comments
 (0)