forked from arkency/find-open-source-mentor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.rubocop.yml
354 lines (300 loc) · 8.58 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
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
AllCops:
TargetRubyVersion: 2.6.3
Exclude:
- 'db/**/*'
- 'bin/*'
- 'config/initializers/*'
- 'config/environments/*'
- 'vendor/**/*'
- 'Gemfile'
- 'Gemfile.lock'
- 'Rakefile'
- 'Guardfile'
- 'lib/tasks/auto_annotate_models.rake'
# === METRICS =================================================================================== #
# Commonly used screens these days easily fit more than 80 characters.
Metrics/LineLength:
Max: 100
# The guiding principle of classes is SRP, SRP can't be accurately measured by LoC
Metrics/ClassLength:
Max: 100
Exclude:
- 'spec/**/*'
# Avoid writing of large modules
Metrics/ModuleLength:
Max: 100
# Avoid excessive block nesting
Metrics/BlockNesting:
Max: 3
Exclude:
- 'spec/**/*'
# Create separate methods/services to be used within block
Metrics/BlockLength:
Max: 3
Exclude:
- 'spec/**/*'
- 'config/initializers/**/*'
- 'config/routes.rb'
ExcludedMethods:
- included
- class_methods
- class_eval
- define_method
- instance_eval
# Avoid parameter lists longer than three or four parameters
# https://github.com/bbatsov/ruby-style-guide#too-many-params
Metrics/ParameterLists:
Max: 4
# === LAYOUT ==================================================================================== #
# Most readable form.
Layout/AlignHash:
EnforcedHashRocketStyle: table
EnforcedColonStyle: table
# Add empty line after all guard clauses
Layout/EmptyLineAfterGuardClause:
Enabled: true
# Check space around operators
Layout/SpaceAroundOperators:
Enabled: true
# This cop checks for extra/unnecessary whitespace
Layout/ExtraSpacing:
ForceEqualSignAlignment: true
# Method chains are indented with 2 spaces
Layout/MultilineMethodCallIndentation:
EnforcedStyle: indented
IndentationWidth: 2
# Multi-line expressions with operators are indented with 2 spaces
Layout/MultilineOperationIndentation:
EnforcedStyle: indented
IndentationWidth: 2
# Check if tabulations throughout the project are the same: 2 spaces
Layout/Tab:
IndentationWidth: 2
# Order of building models
Layout/ClassStructure:
Enabled: true
Include:
- 'app/models/**/*'
- 'lib/models/**/*'
Categories:
modules:
- extend
- include
- prepend
macroses:
- acts_as_token_authenticatable
- acts_as_tenant
- devise
- rolify
- scopify
- resourcify
associations:
- belongs_to
- has_one
- has_many
- has_one_attached
- has_many_attached
nested_attributes:
- accepts_nested_attributes_for
validations:
- validates
- validates_uniqueness_to_tenant
- validate
hooks:
- before_validation
- before_save
- before_create
- before_update
- before_destroy
- after_validation
- after_save
- after_create
- after_update
- after_destroy
attributes:
- attr_accessor
- attr_reader
- attr_writer
- enum
delegations:
- delegate
scopes:
- scope
ExpectedOrder:
- modules
- constants
- macroses
- associations
- nested_attributes
- validations
- hooks
- attributes
- delegations
- scopes
- public_class_methods
- initializer
- public_methods
- protected_methods
- private_methods
# === LINT ====================================================================================== #
# Suppressing exceptions can be perfectly fine, and be it to avoid to
# explicitly type nil into the rescue since that's what you want to return,
# or suppressing LoadError for optional dependencies
Lint/HandleExceptions:
Enabled: false
# Don't use assignment in conditions
Lint/AssignmentInCondition:
AllowSafeAssignment: false
# This cop checks for ambiguous operators in the first argument of a method invocation without parentheses.
Lint/AmbiguousOperator:
Enabled: false
# Shadowing outer local variables with block parameters is often useful
# to not reinvent a new name for the same thing, it highlights the relation
# between the outer variable and the parameter. The cases where it's actually
# confusing are rare, and usually bad for other reasons already, for example
# because the method is too long.
Lint/ShadowingOuterLocalVariable:
Enabled: false
# There are valid cases, for example debugging Cucumber steps,
# also they'll fail CI anyway. Then add those files to exclude
Lint/Debugger:
Enabled: true
# Inherit errors from StandardError is more typical than from RuntimeError
Lint/InheritException:
EnforcedStyle: standard_error
# === NAMING ==================================================================================== #
# Forbid short names for block arguments
Naming/UncommunicativeBlockParamName:
AllowNamesEndingInNumbers: false
ForbiddenNames:
- a
- b
- c
- k
- i
- j
# Forbid short names for method arguments
Naming/UncommunicativeMethodParamName:
MinNameLength: 1
AllowNamesEndingInNumbers: false
ForbiddenNames:
- a
- b
- c
- k
- i
- j
# Forbid numbers in variable names
Naming/VariableNumber:
EnforcedStyle: non_integer
# Same name of instance variable and memoization method
Naming/MemoizedInstanceVariableName:
Exclude:
- 'app/*/concerns/**/*.rb'
# === STYLE ===================================================================================== #
# Allow private to be inlined in method definitions.
Style/AccessModifierDeclarations:
Enabled: false
# We do not need to support Ruby 1.9, so this is good to use.
Style/SymbolArray:
Enabled: true
# Mixing the styles looks just silly.
Style/HashSyntax:
EnforcedStyle: ruby19_no_mixed_keys
# String#% is by far the least verbose and only object oriented variant.
Style/FormatString:
EnforcedStyle: percent
# This cop enforces the use of consistent method names from the Enumerable module
Style/CollectionMethods:
Enabled: true
# Either allow this style or don't. Marking it as safe with parenthesis
# is silly. Let's try to live without them for now.
Style/ParenthesesAroundCondition:
AllowSafeAssignment: false
# A specialized exception class will take one or more arguments and construct the message from it.
# So both variants make sense.
Style/RaiseArgs:
Enabled: false
# Fail is an alias of raise. Avoid aliases, it's more cognitive load for no gain.
# The argument that fail should be used to abort the program is wrong too,
# there's Kernel#abort for that.
Style/SignalException:
EnforcedStyle: only_raise
# do / end blocks should be used for side effects,
# methods that run a block for side effects and have
# a useful return value are rare, assign the return
# value to a local variable for those cases.
Style/MethodCalledOnDoEndBlock:
Enabled: true
# Big numbers with underscore started from one thousand
Style/NumericLiterals:
Exclude:
- 'config/initializers/**/*'
- 'config/puma.rb'
- 'config.ru'
MinDigits: 4
# This cop enforces consistency between 'return nil' and 'return'
Style/ReturnNil:
Enabled: true
# This cop checks for the use of strings as keys in hashes. The use of symbols is preferred instead
Style/StringHashKeys:
Enabled: true
Style/MethodCallWithArgsParentheses:
Enabled: true
Exclude:
- 'spec/**/*'
- 'config/**/*'
- 'config.ru'
IgnoredMethods:
- load
- puts
- raise
- redirect_to
- render_to_string
- redirect_back
- render
- respond_with
- render_with_message
- respond_with_errors
- head
- respond_as_html
- respond_as_json
- respond_as_paginated_json
- require
- acts_as_token_authentication_handler_for
- require_relative
- javascript_include_tag
- stylesheet_link_tag
- render_wizard
- redirect_back
- send_data
# Enforcing the names of variables? To single letter ones? Just no.
Style/SingleLineBlockParams:
Enabled: false
# Check with yard instead.
Style/Documentation:
Enabled: false
# Style preference
Style/MethodDefParentheses:
Enabled: false
# Frozen Literals
Style/FrozenStringLiteralComment:
EnforcedStyle: always
# Quotes
Style/StringLiterals:
EnforcedStyle: single_quotes
# Allow us to use `alias_method` in class body
Style/Alias:
EnforcedStyle: prefer_alias_method
# Allow us to use empty `case`
Style/EmptyCaseCondition:
Enabled: false
# Prefer `call` over `.()` shortcut
Style/LambdaCall:
EnforcedStyle: call
# Prefer `%r{}` over `//`. It better plays with slashes
Style/RegexpLiteral:
EnforcedStyle: percent_r
# Wrap complex conditions in ternary expressions with parentheses
Style/TernaryParentheses:
EnforcedStyle: require_parentheses_when_complex