-
Notifications
You must be signed in to change notification settings - Fork 18
/
.rubocop.yml
266 lines (220 loc) · 6.27 KB
/
.rubocop.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
# This configures Rubocop for this template repo - see
# [rubocop.yml.tt](./rubocop.yml.tt) if you want to change the Rubocop
# configuration which is copied into generated applications.
---
require:
- rubocop-capybara
- rubocop-factory_bot
- rubocop-performance
- rubocop-rails
- rubocop-rspec
# Built-in config:
# https://github.com/bbatsov/rubocop/blob/master/config/default.yml
Rails:
Enabled: true
AllCops:
# Target the oldest Ruby that this template's chosen Rails version supports In
# a normal Rails app, Rubocop would infer this from the version of Ruby
# running. We want the rubocop checks that run on this repo to work for any
# version of Ruby that the chosen Rails version supports so we have to be
# explicit.
TargetRubyVersion:
<%=
YAML.safe_load(Pathname.new("./target_versions.yml").realpath.read).fetch("minimum_ruby_major_minor")
%>
# In a normal Rails app, Rubocop would pull this from the Gemfile. We want the
# rubocop checks that run on this repo to be consistent with the checks that
# run on generated apps so we have to be explicit.
TargetRailsVersion:
<%=
YAML.safe_load(Pathname.new("./target_versions.yml").realpath.read).fetch("target_rails_major_minor")
%>
NewCops: enable
DisplayCopNames: true
DisplayStyleGuide: true
Exclude:
- 'tmp/**/*'
- 'vendor/**/*'
- 'node_modules/**/*'
Style/Documentation:
Enabled: false
Layout/LineLength:
Max: 200
Metrics/BlockLength:
Max: 50
Metrics/CyclomaticComplexity:
Max: 10
Metrics/MethodLength:
Max: 50
# This cop complains when you have variables named things like:
# address_line_1
# address_line_2
# etc.
Naming/VariableNumber:
Enabled: false
# Just always use `raise` and stop thinking about it.
Style/SignalException:
EnforcedStyle: only_raise
# We think that:
# array = [
# :value
# ]
# and_in_a_method_call([
# :value
# ])
# Looks better than:
# value = [
# :value
# ]
# but_in_a_method_call([
# :its_like_this
# ])
Layout/FirstArrayElementIndentation:
EnforcedStyle: consistent
# We think that:
# hash = {
# key: :value
# }
# and_in_a_method_call({
# no: :difference
# })
# Looks better than:
# hash = {
# key: :value
# }
# but_in_a_method_call({
# its_like: :this
# })
Layout/FirstHashElementIndentation:
EnforcedStyle: consistent
# We think that:
# {
# foo: :bar
# baz: :bip
# }
# Looks better than:
# { foo: :bar
# baz: :bip }
Layout/MultilineHashBraceLayout:
Enabled: false
# We think that:
# foo(
# bar: :baz,
# bip: :whizz
# )
# Looks better than:
# foo(bar: baz,
# bip: :whizz)
Layout/MultilineMethodCallBraceLayout:
Enabled: false
# Just always use double quotes and stop thinking about it.
Style/StringLiterals:
EnforcedStyle: double_quotes
Style/StringLiteralsInInterpolation:
EnforcedStyle: double_quotes
# Ruby 2.4+ has a magic comment that makes all strings frozen and Rubocop wants to put it
# at the top of every. single. file. We decided we didn't want that - for now.
Style/FrozenStringLiteralComment:
Enabled: false
# Single line method definitions are totally fine, and often more readable, consider:
# class WidgetsPolicy
# def create?; false; end
# def index?; true; end
# def show?; true; end
# def update?; false; end
# def delete?; false; end
# end
Style/SingleLineMethods:
Enabled: false
# We want you to put a blank line between method definitions, the only exception being
# if you're defining a bunch of single-line methods as above.
Layout/EmptyLineBetweenDefs:
AllowAdjacentOneLineDefs: true
Naming/FileName:
Exclude:
- '**/Gemfile.rb'
- '**/Rakefile.rb'
# Disable preference for Ruby's new safe navigation operator `&.` because it
# usually comes at the cost of expressiveness in the simple case:
#
# - coupon_usage.destroy if coupon_usage
# + coupon_usage&.destroy
#
# And guides you towards Law of Demeter violations in the extreme case:
#
# result&.data&.attributes&.payments&.first&.payment_token
#
# Disabling this cop doesn't stop you from using it, but be prepared to defend
# it in code review if you do.
Style/SafeNavigation:
Enabled: false
# Ruby supports two styles of string template formatting.
# "annotated" - format("%<greeting>s", greeting: "Hello")
# "template" - format("%{greeting}", greeting: "Hello")
#
# While the annotated format is more descriptive, it also comes in a style that is
# significantly harder for a developer to parse. The template style is easy to read, understand,
# and is consistent with formatting with (for example), interpolation (#{}).
Style/FormatStringToken:
EnforcedStyle: template
# This syntax is a deliberate idiom in rspec
# bbatsov endorses disabling it for rspec
# https://github.com/bbatsov/rubocop/issues/4222#issuecomment-290722962
Lint/AmbiguousBlockAssociation:
Exclude:
- 'spec/**/*'
# https://rubocop.readthedocs.io/en/latest/cops_style/
Style/HashTransformKeys:
Enabled: false
# https://rubocop.readthedocs.io/en/latest/cops_style/
Style/HashTransformValues:
Enabled: false
Metrics/AbcSize:
Max: 18
Exclude:
- 'spec/**/*'
Metrics/ClassLength:
Exclude:
- 'spec/**/*'
Naming/MemoizedInstanceVariableName:
EnforcedStyleForLeadingUnderscores: optional
Performance/Casecmp:
Enabled: false
Rails/ApplicationRecord:
Exclude:
- 'db/migrate/**'
# we don't require using Rails.logger in lib, as it often doesn't go where
# we'd want for the code that lives there, or otherwise isn't even available
Rails/Output:
Exclude:
- 'lib/**/*'
Style/BarePercentLiterals:
EnforcedStyle: percent_q
Style/DoubleNegation:
Enabled: false
Style/EmptyMethod:
Enabled: false
Style/NumericPredicate:
Enabled: false
Style/TrivialAccessors:
AllowPredicates: true
RSpec:
Language:
Expectations:
- assert_match
RSpec/MultipleExpectations:
Max: 10
RSpec/ExampleLength:
Max: 30
Rails/LexicallyScopedActionFilter:
Exclude:
- 'app/controllers/application_controller.rb'
RSpec/RepeatedExample:
Exclude:
- 'variants/pundit/spec/policies/**'
RSpec/MultipleMemoizedHelpers:
Max: 10
FactoryBot/SyntaxMethods:
Enabled: false
Rails/SquishedSQLHeredocs:
Enabled: false