Skip to content

Include thread-safety rubocop and refactor minimum rubocop.gemfile #703

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 4 commits into from
Mar 21, 2025
Merged
Show file tree
Hide file tree
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
8 changes: 6 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ PATH
remote: .
specs:
rubocop-shopify (2.15.1)
rubocop (~> 1.62)
rubocop (~> 1.72, >= 1.72.1)
rubocop-thread_safety (>= 0.7.1)

GEM
remote: https://rubygems.org/
Expand Down Expand Up @@ -31,7 +32,7 @@ GEM
rainbow (3.1.1)
rake (13.2.1)
regexp_parser (2.10.0)
rubocop (1.73.1)
rubocop (1.72.2)
json (~> 2.3)
language_server-protocol (~> 3.17.0.2)
lint_roller (~> 1.1.0)
Expand All @@ -44,6 +45,9 @@ GEM
unicode-display_width (>= 2.4.0, < 4.0)
rubocop-ast (1.38.1)
parser (>= 3.3.1.0)
rubocop-thread_safety (0.7.1)
lint_roller (~> 1.1)
rubocop (~> 1.72, >= 1.72.1)
ruby-progressbar (1.13.0)
unicode-display_width (3.1.4)
unicode-emoji (~> 4.0, >= 4.0.4)
Expand Down
2 changes: 1 addition & 1 deletion bin/sort-cops
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def sort_cops(file_path)
end

if ARGV.empty?
puts "Usage: ruby sort_cops.rb path/to/rubocop.yml"
puts "Usage: ruby sort-cops path/to/rubocop.yml"
exit 1
end

Expand Down
20 changes: 16 additions & 4 deletions gemfiles/minimum_rubocop.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,21 @@

eval_gemfile "../Gemfile"

# This naively extracts the minimum rubocop version from our gemspec,
# This extracts the minimum rubocop version from our gemspec,
# allowing us to ensure that it remains compatible.
minimum_rubocop_version = File.read("rubocop-shopify.gemspec")[/(?<=add_dependency\("rubocop", "~> ).*(?="\)$)/]
raise "Failed to extract minimum rubocop version from gemspec" if minimum_rubocop_version.nil?

gem "rubocop", minimum_rubocop_version
supported_requirement_types = ['>=', '~>']
supported_requirements, unsupported_requirements = Gem::Specification
.load("rubocop-shopify.gemspec")
.dependencies.find { |d| d.name == "rubocop" }
.requirement.requirements
.partition { |type, _version| supported_requirement_types.include?(type) }
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clever 👏


raise <<~ERROR_MESSAGE unless unsupported_requirements.empty?
Unsupported requirement types: #{unsupported_requirements.inspect}.
Only #{supported_requirement_types.inspect} are supported.
ERROR_MESSAGE

minimum_version = supported_requirements.map { |_type, version| version }.max

gem "rubocop", minimum_version
3 changes: 2 additions & 1 deletion rubocop-shopify.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,6 @@ Gem::Specification.new do |s|

s.required_ruby_version = ">= 3.1.0"

s.add_dependency("rubocop", "~> 1.62")
s.add_dependency("rubocop", "~> 1.72", ">= 1.72.1")
s.add_dependency("rubocop-thread_safety", ">= 0.7.1")
end
Loading