Skip to content

Commit 7db18dc

Browse files
committed
Setup Ruby linter and correct mistakes
1 parent 7099cbb commit 7db18dc

File tree

22 files changed

+88
-44
lines changed

22 files changed

+88
-44
lines changed

.rubocop.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
inherit_gem:
2+
rubocop-shopify: rubocop.yml
3+
4+
AllCops:
5+
NewCops: disable
6+
SuggestExtensions: false
7+
Exclude:
8+
- test/fixtures/date/**/*

Gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ gemspec
77

88
gem "rake", "~> 13.0"
99
gem "minitest", "~> 5.16"
10+
gem "rubocop-shopify"

Gemfile.lock

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,43 @@ PATH
99
GEM
1010
remote: https://rubygems.org/
1111
specs:
12+
ast (2.4.3)
13+
json (2.16.0)
14+
language_server-protocol (3.17.0.5)
15+
lint_roller (1.1.0)
1216
minitest (5.25.5)
17+
parallel (1.27.0)
18+
parser (3.3.10.0)
19+
ast (~> 2.4.1)
20+
racc
1321
prism (1.6.0)
22+
racc (1.8.1)
23+
rainbow (3.1.1)
1424
rake (13.3.0)
1525
rake-compiler (1.3.0)
1626
rake
27+
regexp_parser (2.11.3)
28+
rubocop (1.81.7)
29+
json (~> 2.3)
30+
language_server-protocol (~> 3.17.0.2)
31+
lint_roller (~> 1.1.0)
32+
parallel (~> 1.10)
33+
parser (>= 3.3.0.2)
34+
rainbow (>= 2.2.2, < 4.0)
35+
regexp_parser (>= 2.9.3, < 3.0)
36+
rubocop-ast (>= 1.47.1, < 2.0)
37+
ruby-progressbar (~> 1.7)
38+
unicode-display_width (>= 2.4.0, < 4.0)
39+
rubocop-ast (1.48.0)
40+
parser (>= 3.3.7.2)
41+
prism (~> 1.4)
42+
rubocop-shopify (2.18.0)
43+
rubocop (~> 1.62)
44+
ruby-progressbar (1.13.0)
1745
thor (1.4.0)
46+
unicode-display_width (3.2.0)
47+
unicode-emoji (~> 4.1)
48+
unicode-emoji (4.1.0)
1849

1950
PLATFORMS
2051
arm64-darwin-23
@@ -24,6 +55,7 @@ DEPENDENCIES
2455
cibuildgem!
2556
minitest (~> 5.16)
2657
rake (~> 13.0)
58+
rubocop-shopify
2759

2860
BUNDLED WITH
2961
2.7.2

Rakefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ rescue LoadError
1313
# it the GitHub action clones the repo and runs `rake install`, without running a `bundle install` first.
1414
end
1515

16-
task default: :test
16+
task(default: :test)

cibuildgem.gemspec

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ Gem::Specification.new do |spec|
3030
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
3131
spec.require_paths = ["lib"]
3232

33-
spec.add_dependency "rake-compiler"
34-
spec.add_dependency "thor"
35-
spec.add_dependency "prism"
33+
spec.add_dependency("prism")
34+
spec.add_dependency("rake-compiler")
35+
spec.add_dependency("thor")
3636
end

lib/cibuildgem/cli.rb

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@ class CLI < Thor
99

1010
source_root(File.expand_path("templates", __dir__))
1111

12-
def self.exit_on_failure?
13-
true
12+
class << self
13+
def exit_on_failure?
14+
true
15+
end
1416
end
1517

1618
desc "compile", "Compile a gem's native extension."
@@ -92,13 +94,12 @@ def clobber
9294
method_option "working-directory", type: "string", required: false, desc: "If your gem lives outside of the repository root, specify where."
9395
method_option "test-command", type: "string", required: false, desc: "The test command to run. Defaults to running `bundle exec rake test` and `bundle exec rake spec`."
9496
def ci_template
95-
# os = ["macos-latest", "macos-15-intel", "ubuntu-latest", "windows-latest"]
96-
os = ["macos-latest", "ubuntu-22.04"] # Just this for now because the CI takes too long otherwise.
97-
9897
ruby_requirements = compilation_task.gemspec.required_ruby_version
99-
latest_supported_ruby_version = RubySeries.latest_version_for_requirements(ruby_requirements)
100-
runtime_version_for_compilation = RubySeries.runtime_version_for_compilation(ruby_requirements)
101-
ruby_versions_for_testing = RubySeries.versions_to_test_against(ruby_requirements)
98+
# os = ["macos-latest", "macos-15-intel", "ubuntu-latest", "windows-latest"]
99+
@os = ["macos-latest", "ubuntu-22.04"] # Just this for now because the CI takes too long otherwise.
100+
@latest_supported_ruby_version = RubySeries.latest_version_for_requirements(ruby_requirements)
101+
@runtime_version_for_compilation = RubySeries.runtime_version_for_compilation(ruby_requirements)
102+
@ruby_versions_for_testing = RubySeries.versions_to_test_against(ruby_requirements)
102103

