Skip to content

Commit 41d2295

Browse files
authored
Switch to Omakase Rubocop config (#37)
1 parent dde3027 commit 41d2295

File tree

70 files changed

+378
-527
lines changed

Some content is hidden

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

70 files changed

+378
-527
lines changed

.rubocop.yml

Lines changed: 5 additions & 166 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,11 @@
1-
# Use Shopify's Rubocop config as a baseline.
21
inherit_gem:
3-
rubocop-shopify: rubocop.yml
2+
rubocop-rails-omakase: rubocop.yml
43

54
AllCops:
65
Exclude:
7-
- test/db/schema.rb
8-
- test/db/queue_schema.rb
6+
- test/db/*schema.rb
97
- vendor
108
SuggestExtensions: false
11-
NewCops: disable
12-
TargetRubyVersion: 3.2
13-
14-
# Layout
15-
16-
Layout/ArgumentAlignment:
17-
Enabled: true
18-
EnforcedStyle: with_fixed_indentation
19-
20-
Layout/ArrayAlignment:
21-
Enabled: true
22-
EnforcedStyle: with_fixed_indentation
23-
24-
Layout/FirstMethodArgumentLineBreak:
25-
Enabled: true
26-
27-
Layout/FirstMethodParameterLineBreak:
28-
Enabled: true
299

3010
Layout/LineLength:
3111
Enabled: true
@@ -34,148 +14,6 @@ Layout/LineLength:
3414
# Allow long comments.
3515
- "^#.*"
3616

37-
Layout/EndAlignment:
38-
Enabled: true
39-
EnforcedStyleAlignWith: start_of_line
40-
41-
Layout/ExtraSpacing:
42-
Enabled: true
43-
AllowForAlignment: false
44-
AllowBeforeTrailingComments: true
45-
46-
Layout/MultilineAssignmentLayout:
47-
Enabled: true
48-
EnforcedStyle: same_line
49-
50-
Layout/MultilineHashBraceLayout:
51-
Enabled: true
52-
EnforcedStyle: new_line
53-
54-
Layout/MultilineHashKeyLineBreaks:
55-
Enabled: true
56-
57-
Layout/MultilineMethodArgumentLineBreaks:
58-
Enabled: true
59-
60-
Layout/MultilineMethodCallBraceLayout:
61-
Enabled: true
62-
EnforcedStyle: new_line
63-
64-
Layout/SpaceAroundEqualsInParameterDefault:
65-
Enabled: true
66-
EnforcedStyle: no_space
67-
68-
Layout/SpaceInLambdaLiteral:
69-
Enabled: true
70-
EnforcedStyle: require_no_space
71-
72-
Layout/SpaceInsideArrayLiteralBrackets:
73-
Enabled: true
74-
EnforcedStyle: no_space
75-
76-
Layout/SpaceInsideArrayPercentLiteral:
77-
Enabled: true
78-
79-
Layout/SpaceInsideBlockBraces:
80-
Enabled: true
81-
EnforcedStyle: space
82-
EnforcedStyleForEmptyBraces: no_space
83-
SpaceBeforeBlockParameters: true
84-
85-
Layout/SpaceInsideHashLiteralBraces:
86-
Enabled: true
87-
EnforcedStyle: no_space
88-
89-
Layout/SpaceInsideParens:
90-
Enabled: true
91-
EnforcedStyle: no_space
92-
93-
Layout/SpaceInsidePercentLiteralDelimiters:
94-
Enabled: true
95-
96-
Layout/SpaceInsideRangeLiteral:
97-
Enabled: true
98-
99-
Layout/SpaceInsideReferenceBrackets:
100-
Enabled: true
101-
EnforcedStyle: no_space
102-
103-
Layout/SpaceInsideStringInterpolation:
104-
Enabled: true
105-
EnforcedStyle: no_space
106-
107-
# Linting
108-
109-
Lint/AssignmentInCondition:
110-
Enabled: false
111-
112-
Lint/SuppressedException:
113-
Enabled: false
114-
115-
# Metrics
116-
117-
Metrics/BlockNesting:
118-
Enabled: false
119-
120-
# Naming
121-
122-
Naming/AccessorMethodName:
123-
Enabled: false
124-
125-
Naming/InclusiveLanguage:
126-
Enabled: false
127-
128-
Naming/PredicateName:
129-
Enabled: false
130-
131-
# Style
132-
133-
Style/BlockDelimiters:
134-
Enabled: false
135-
136-
Style/ClassAndModuleChildren:
137-
Enabled: false
138-
139-
Style/ClassMethodsDefinitions:
140-
Enabled: false
141-
142-
Style/CommandLiteral:
143-
Enabled: false
144-
145-
Style/ConditionalAssignment:
146-
Enabled: false
147-
148-
Style/DateTime:
149-
Enabled: false
150-
151-
Style/FrozenStringLiteralComment:
152-
Enabled: false
153-
154-
Style/IfInsideElse:
155-
Enabled: false
156-
157-
Style/MultilineTernaryOperator:
158-
Enabled: false
159-
160-
Style/NestedTernaryOperator:
161-
Enabled: false
162-
163-
Style/RedundantReturn:
164-
Enabled: false
165-
166-
Style/RedundantSelf:
167-
Enabled: false
168-
169-
Style/RegexpLiteral:
170-
Enabled: false
171-
172-
Style/ReturnNil:
173-
Enabled: false
174-
175-
Style/TrailingCommaInArguments:
176-
Enabled: true
177-
EnforcedStyleForMultiline: comma
178-
17917
Style/TrailingCommaInArrayLiteral:
18018
Enabled: true
18119
EnforcedStyleForMultiline: comma
@@ -184,5 +22,6 @@ Style/TrailingCommaInHashLiteral:
18422
Enabled: true
18523
EnforcedStyleForMultiline: comma
18624

187-
Style/WordArray:
188-
Enabled: false
25+
Style/TrailingCommaInArguments:
26+
Enabled: true
27+
EnforcedStyleForMultiline: comma

Gemfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ group :development do
7474
gem "foreman"
7575
gem "listen"
7676
gem "pry-rails"
77-
gem "rubocop-shopify", require: false
77+
gem "rubocop-rails-omakase", require: false
7878
gem "ruby-lsp", require: false
7979
gem "web-console"
8080

Gemfile.lock

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -295,8 +295,20 @@ GEM
295295
rubocop-ast (1.44.1)
296296
parser (>= 3.3.7.2)
297297
prism (~> 1.4)
298-
rubocop-shopify (2.17.0)
299-
rubocop (~> 1.62)
298+
rubocop-performance (1.25.0)
299+
lint_roller (~> 1.1)
300+
rubocop (>= 1.75.0, < 2.0)
301+
rubocop-ast (>= 1.38.0, < 2.0)
302+
rubocop-rails (2.31.0)
303+
activesupport (>= 4.2.0)
304+
lint_roller (~> 1.1)
305+
rack (>= 1.1)
306+
rubocop (>= 1.75.0, < 2.0)
307+
rubocop-ast (>= 1.38.0, < 2.0)
308+
rubocop-rails-omakase (1.1.0)
309+
rubocop (>= 1.72)
310+
rubocop-performance (>= 1.24)
311+
rubocop-rails (>= 2.30)
300312
ruby-lsp (0.23.17)
301313
language_server-protocol (~> 3.17.0)
302314
prism (>= 1.2, < 2.0)
@@ -324,7 +336,7 @@ GEM
324336
fugit (~> 1.11.0)
325337
railties (>= 7.1)
326338
thor (~> 1.3.1)
327-
sorbet-runtime (0.5.12070)
339+
sorbet-runtime (0.5.12079)
328340
sqlite3 (2.6.0-arm64-darwin)
329341
sqlite3 (2.6.0-x86_64-darwin)
330342
sqlite3 (2.6.0-x86_64-linux-gnu)
@@ -389,7 +401,7 @@ DEPENDENCIES
389401
rake
390402
ransack (>= 4.0)
391403
rest_framework!
392-
rubocop-shopify
404+
rubocop-rails-omakase
393405
ruby-lsp
394406
sentry-rails
395407
simplecov

Rakefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ task :maintain_assets do
1212
assets_dir = File.expand_path("vendor/assets", __dir__)
1313

1414
# First, delete js/css directories.
15-
["javascripts", "stylesheets"].each do |path_type|
15+
[ "javascripts", "stylesheets" ].each do |path_type|
1616
FileUtils.rm_rf(File.expand_path("#{path_type}/rest_framework", assets_dir))
1717
Dir.mkdir(File.expand_path("#{path_type}/rest_framework", assets_dir))
1818
end

lib/rest_framework.rb

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ module RESTFramework
99
BUILTIN_MEMBER_ACTIONS = {
1010
show: :get,
1111
edit: :get,
12-
update: [:put, :patch].freeze,
12+
update: [ :put, :patch ].freeze,
1313
destroy: :delete,
1414
}.freeze
1515
RRF_BUILTIN_ACTIONS = {
1616
options: :options,
1717
}.freeze
1818
RRF_BUILTIN_BULK_ACTIONS = {
19-
update_all: [:put, :patch].freeze,
19+
update_all: [ :put, :patch ].freeze,
2020
destroy_all: :delete,
2121
}.freeze
2222

@@ -65,12 +65,12 @@ module RESTFramework
6565
"highlight-a11y-dark.min.css" => {
6666
url: "https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.11.0/styles/a11y-dark.min.css",
6767
sri: "sha512-Vj6gPCk8EZlqnoveEyuGyYaWZ1+jyjMPg8g4shwyyNlRQl6d3L9At02ZHQr5K6s5duZl/+YKMnM3/8pDhoUphg==",
68-
extra_tag_attrs: {class: "rrf-dark-mode"},
68+
extra_tag_attrs: { class: "rrf-dark-mode" },
6969
},
7070
"highlight-a11y-light.min.css" => {
7171
url: "https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.11.0/styles/a11y-light.min.css",
7272
sri: "sha512-WDk6RzwygsN9KecRHAfm9HTN87LQjqdygDmkHSJxVkVI7ErCZ8ZWxP6T8RvBujY1n2/E4Ac+bn2ChXnp5rnnHA==",
73-
extra_tag_attrs: {class: "rrf-light-mode"},
73+
extra_tag_attrs: { class: "rrf-light-mode" },
7474
},
7575

7676
# NeatJSON
@@ -117,7 +117,7 @@ module RESTFramework
117117
raise "Unknown asset extension: #{ext}."
118118
end
119119

120-
[name, cfg]
120+
[ name, cfg ]
121121
}.to_h.freeze
122122
# rubocop:enable Layout/LineLength
123123

@@ -126,8 +126,8 @@ module RESTFramework
126126
# Global configuration should be kept minimal, as controller-level configurations allows multiple
127127
# APIs to be defined to behave differently.
128128
class Config
129-
DEFAULT_LABEL_FIELDS = %w(name label login title email username url).freeze
130-
DEFAULT_SEARCH_COLUMNS = DEFAULT_LABEL_FIELDS + %w(description note).freeze
129+
DEFAULT_LABEL_FIELDS = %w[name label login title email username url].freeze
130+
DEFAULT_SEARCH_COLUMNS = DEFAULT_LABEL_FIELDS + %w[description note].freeze
131131
DEFAULT_EXCLUDE_BODY_FIELDS = %w[
132132
created_at
133133
created_by
@@ -192,15 +192,15 @@ def initialize
192192
end
193193

194194
def self.config
195-
return @config ||= Config.new
195+
@config ||= Config.new
196196
end
197197

198198
def self.configure
199199
yield(self.config)
200200
end
201201

202202
def self.features
203-
return @features ||= {}
203+
@features ||= {}
204204
end
205205
end
206206

lib/rest_framework/errors/nil_passed_to_render_api_error.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
class RESTFramework::Errors::NilPassedToRenderAPIError < RESTFramework::Errors::BaseError
22
def message
3-
return <<~MSG.split("\n").join(" ")
3+
<<~MSG.split("\n").join(" ")
44
Payload of `nil` was passed to `render_api`; this is unsupported. If you want a blank
55
response, pass `''` (an empty string) as the payload. If this was the result of a `find_by`
66
(or similar Active Record method) not finding a record, you should use the bang version (e.g.,

lib/rest_framework/errors/unknown_model_error.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ def initialize(controller_class)
55
end
66

77
def message
8-
return <<~MSG.split("\n").join(" ")
8+
<<~MSG.split("\n").join(" ")
99
The model class for `#{@controller_class}` could not be determined. Any controller that
1010
includes `RESTFramework::BaseModelControllerMixin` (directly or indirectly) must either set
1111
the `model` attribute on the controller, or the model must be deducible from the controller

lib/rest_framework/filters/ordering_filter.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
class RESTFramework::Filters::OrderingFilter < RESTFramework::Filters::BaseFilter
33
# Get a list of ordering fields for the current action.
44
def _get_fields
5-
return @controller.class.ordering_fields&.map(&:to_s) || @controller.get_fields
5+
@controller.class.ordering_fields&.map(&:to_s) || @controller.get_fields
66
end
77

88
# Convert ordering string to an ordering configuration.
@@ -34,7 +34,7 @@ def _get_ordering
3434
return ordering
3535
end
3636

37-
return nil
37+
nil
3838
end
3939

4040
# Order data according to the request query parameters.
@@ -46,7 +46,7 @@ def filter_data(data)
4646
return data.send(reorder ? :reorder : :order, ordering)
4747
end
4848

49-
return data
49+
data
5050
end
5151
end
5252

0 commit comments

Comments
 (0)