Skip to content

Commit b48ea72

Browse files
authored
Merge pull request #579 from ualbertalib/add-rubocop
Add rubocop linter and CI job
2 parents 8c56309 + 1f16575 commit b48ea72

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+638
-297
lines changed

.github/workflows/ci.yml

+12-12
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,20 @@ on:
66
branches: [ main ]
77

88
jobs:
9-
# lint:
10-
# runs-on: ubuntu-latest
11-
# steps:
12-
# - name: Checkout code
13-
# uses: actions/checkout@v4
9+
lint:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Checkout code
13+
uses: actions/checkout@v4
1414

15-
# - name: Set up Ruby
16-
# uses: ruby/setup-ruby@v1
17-
# with:
18-
# ruby-version: .ruby-version
19-
# bundler-cache: true
15+
- name: Set up Ruby
16+
uses: ruby/setup-ruby@v1
17+
with:
18+
ruby-version: .ruby-version
19+
bundler-cache: true
2020

21-
# - name: Lint code for consistent style
22-
# run: bin/rubocop -f github
21+
- name: Lint code for consistent style
22+
run: bin/rubocop -f github
2323

2424
test:
2525
runs-on: ubuntu-latest

.rubocop.yml

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
require:
2+
- rubocop-capybara
3+
- rubocop-minitest
4+
- rubocop-performance
5+
- rubocop-rails
6+
- standard
7+
8+
inherit_gem:
9+
standard: config/base.yml
10+
11+
AllCops:
12+
SuggestExtensions: false
13+
TargetRubyVersion: 3.3
14+
NewCops: enable
15+
16+
Minitest/MultipleAssertions:
17+
Max: 10 # default 3
18+
19+
Style/FrozenStringLiteralComment:
20+
Enabled: true
21+
22+
# These below cops are good practice going forward, but due to legacy we exclude some migrations
23+
Rails/CreateTableWithTimestamps:
24+
Exclude:
25+
- db/migrate/20181101154531_create_cms.rb
26+
- db/migrate/20220603215833_create_active_storage_variant_records.active_storage.rb
27+
28+
Rails/SkipsModelValidations:
29+
Exclude:
30+
- db/migrate/20220603215832_add_service_name_to_active_storage_blobs.active_storage.rb
31+
32+
Rails/BulkChangeTable:
33+
Exclude:
34+
- db/migrate/20181101154602_create_friendly_id_slugs.rb
35+
- db/migrate/20181101154832_add_slug_to_profiles.rb
36+
37+
Rails/ThreeStateBooleanColumn:
38+
Exclude:
39+
- db/migrate/20181101154627_create_profiles.rb
40+
41+
# Below are cops that are currently disabled, where we should fix in the future
42+
# TODO: Fix ProfilesController so we don't need to use global vars
43+
Style/GlobalVars:
44+
Exclude:
45+
- app/controllers/profiles_controller.rb

Gemfile

+32-22
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,69 @@
1-
source 'https://rubygems.org'
1+
# frozen_string_literal: true
2+
3+
source "https://rubygems.org"
24
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
35

4-
ruby '3.1.4'
6+
ruby "3.1.4"
57

6-
gem 'rails', '~> 7.1.3'
8+
gem "rails", "~> 7.1.3"
79

8-
gem 'mysql2', '~> 0.5.6'
10+
gem "mysql2", "~> 0.5.6"
911
# Use Puma as the app server
10-
gem 'puma', '~> 6.4'
12+
gem "puma", "~> 6.4"
1113

1214
# Use Uglifier as compressor for JavaScript assets
13-
gem 'uglifier', '>= 1.3.0'
15+
gem "uglifier", ">= 1.3.0"
1416

15-
gem 'rollbar'
17+
gem "rollbar"
1618

1719
# See https://github.com/rails/execjs#readme for more supported runtimes
18-
gem 'execjs'
20+
gem "execjs"
1921

2022
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
21-
gem 'jbuilder', '~> 2.12'
23+
gem "jbuilder", "~> 2.12"
2224

2325
# Use ActiveStorage variant
24-
gem 'image_processing', '~> 1.12', '>= 1.12.2'
26+
gem "image_processing", "~> 1.12", ">= 1.12.2"
2527

26-
gem 'comfortable_mexican_sofa', github: 'restarone/comfortable-mexican-sofa', tag: '3.5'
28+
gem "comfortable_mexican_sofa", github: "restarone/comfortable-mexican-sofa", tag: "3.5"
2729

