-
Notifications
You must be signed in to change notification settings - Fork 0
/
.rubocop.yml
411 lines (364 loc) · 11.2 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
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
# Up to date as of v0.49.1
# See https://github.com/robkilby/styleguides for original.
# If a cop is not referenced here, the defaults from Rubocop will be used.
AllCops:
Exclude:
- '**/db/schema.rb'
- '**/tmp/**/*'
- '**/vendor/**/*'
DisplayCopNames: true
DisplayStyleGuide: true
EnabledByDefault: true
ExtraDetails: true
UseCache: true
TargetRubyVersion: 2.4
TargetRailsVersion: 5.0
# Always use alias_method when aliasing methods of modules, classes, or singleton classes at runtime, as the lexical
# scope of alias leads to unpredictability in these cases.
Style/Alias:
EnforcedStyle: prefer_alias_method
# Checks if usage of %() or %Q() matches configuration.
#
# EnforcedStyle: percent_q - enforces use of %Q().
Style/BarePercentLiterals:
EnforcedStyle: percent_q
# Checks the style of children definitions at classes and modules. Basically there are two different styles:
#
# EnforcedStyle:
# nested - have each child on its own line
# class Foo
# class Bar
# end
# end
#
# compact (allowed for specs only) - combine definitions as much as possible
# class Foo::Bar
# end
Style/ClassAndModuleChildren:
Exclude:
- '**/spec/**/*'
- '**/test/**/*'
# Mapping from undesired method to desired method e.g. to use `detect` over `find`.
Style/CollectionMethods:
PreferredMethods:
collect: 'map'
collect!: 'map!'
inject: 'reduce'
detect: 'detect'
find_all: 'select'
# This cop checks that a copyright notice was given in each source file.
Style/Copyright:
Enabled: false
# This cop checks for missing top-level documentation of classes and modules. Classes with no body are exempt from the
# check and so are namespace modules - modules that have nothing in their bodies except classes, other modules, or
# constant definitions.
#
# The documentation requirement is annulled if the class or module has a "#:nodoc:" comment next to it. Likewise,
# "#:nodoc: all" does the same for all its children.
Style/Documentation:
Exclude:
- '**/config/**/*.rb'
- '**/db/migrate/*.rb'
- '**/spec/**/*'
- '**/test/**/*'
# This cop checks for missing documentation comments for all methods.
#
# The documentation requirement is annulled if the method has a "#:nodoc:" comment next to it.
Style/DocumentationMethod:
RequireForNonPublicMethods: true
Exclude:
- '**/config/**/*.rb'
- '**/db/migrate/*.rb'
- '**/spec/**/*'
- '**/test/**/*'
# Warn on empty else statements
#
# EnforcedStyle: empty - only return an error for a completely empty else clause as sometimes it may be necessary to
# return `nil` from an else branch.
Style/EmptyElse:
EnforcedStyle: empty
# Checks for the formatting of empty method definitions.
#
# EnforcedStyle: expanded - only return an error if the end is on the same line as the def.
#
# def foo(bar)
# end
Style/EmptyMethod:
EnforcedStyle: expanded
Exclude:
- '**/spec/**/*'
- '**/test/**/*'
# Checks whether the source file has a utf-8 encoding comment or not.
#
# EnforcedStyle: when_needed - checks the contents of the file before issuing an error.
Style/Encoding:
EnforcedStyle: when_needed
# Checks for if and unless statements that would fit on one line if written as a modifier if/unless.
#
# Triggers an warning for if/unless statements that would be under 120 characters.
Style/IfUnlessModifier:
MaxLineLength: 120
# This cop checks for trailing inline comments.
Style/InlineComment:
Enabled: false
# This cop checks for usages of not (`not` or `!`) called on a method when an inverse of that method can be used
# instead.
Style/InverseMethods:
InverseMethods:
:any?: :none?
:even?: :odd?
:==: :!=
:=~: :!~
:<: :>=
:>: :<=
:present?: :blank?,
:include?: :exclude?
# Checks for `if` / `case` expressions that do not have an `else` branch.
#
# Only configured to check for `case` statements. It's best practice to always provide a default for `case` statements.
Style/MissingElse:
EnforcedStyle: case
# TODO: This cop is disabled until a bug is patched on v0.48.0 where it flags setters.
Style/MethodCallWithArgsParentheses:
Enabled: false
# Use `next` to skip iteration instead of a condition at the end.
#
# # bad
# [1, 2].each do |a|
# if a == 1 do
# puts a
# end
# end
#
# # good
# [1, 2].each do |a|
# next unless a == 1
#
# puts a
# end
Style/Next:
EnforcedStyle: always
# This cop checks for redundant `return` expressions. Allows parallel return statments such as `return x, y`
Style/RedundantReturn:
AllowMultipleReturnValues: true
# Checks for the presence of parentheses around ternary conditions.
#
# EnforcedStyle: require_parentheses_when_complex
#
# bad
# foo = (bar?) ? a : b
# foo = (bar.baz?) ? a : b
# foo = bar && baz ? a : b
#
# good
# foo = bar? ? a : b
# foo = bar.baz ? a : b
# foo = (bar && baz) ? a : b
Style/TernaryParentheses:
EnforcedStyle: require_parentheses_when_complex
# Checks that all numbered variables use the configured style for their numbering.
#
# EnforcedStyle: snake_case
#
# # bad
#
# variable1 = 1
#
# # good
#
# variable_1 = 1
Style/VariableNumber:
EnforcedStyle: snake_case
# Checks for while and until statements that would fit on one line if written as a modifier while/until.
Style/WhileUntilModifier:
MaxLineLength: 120
#################### Layout ################################
# Align the elements of a hash literal if they span more than one line.
#
# EnforcedHashRocketStyle: key - left alignment of keys.
# 'a' => 2
# 'bb' => 3
#
# EnforcedColonStyle: key - left alignment of keys.
# a: 0
# bb: 1
Layout/AlignHash:
EnforcedHashRocketStyle: key
EnforcedColonStyle: key
# Alignment of parameters in multi-line method calls.
#
# The `with_fixed_indentation` style aligns the following lines with one level of indentation relative to the start of
# the line with the method call.
#
# method_call(a,
# b)
Layout/AlignParameters:
EnforcedStyle: with_fixed_indentation
# Checks how the whens of a case expression are indented in relation to its end keyword.
#
# EnforcedStyle: end
#
# good
# kind = case year
# when 1850..1889
# 'Blues'
# when 1890..1909
# 'Ragtime'
# when 1910..1929
# 'New Orleans Jazz'
# when 1930..1939
# 'Swing'
# when 1940..1950
# 'Bebop'
# else
# 'Jazz'
# end
Layout/CaseIndentation:
EnforcedStyle: end
# Checks the indentation of the first element in an array literal.
#
# The value `consistent` means that the indentation of the first element shall always be relative to the first position
# of the line where the opening bracket is.
#
# array = [
# :value
# ]
# and_in_a_method_call([
# :no_difference
# ])
Layout/IndentArray:
EnforcedStyle: consistent
# Checks the indentation of the first key in a hash literal.
#
# The value `consistent` means that the indentation of the first key shall always be relative to the first position
# of the line where the opening brace is.
#
# hash = {
# key: :value
# }
# and_in_a_method_call({
# no: :difference
# })
Layout/IndentHash:
EnforcedStyle: consistent
# Checks that multiline assignments do not have a newline after the assignment operator.
#
# EnforcedStyle: same_line
#
# foo = if expression
# 'bar'
# end
Layout/MultilineAssignmentLayout:
EnforcedStyle: same_line
# Checks the indentation of the method name part in method calls that span more than one line.
#
# EnforcedStyle: indented
#
# Thing.a
# .b
# .c
Layout/MultilineMethodCallIndentation:
EnforcedStyle: indented
# Checks the indentation of the right hand side operand in binary operations that span more than one line.
#
# EnforcedStyle: indented
#
# if a &&
# b
# something
# end
Layout/MultilineOperationIndentation:
EnforcedStyle: indented
# This cop checks for spaces between -> and opening parameter brace in lambda literals.
#
# EnforcedStyle: require_space
#
# a = -> (x, y) { x + y }
Layout/SpaceInLambdaLiteral:
EnforcedStyle: require_space
#################### Metrics ################################
# Checks that the ABC size of methods is not higher than the configured maximum. The ABC size is based on assignments,
# branches (method calls), and conditions. See http://c2.com/cgi/wiki?AbcMetric.
Metrics/AbcSize:
Max: 22
# This cop checks if the length of a block exceeds some maximum value. Ignores comment-only lines.
Metrics/BlockLength:
Exclude:
- 'Rakefile'
- '**/*.rake'
- '**/routes.rb'
- '**/config/initializers/**/*.rb'
- '**/config/environments/**/*.rb'
- '**/spec/**/*'
- '**/test/**/*'
- '**/*.gemspec'
# Checks if the length a class exceeds some maximum value. Ignores comment-only lines.
Metrics/ClassLength:
Max: 150
# Checks that the cyclomatic complexity of methods is not higher than the configured maximum. The cyclomatic complexity
# is the number of linearly independent paths through a method. The algorithm counts decision points and adds one.
#
# An if statement (or unless or ?:) increases the complexity by one. An else branch does not, since it doesn't add a
# decision point. The && operator (or keyword and) can be converted to a nested if statement, and ||/or is shorthand for
# a sequence of ifs, so they also add one. Loops can be said to have an exit condition, so they add one.
Metrics/CyclomaticComplexity:
Max: 10
# Checks the length of lines in the source code.
Metrics/LineLength:
Max: 120
IgnoreCopDirectives: true
Exclude:
- '**/routes.rb'
- '**/config/initializers/**/*.rb'
- '**/config/environments/**/*.rb'
- '**/Gemfile'
# Checks if the length of a method exceeds some maximum value. Ignores comment-only lines.
Metrics/MethodLength:
Max: 20
# Checks if the length of a module exceeds some maximum value. Ignores comment-only lines.
Metrics/ModuleLength:
Max: 100
#################### Lint ################################
# Checks for assignments in the conditions of if/while/until.
Lint/AssignmentInCondition:
AllowSafeAssignment: false
# This cop checks whether the end keywords are aligned properly for do end blocks.
#
# EnforcedStyleAlignWith: start_of_line
#
# foo.bar
# .each do
# baz
# end
Lint/BlockAlignment:
EnforcedStyleAlignWith: start_of_line
# Checks whether the end keywords are aligned properly.
#
# EnforcedStyleAlignWith: variable - in assignments, `end` should be aligned with the start of the variable on the left
# hand side of `=`. In all other situations, `end` should still be aligned with the keyword.
#
# variable = if true
# end
Lint/EndAlignment:
EnforcedStyleAlignWith: variable
##################### Rails ##################################
# Checks for the correct use of `Date` methods, such as `Date.today`, `Date.current` etc.
#
# Using `Date.today` is dangerous, because it doesn't know anything about Rails time zone. You must use
# `Time.zone.today` instead.
#
# It also reports warnings when you are using the `to_time` method, because it doesn't know about Rails time zone
# either.
#
# EnforcedStyle: strict - the Date methods (`today`, `current`, `yesterday`, `tomorrow`) are prohibited and the usage
# of both `to_time` and `to_time_in_current_zone` is reported as warning.
Rails/Date:
EnforcedStyle: strict
# This cop checks for usages of `try` and `try!` where `&.` could be used instead.
Rails/SafeNavigation:
ConvertTry: true
# Checks for the use of Time methods without zone.
#
# EnforcedStyle: strict - only use of Time.zone is allowed.
Rails/TimeZone:
EnforcedStyle: strict