-
Notifications
You must be signed in to change notification settings - Fork 1
/
.rubocop.yml
511 lines (396 loc) · 14 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
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
# Defaults can be found here: https://github.com/bbatsov/rubocop/blob/master/config/default.yml
require:
- rubocop-rspec
- rubocop-rake
- rubocop-performance
AllCops:
TargetRubyVersion: 3.0
NewCops: enable
Style/MultilineBlockChain:
Enabled: false
Style/MultilineIfModifier:
Enabled: false
Style/TrailingCommaInArrayLiteral:
EnforcedStyleForMultiline: consistent_comma
Style/StderrPuts:
Enabled: false
Style/RegexpLiteral:
Enabled: true
EnforcedStyle: slashes
RSpec/ExampleLength:
Enabled: false
RSpec/RepeatedExample:
Enabled: false
Style/BlockDelimiters:
Enabled: true
EnforcedStyle: always_braces
Exclude:
- spec/*.rb
- Guardfile
- Rakefile
- danger-*.gemspec
Metrics/ModuleLength:
Enabled: true
Exclude:
- spec/*.rb
Layout/ClassStructure:
Enabled: true
Layout/MultilineArrayLineBreaks:
Enabled: true
Layout/MultilineAssignmentLayout:
Enabled: true
EnforcedStyle: same_line
Layout/MultilineHashKeyLineBreaks:
Enabled: true
Layout/MultilineMethodArgumentLineBreaks:
Enabled: true
Layout/MultilineMethodParameterLineBreaks:
Enabled: true
Layout/SingleLineBlockChain:
Enabled: true
Style/AutoResourceCleanup:
Enabled: true
Style/CollectionMethods:
Enabled: true
Style/InvertibleUnlessCondition:
Enabled: true
Style/MethodCallWithArgsParentheses:
Enabled: true
Exclude:
- spec/*.rb
Style/MethodCalledOnDoEndBlock:
Enabled: true
Style/RequireOrder:
Enabled: true
Style/StringMethods:
Enabled: true
Style/TopLevelMethodDefinition:
Enabled: true
Exclude:
- spec/*.rb
Style/StringLiterals:
EnforcedStyle: double_quotes
Enabled: true
# kind_of? is a good way to check a type
Style/ClassCheck:
EnforcedStyle: kind_of?
# specs sometimes have useless assignments, which is fine
Lint/UselessAssignment:
Exclude:
- "**/spec/**/*"
Layout/FirstHashElementIndentation:
Enabled: true
Layout/HashAlignment:
Enabled: true
# HoundCI doesn't like this rule
Layout/DotPosition:
Enabled: false
# We allow !! as it's an easy way to convert to boolean
Style/DoubleNegation:
Enabled: false
# Cop supports --auto-correct.
Lint/UnusedBlockArgument:
Enabled: true
# We want to allow class Fastlane::Class
Style/ClassAndModuleChildren:
Enabled: false
Metrics/AbcSize:
Max: 60
# The %w might be confusing for new users
Style/WordArray:
MinSize: 19
# raise and fail are both okay
Style/SignalException:
Enabled: false
# Having if in the same line might not always be good
Style/IfUnlessModifier:
Enabled: false
Style/AndOr:
Enabled: true
# Configuration parameters: CountComments.
Metrics/ClassLength:
Max: 350
Metrics/CyclomaticComplexity:
Max: 17
# Configuration parameters: AllowURI, URISchemes.
Layout/LineLength:
Max: 370
# Configuration parameters: CountKeywordArgs.
Metrics/ParameterLists:
Max: 10
Metrics/PerceivedComplexity:
Max: 18
Style/GuardClause:
Enabled: true
Style/ConditionalAssignment:
Enabled: true
# Better to have too much self than missing a self
Style/RedundantSelf:
Enabled: false
Metrics/MethodLength:
Max: 60
# We're not there yet
Style/Documentation:
Enabled: false
# Adds complexity
Style/IfInsideElse:
Enabled: false
# danger specific
Style/BlockComments:
Enabled: false
Layout/MultilineMethodCallIndentation:
EnforcedStyle: indented
# FIXME: 25
Metrics/BlockLength:
Max: 345
Exclude:
- "**/*_spec.rb"
Style/MixinGrouping:
Enabled: true
Naming/FileName:
Enabled: false
Layout/HeredocIndentation:
Enabled: false
Style/SpecialGlobalVars:
Enabled: false
Style/PercentLiteralDelimiters:
PreferredDelimiters:
"%": ()
"%i": ()
"%q": ()
"%Q": ()
"%r": "{}"
"%s": ()
"%w": ()
"%W": ()
"%x": ()
Security/YAMLLoad:
Enabled: false
Gemspec/DevelopmentDependencies:
Enabled: false
# This is the default configuration file.
Performance:
Enabled: true
Performance/AncestorsInclude:
Description: "Use `A <= B` instead of `A.ancestors.include?(B)`."
Enabled: true
Performance/ArraySemiInfiniteRangeSlice:
Description: "Identifies places where slicing arrays with semi-infinite ranges can be replaced by `Array#take` and `Array#drop`."
# This cop was created due to a mistake in microbenchmark.
# Refer https://github.com/rubocop/rubocop-performance/pull/175#issuecomment-731892717
Enabled: true
Performance/BigDecimalWithNumericArgument:
Description: "Convert numeric literal to string and pass it to `BigDecimal`."
Enabled: true
Performance/BindCall:
Description: "Use `bind_call(obj, args, ...)` instead of `bind(obj).call(args, ...)`."
Enabled: true
Performance/BlockGivenWithExplicitBlock:
Description: "Check block argument explicitly instead of using `block_given?`."
Enabled: true
Performance/Caller:
Description: >-
Use `caller(n..n)` instead of `caller`.
Enabled: true
Performance/CaseWhenSplat:
Description: >-
Reordering `when` conditions with a splat to the end
of the `when` branches can improve performance.
Enabled: true
Performance/Casecmp:
Description: >-
Use `casecmp` rather than `downcase ==`, `upcase ==`, `== downcase`, or `== upcase`..
Reference: "https://github.com/fastruby/fast-ruby#stringcasecmp-vs--stringcasecmp-vs-stringdowncase---code"
Enabled: true
Performance/ChainArrayAllocation:
Description: >-
Instead of chaining array methods that allocate new arrays, mutate an
existing array.
Reference: "https://twitter.com/schneems/status/1034123879978029057"
Enabled: true
Exclude:
- spec/*.rb
Performance/CollectionLiteralInLoop:
Description: "Extract Array and Hash literals outside of loops into local variables or constants."
Enabled: true
Performance/CompareWithBlock:
Description: "Use `sort_by(&:foo)` instead of `sort { |a, b| a.foo <=> b.foo }`."
Enabled: true
Performance/ConcurrentMonotonicTime:
Description: "Use `Process.clock_gettime(Process::CLOCK_MONOTONIC)` instead of `Concurrent.monotonic_time`."
Reference: "https://github.com/rails/rails/pull/43502"
Enabled: true
Performance/ConstantRegexp:
Description: "Finds regular expressions with dynamic components that are all constants."
Enabled: true
Performance/Count:
Description: >-
Use `count` instead of `{select,find_all,filter,reject}...{size,count,length}`.
# This cop has known compatibility issues with `ActiveRecord` and other
# frameworks. ActiveRecord's `count` ignores the block that is passed to it.
# For more information, see the documentation in the cop itself.
Enabled: true
Performance/DeletePrefix:
Description: "Use `delete_prefix` instead of `gsub`."
Enabled: true
Performance/DeleteSuffix:
Description: "Use `delete_suffix` instead of `gsub`."
Enabled: true
Performance/Detect:
Description: >-
Use `detect` instead of `select.first`, `find_all.first`, `filter.first`,
`select.last`, `find_all.last`, and `filter.last`.
Reference: "https://github.com/fastruby/fast-ruby#enumerabledetect-vs-enumerableselectfirst-code"
# This cop has known compatibility issues with `ActiveRecord` and other
# frameworks. `ActiveRecord` does not implement a `detect` method and `find`
# has its own meaning. Correcting `ActiveRecord` methods with this cop
# should be considered unsafe.
Enabled: true
Performance/DoubleStartEndWith:
Description: >-
Use `str.{start,end}_with?(x, ..., y, ...)`
instead of `str.{start,end}_with?(x, ...) || str.{start,end}_with?(y, ...)`.
Enabled: true
Performance/EndWith:
Description: "Use `end_with?` instead of a regex match anchored to the end of a string."
Reference: "https://github.com/fastruby/fast-ruby#stringmatch-vs-stringmatch-vs-stringstart_withstringend_with-code-start-code-end"
# This will change to a new method call which isn't guaranteed to be on the
# object. Switching these methods has to be done with knowledge of the types
# of the variables which rubocop doesn't have.
Enabled: true
Performance/FixedSize:
Description: "Do not compute the size of statically sized objects except in constants."
Enabled: true
Performance/FlatMap:
Description: >-
Use `Enumerable#flat_map`
instead of `Enumerable#map...Array#flatten(1)`
or `Enumerable#collect..Array#flatten(1)`.
Reference: "https://github.com/fastruby/fast-ruby#enumerablemaparrayflatten-vs-enumerableflat_map-code"
Enabled: true
EnabledForFlattenWithoutParams: false
# If enabled, this cop will warn about usages of
# `flatten` being called without any parameters.
# This can be dangerous since `flat_map` will only flatten 1 level, and
# `flatten` without any parameters can flatten multiple levels.
Performance/InefficientHashSearch:
Description: "Use `key?` or `value?` instead of `keys.include?` or `values.include?`."
Reference: "https://github.com/fastruby/fast-ruby#hashkey-instead-of-hashkeysinclude-code"
Enabled: true
Performance/IoReadlines:
Description: "Use `IO.each_line` (`IO#each_line`) instead of `IO.readlines` (`IO#readlines`)."
Reference: "https://docs.gitlab.com/ee/development/performance.html#reading-from-files-and-other-data-sources"
Enabled: true
Performance/MapCompact:
Description: "Use `filter_map` instead of `collection.map(&:do_something).compact`."
Enabled: true
Performance/MapMethodChain:
Description: "Checks if the `map` method is used in a chain."
Enabled: true
Performance/MethodObjectAsBlock:
Description: "Use block explicitly instead of block-passing a method object."
Reference: "https://github.com/fastruby/fast-ruby#normal-way-to-apply-method-vs-method-code"
Enabled: true
Performance/OpenStruct:
Description: "Use `Struct` instead of `OpenStruct`."
Enabled: true
Performance/RangeInclude:
Description: "Use `Range#cover?` instead of `Range#include?` (or `Range#member?`)."
Reference: "https://github.com/fastruby/fast-ruby#cover-vs-include-code"
Enabled: true
Performance/RedundantBlockCall:
Description: "Use `yield` instead of `block.call`."
Reference: "https://github.com/fastruby/fast-ruby#proccall-and-block-arguments-vs-yieldcode"
Enabled: true
Performance/RedundantEqualityComparisonBlock:
Description: >-
Checks for uses `Enumerable#all?`, `Enumerable#any?`, `Enumerable#one?`,
or `Enumerable#none?` are compared with `===` or similar methods in block.
Reference: "https://github.com/rails/rails/pull/41363"
Enabled: true
Performance/RedundantMatch:
Description: >-
Use `=~` instead of `String#match` or `Regexp#match` in a context where the
returned `MatchData` is not needed.
Enabled: true
Performance/RedundantMerge:
Description: "Use Hash#[]=, rather than Hash#merge! with a single key-value pair."
Reference: "https://github.com/fastruby/fast-ruby#hashmerge-vs-hash-code"
Enabled: true
# Max number of key-value pairs to consider an offense
MaxKeyValuePairs: 2
Performance/RedundantSortBlock:
Description: "Use `sort` instead of `sort { |a, b| a <=> b }`."
Enabled: true
Performance/RedundantSplitRegexpArgument:
Description: "Identifies places where `split` argument can be replaced from a deterministic regexp to a string."
Enabled: true
Performance/RedundantStringChars:
Description: "Checks for redundant `String#chars`."
Enabled: true
Performance/RegexpMatch:
Description: >-
Use `match?` instead of `Regexp#match`, `String#match`, `Symbol#match`,
`Regexp#===`, or `=~` when `MatchData` is not used.
Reference: "https://github.com/fastruby/fast-ruby#regexp-vs-regexpmatch-vs-regexpmatch-vs-stringmatch-vs-string-vs-stringmatch-code-"
Enabled: true
Performance/ReverseEach:
Description: "Use `reverse_each` instead of `reverse.each`."
Reference: "https://github.com/fastruby/fast-ruby#enumerablereverseeach-vs-enumerablereverse_each-code"
Enabled: true
Performance/ReverseFirst:
Description: "Use `last(n).reverse` instead of `reverse.first(n)`."
Enabled: true
Performance/SelectMap:
Description: "Use `filter_map` instead of `ary.select(&:foo).map(&:bar)`."
Enabled: true
Performance/Size:
Description: >-
Use `size` instead of `count` for counting
the number of elements in `Array` and `Hash`.
Reference: "https://github.com/fastruby/fast-ruby#arraylength-vs-arraysize-vs-arraycount-code"
Enabled: true
Performance/SortReverse:
Description: "Use `sort.reverse` instead of `sort { |a, b| b <=> a }`."
Enabled: true
Performance/Squeeze:
Description: "Use `squeeze('a')` instead of `gsub(/a+/, 'a')`."
Reference: "https://github.com/fastruby/fast-ruby#remove-extra-spaces-or-other-contiguous-characters-code"
Enabled: true
Performance/StartWith:
Description: "Use `start_with?` instead of a regex match anchored to the beginning of a string."
Reference: "https://github.com/fastruby/fast-ruby#stringmatch-vs-stringmatch-vs-stringstart_withstringend_with-code-start-code-end"
# This will change to a new method call which isn't guaranteed to be on the
# object. Switching these methods has to be done with knowledge of the types
# of the variables which rubocop doesn't have.
Enabled: true
SafeMultiline: true
Performance/StringIdentifierArgument:
Description: "Use symbol identifier argument instead of string identifier argument."
Enabled: true
Performance/StringInclude:
Description: "Use `String#include?` instead of a regex match with literal-only pattern."
Enabled: true
Performance/StringReplacement:
Description: >-
Use `tr` instead of `gsub` when you are replacing the same
number of characters. Use `delete` instead of `gsub` when
you are deleting characters.
Reference: "https://github.com/fastruby/fast-ruby#stringgsub-vs-stringtr-code"
Enabled: true
Performance/Sum:
Description: "Use `sum` instead of a custom array summation."
Reference: "https://blog.bigbinary.com/2016/11/02/ruby-2-4-introduces-enumerable-sum.html"
Enabled: true
Performance/TimesMap:
Description: "Checks for .times.map calls."
Enabled: true
# See https://github.com/rubocop/rubocop/issues/4658
Performance/UnfreezeString:
Description: "Use unary plus to get an unfrozen string literal."
Enabled: true
Performance/UriDefaultParser:
Description: "Use `URI::DEFAULT_PARSER` instead of `URI::Parser.new`."
Enabled: true
RSpec/AnyInstance:
Enabled: false