28-
gem 'friendly_id'
30+
gem "friendly_id"
2931

30-
gem 'htmlentities'
32+
gem "htmlentities"
3133
# Reduces boot times through caching; required in config/boot.rb
32-
gem 'bootsnap', '>= 1.4.2', require: false
34+
gem "bootsnap", ">= 1.4.2", require: false
3335

34-
gem 'webpacker', '~> 5.4'
36+
gem "webpacker", "~> 5.4"
3537

3638
gem "rdoc", ">= 6.6.3.1"
3739

3840
group :development, :test do
3941
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
40-
gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
42+
gem "byebug", platforms: [:mri, :mingw, :x64_mingw]
43+
44+
# Linters
45+
gem "rubocop", require: false
46+
gem "rubocop-capybara", require: false
47+
gem "rubocop-minitest", require: false
48+
gem "rubocop-performance", require: false
49+
gem "rubocop-rails", require: false
50+
gem "standard", ">= 1.35.1", require: false
4151
end
4252

4353
group :development do
4454
# Access an interactive console on exception pages or by calling 'console' anywhere in the code.
45-
gem 'web-console', '>= 3.3.0'
55+
gem "web-console", ">= 3.3.0"
4656

47-
gem 'listen', '>= 3.0.5', '< 3.10'
57+
gem "listen", ">= 3.0.5", "< 3.10"
4858
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
49-
gem 'spring', '>= 3.0'
59+
gem "spring", ">= 3.0"
5060
end
5161

5262
group :test do
5363
# Adds support for Capybara system testing and selenium driver
54-
gem 'capybara', '>= 2.15'
55-
gem 'selenium-webdriver'
64+
gem "capybara", ">= 2.15"
65+
gem "selenium-webdriver"
5666
end
5767

5868
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
59-
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
69+
gem "tzinfo-data", platforms: [:mingw, :mswin, :x64_mingw, :jruby]

Gemfile.lock

