-
Notifications
You must be signed in to change notification settings - Fork 1
/
.rubocop.yml
384 lines (338 loc) · 10.4 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
# Up to date as of v0.54.0
# If a cop is not referenced here, the defaults from Rubocop will be used.
AllCops:
Exclude:
- '**/db/**/*'
- '**/tmp/**/*'
- '**/vendor/**/*'
- '**/script/**/*'
DisplayStyleGuide: true
ExtraDetails: true
UseCache: true
MaxFilesInCache: 50000
TargetRubyVersion: 2.3
TargetRailsVersion: 4.2
# 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 for cases when you could use a block accepting version of a method that does automatic resource cleanup.
#
# # bad
# f = File.open('file')
#
# # good
# f = File.open('file') do
# ...
# end
Style/AutoResourceCleanup:
Enabled: true
# 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/**/*'
# Mapping from undesired method to desired method e.g. to use `detect` over `find`.
Style/CollectionMethods:
Enabled: true
PreferredMethods:
collect: 'map'
collect!: 'map!'
inject: 'reduce'
detect: 'detect'
find_all: 'select'
# 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:
- '**/spec/**/*'
# 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.
#
# bad
# def foo(bar); end
#
# good
# def foo(bar)
# end
Style/EmptyMethod:
EnforcedStyle: expanded
Exclude:
- '**/spec/**/*'
# Checks for methods called on a do...end block. The point of this check is that it's easy to miss the call tacked on
# to the block when reading code.
Style/MethodCalledOnDoEndBlock:
Enabled: true
# 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:
Enabled: true
EnforcedStyle: case
# 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
# Checks for options hashes and discourages them if the current Ruby version supports keyword arguments.
Style/OptionHash:
Enabled: true
Style/PercentLiteralDelimiters:
PreferredDelimiters:
default: ()
'%i': '()'
'%I': '()'
'%w': '()'
'%W': '()'
# Checks for the use of the send method. Prefers use of `__send__` and `public_send` over `send`.
Style/Send:
Enabled: true
# Enforces the use of consistent method names from the String class. So far it enforces use of `to_sym` over `intern`.
Style/StringMethods:
Enabled: true
# Check for array literals made up of symbols that are not using the %i() syntax.
Style/SymbolArray:
Enabled: true
EnforcedStyle: brackets
# 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
#################### 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 whether the end keywords are aligned properly.
#
# AlignWith: 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
Layout/EndAlignment:
EnforcedStyleAlignWith: variable
# Checks for a line break before the first element in a multi-line array.
Layout/FirstArrayElementLineBreak:
Enabled: true
# Checks for a line break before the first element in a multi-line hash.
Layout/FirstHashElementLineBreak:
Enabled: true
# Checks for a line break before the first argument in a multi-line method call.
Layout/FirstMethodArgumentLineBreak:
Enabled: true
# Checks for a line break before the first parameter in a multi-line method parameter definition.
Layout/FirstMethodParameterLineBreak:
Enabled: true
# 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/IndentFirstArrayElement:
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/IndentFirstHashElement:
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:
Enabled: true
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
#################### Naming ##########################
# Checks that all numbered variables use the configured style for their numbering.
#
# EnforcedStyle: snake_case
#
# # bad
#
# variable1 = 1
#
# # good
#
# variable_1 = 1
Naming/VariableNumber:
EnforcedStyle: snake_case
#################### 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:
- '**/routes.rb'
- '**/config/initializers/**/*.rb'
- '**/config/environments/**/*.rb'
- '**/spec/**/*'
- '**/*.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
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
Exclude:
- '**/spec/**/*'
# Checks if the length of a module exceeds some maximum value. Ignores comment-only lines.
Metrics/ModuleLength:
Max: 100
# Tries to produce a complexity score that's a measure of the complexity the reader experiences when looking at a
# method. For that reason it considers `when` nodes as something that doesn't add as much complexity as an `if` or a
# `&&`. Except if it's one of those special `case`/`when` constructs where there's no expression after `case`. Then
# the cop treats it as an `if`/`elsif`/`elsif`... and lets all the `when` nodes count. In contrast to
# CyclomaticComplexity, it considers `else` nodes as adding complexity.
Metrics/PerceivedComplexity:
Max: 7
#################### Lint ################################
# Checks for assignments in the conditions of if/while/until.
Lint/AssignmentInCondition:
AllowSafeAssignment: false
# Checks for interpolated literals.
#
# "result is #{10}"
Lint/LiteralInInterpolation:
AutoCorrect: true