Skip to content

Ensure no leftover RuboCop version checks #701

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 4, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions test/config_test.rb
Original file line number Diff line number Diff line change
@@ -90,6 +90,32 @@ def test_no_cops_are_configured_as_pending
ERROR_MESSAGE
end

def test_config_does_not_check_for_rubocop_versions_below_minimum_version
rubocop_version_requirement = Gem
.loaded_specs.fetch('rubocop-shopify')
.dependencies.find { _1.name == 'rubocop' }
.requirement

# RuboCop version checks are done in ERB, so we need to read the raw file
redundant_rubocop_version_checks = File.read('rubocop.yml').each_line.with_index.filter_map do |line, index|
match = line.match(/<% if rubocop_version >= "(?<version>.*)" %>/)
next unless match

minimum_version_for_config = Gem::Version.new(match[1])
next if rubocop_version_requirement.satisfied_by?(minimum_version_for_config)

[index, line.chomp]
end

assert(redundant_rubocop_version_checks.empty?, <<~ERROR_MESSAGE.chomp)
The following RuboCop version check(s) are redundant given the gemspec's version requirement (#{rubocop_version_requirement}):

#{redundant_rubocop_version_checks.map { " #{_1.to_s.rjust(4)}: #{_2}" }.join("\n")}

Please remove these check(s), or (if you intend to maintain compatibility) loosen the `rubocop` requirement in the gemspec.
ERROR_MESSAGE
end

private

def checking_rubocop_version_compatibility?