+72-4
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ GEM
9898
tzinfo (~> 2.0)
9999
addressable (2.8.6)
100100
public_suffix (>= 2.0.2, < 6.0)
101+
ast (2.4.2)
101102
base64 (0.2.0)
102103
bigdecimal (3.1.8)
103104
bindex (0.8.1)
@@ -154,8 +155,11 @@ GEM
154155
rails-dom-testing (>= 1, < 3)
155156
railties (>= 4.2.0)
156157
thor (>= 0.14, < 2.0)
158+
json (2.7.2)
157159
kramdown (2.4.0)
158160
rexml
161+
language_server-protocol (3.17.0.3)
162+
lint_roller (1.1.0)
159163
listen (3.9.0)
160164
rb-fsevent (~> 0.10, >= 0.10.3)
161165
rb-inotify (~> 0.9, >= 0.9.10)
@@ -174,7 +178,6 @@ GEM
174178
rake
175179
mini_magick (4.12.0)
176180
mini_mime (1.1.5)
177-
mini_portile2 (2.8.7)
178181
minitest (5.23.1)
179182
msgpack (1.7.2)
180183
mutex_m (0.2.0)
@@ -189,9 +192,22 @@ GEM
189192
net-smtp (0.5.0)
190193
net-protocol
191194
nio4r (2.7.3)
192-
nokogiri (1.16.5)
193-
mini_portile2 (~> 2.8.2)
195+
nokogiri (1.16.5-aarch64-linux)
194196
racc (~> 1.4)
197+
nokogiri (1.16.5-arm-linux)
198+
racc (~> 1.4)
199+
nokogiri (1.16.5-arm64-darwin)
200+
racc (~> 1.4)
201+
nokogiri (1.16.5-x86-linux)
202+
racc (~> 1.4)
203+
nokogiri (1.16.5-x86_64-darwin)
204+
racc (~> 1.4)
205+
nokogiri (1.16.5-x86_64-linux)
206+
racc (~> 1.4)
207+
parallel (1.24.0)
208+
parser (3.3.1.0)
209+
ast (~> 2.4.1)
210+
racc
195211
psych (5.1.2)
196212
stringio
197213
public_suffix (5.0.4)
@@ -240,6 +256,7 @@ GEM
240256
rake (>= 12.2)
241257
thor (~> 1.0, >= 1.2.2)
242258
zeitwerk (~> 2.6)
259+
rainbow (3.1.1)
243260
rake (13.2.1)
244261
rb-fsevent (0.11.2)
245262
rb-inotify (0.10.1)
@@ -252,6 +269,33 @@ GEM
252269
rexml (3.2.8)
253270
strscan (>= 3.0.9)
254271
rollbar (3.5.2)
272+
rubocop (1.63.5)
273+
json (~> 2.3)
274+
language_server-protocol (>= 3.17.0)
275+
parallel (~> 1.10)
276+
parser (>= 3.3.0.2)
277+
rainbow (>= 2.2.2, < 4.0)
278+
regexp_parser (>= 1.8, < 3.0)
279+
rexml (>= 3.2.5, < 4.0)
280+
rubocop-ast (>= 1.31.1, < 2.0)
281+
ruby-progressbar (~> 1.7)
282+
unicode-display_width (>= 2.4.0, < 3.0)
283+
rubocop-ast (1.31.3)
284+
parser (>= 3.3.1.0)
285+
rubocop-capybara (2.20.0)
286+
rubocop (~> 1.41)
287+
rubocop-minitest (0.35.0)
288+
rubocop (>= 1.61, < 2.0)
289+
rubocop-ast (>= 1.31.1, < 2.0)
290+
rubocop-performance (1.21.0)
291+
rubocop (>= 1.48.1, < 2.0)
292+
rubocop-ast (>= 1.31.1, < 2.0)
293+
rubocop-rails (2.25.0)
294+
activesupport (>= 4.2.0)
295+
rack (>= 1.1)
296+
rubocop (>= 1.33.0, < 2.0)
297+
rubocop-ast (>= 1.31.1, < 2.0)
298+
ruby-progressbar (1.13.0)
255299
ruby-vips (2.1.4)
256300
ffi (~> 1.12)
257301
rubyzip (2.3.2)
@@ -277,6 +321,18 @@ GEM
277321
actionpack (>= 5.2)
278322
activesupport (>= 5.2)
279323
sprockets (>= 3.0.0)
324+
standard (1.36.0)
325+
language_server-protocol (~> 3.17.0.2)
326+
lint_roller (~> 1.0)
327+
rubocop (~> 1.63.0)
328+
standard-custom (~> 1.0.0)
329+
standard-performance (~> 1.4)
330+
standard-custom (1.0.2)
331+
lint_roller (~> 1.0)
332+
rubocop (~> 1.50)
333+
standard-performance (1.4.0)
334+
lint_roller (~> 1.1)
335+
rubocop-performance (~> 1.21.0)
280336
stringio (3.1.0)
281337
strscan (3.1.0)
282338
temple (0.10.3)
@@ -287,6 +343,7 @@ GEM
287343
concurrent-ruby (~> 1.0)
288344
uglifier (4.2.0)
289345
execjs (>= 0.3.0, < 3)
346+
unicode-display_width (2.5.0)
290347
web-console (4.2.1)
291348
actionview (>= 6.0.0)
292349
activemodel (>= 6.0.0)
@@ -307,7 +364,12 @@ GEM
307364
zeitwerk (2.6.15)
308365

309366
PLATFORMS
310-
ruby
367+
aarch64-linux
368+
arm-linux
369+
arm64-darwin
370+
x86-linux
371+
x86_64-darwin
372+
x86_64-linux
311373

312374
DEPENDENCIES
313375
bootsnap (>= 1.4.2)
@@ -325,8 +387,14 @@ DEPENDENCIES
325387
rails (~> 7.1.3)
326388
rdoc (>= 6.6.3.1)
327389
rollbar
390+
rubocop
391+
rubocop-capybara
392+
rubocop-minitest
393+
rubocop-performance
394+
rubocop-rails
328395
selenium-webdriver
329396
spring (>= 3.0)
397+
standard (>= 1.35.1)
330398
tzinfo-data
331399
uglifier (>= 1.3.0)
332400
web-console (>= 3.3.0)

Rakefile

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
# frozen_string_literal: true
2+
13
# Add your own tasks in files placed in lib/tasks ending in .rake,
24
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
35

4-
require_relative 'config/application'
6+
require_relative "config/application"
57

68
Rails.application.load_tasks

app/channels/application_cable/channel.rb

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
module ApplicationCable
24
class Channel < ActionCable::Channel::Base
35
end

app/channels/application_cable/connection.rb

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
module ApplicationCable
24
class Connection < ActionCable::Connection::Base
35
end
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
1+
# frozen_string_literal: true
2+
13
class ApplicationController < ActionController::Base
24
end

app/controllers/errors_controller.rb

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
class ErrorsController < ApplicationController
24
def file_not_found
35
end

0 commit comments

Comments
 (0)