103104
directory(".github", context: instance_eval("binding"))
104105
end
@@ -117,12 +118,12 @@ def release
117118
desc "print_ruby_cc_version", "Output the cross compile ruby version needed for the gem. For internal usage", hide: true
118119
method_option "gemspec", type: "string", required: false, desc: "The gemspec to use. If the option is not passed, a gemspec file from the current working directory will be used."
119120
def print_ruby_cc_version
120-
print compilation_task.ruby_cc_version
121+
print(compilation_task.ruby_cc_version)
121122
end
122123

123124
desc "normalized_platform", "The platform name for compilation purposes", hide: true
124125
def print_normalized_platform
125-
print compilation_task.normalized_platform
126+
print(compilation_task.normalized_platform)
126127
end
127128

128129
private
@@ -143,7 +144,7 @@ def run_rake_tasks!(*tasks)
143144
def compilation_task
144145
@compilation_task ||= CompilationTasks.new(false)
145146
rescue GemspecError => e
146-
print e.message
147+
print(e.message)
147148

148149
Kernel.exit(false)
149150
end

lib/cibuildgem/compilation_tasks.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class CompilationTasks
1010
attr_reader :gemspec, :native, :create_packaging_task, :extension_task
1111

1212
def initialize(create_packaging_task = false, gemspec = nil)
13-
@gemspec = Bundler.load_gemspec(gemspec || find_gemspec)
13+
@gemspec = Bundler.load_gemspec(gemspec || find_gemspec)
1414
verify_gemspec!
1515

1616
@create_packaging_task = create_packaging_task
@@ -85,7 +85,7 @@ def disable_shared
8585
makefile_content.match(/LIBRUBYARG_SHARED = (.*)/) do |match|
8686
shared_flags = match[1].split(" ")
8787
shared_flags.reject! { |flag| flag == "-l$(RUBY_SO_NAME)" }
88-
makefile_content.gsub!(/(LIBRUBYARG_SHARED = ).*/, "\\1#{shared_flags.join(' ')}")
88+
makefile_content.gsub!(/(LIBRUBYARG_SHARED = ).*/, "\\1#{shared_flags.join(" ")}")
8989

9090
File.write(task.name, makefile_content)
9191
end

lib/cibuildgem/ruby_series.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def versions_to_test_against(requirements)
3131
end.reverse
3232

3333
selected_rubies.map do |version|
34-
version.segments.tap(&:pop).join('.')
34+
version.segments.tap(&:pop).join(".")
3535
end
3636
end
3737

lib/cibuildgem/tasks/wrapper.rake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ end
2222

2323
unless Rake::Task.task_defined?(:test)
2424
task(:test) do
25-
raise(RuntimeError, "Don't know how to build task 'test'") unless Rake::Task.task_defined?(:spec)
25+
raise("Don't know how to build task 'test'") unless Rake::Task.task_defined?(:spec)
2626

2727
Rake::Task[:spec].invoke
2828
end

lib/cibuildgem/templates/.github/workflows/cibuildgem.yaml.tt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@ jobs:
1313
name: "Cross compile the gem on different ruby versions"
1414
strategy:
1515
matrix:
16-
os: <%= os %>
16+
os: <%= @os %>
1717
runs-on: "${{ matrix.os }}"
1818
steps:
1919
- name: "Checkout code"
2020
uses: "actions/checkout@v5"
2121
- name: "Setup Ruby"
2222
uses: "ruby/setup-ruby@v1"
2323
with:
24-
ruby-version: "<%= runtime_version_for_compilation %>"
24+
ruby-version: "<%= @runtime_version_for_compilation %>"
2525
bundler-cache: true
2626
<%- if options['working-directory'] -%>
2727
working-directory: "<%= options['working-directory'] %>"
@@ -39,8 +39,8 @@ jobs:
3939
needs: compile
4040
strategy:
4141
matrix:
42-
os: <%= os %>
43-
rubies: <%= ruby_versions_for_testing %>
42+
os: <%= @os %>
43+
rubies: <%= @ruby_versions_for_testing %>
4444
type: ["cross", "native"]
4545
runs-on: "${{ matrix.os }}"
4646
steps:
@@ -70,13 +70,13 @@ jobs:
7070
needs: test
7171
strategy:
7272
matrix:
73-
os: <%= os %>
73+
os: <%= @os %>
7474
runs-on: "${{ matrix.os }}"
7575
steps:
7676
- name: "Setup Ruby"
7777
uses: "ruby/setup-ruby@v1"
7878
with:
79-
ruby-version: "<%= latest_supported_ruby_version %>"
79+
ruby-version: "<%= @latest_supported_ruby_version %>"
8080
- name: "Run cibuildgem"
8181
uses: "shopify/cibuildgem/.github/actions/cibuildgem@main"
8282
with:

0 commit comments

Comments
 (0)