-
Notifications
You must be signed in to change notification settings - Fork 1
/
.rubocop_1.x.yml
1320 lines (1235 loc) · 30.1 KB
/
.rubocop_1.x.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
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# 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.4
TargetRailsVersion: 4.2
#################### Style ################################
# This cop checks for grouping of accessors in `class` and `module`
# bodies. By default it enforces accessors to be placed in grouped
# declarations, but it can be configured to enforce separating them
# in multiple declarations.
#
# NOTE: `Sorbet` is not compatible with “grouped” style. Consider “separated” style or disabling this cop.
#
#
# EnforcedStyle: grouped (default)
#
# # bad
# class Foo
# attr_reader :bar
# attr_reader :baz
# end
#
# # good
# class Foo
# attr_reader :bar, :baz
# end
Style/AccessorGrouping:
Enabled: true
# This cop enforces the use of `Array()` instead of explicit `Array`
# check or `[*var]`.
#
# The cop is disabled by default due to safety concerns.
#
# # bad
# paths = [paths] unless paths.is_a?(Array)
# paths.each { |path| do_something(path) }
#
# # bad (always creates a new Array instance)
# [*paths].each { |path| do_something(path) }
#
# # good (and a bit more readable)
# Array(paths).each { |path| do_something(path) }
Style/ArrayCoercion:
Enabled: true
# This cop checks for places where `attr_reader` and `attr_writer` for the same method can be combined into single `attr_accessor`.
#
# # bad
# class Foo
# attr_reader :bar
# attr_writer :bar
# end
#
# # good
# class Foo
# attr_accessor :bar
# end
Style/BisectedAttrAccessor:
Enabled: true
# This cop identifies places where `if-elsif` constructions can be replaced with `case-when`.
#
# # bad
# if status == :active
# perform_action
# elsif status == :inactive || status == :hibernating
# check_timeout
# else
# final_action
# end
#
# # good
# case status
# when :active
# perform_action
# when :inactive, :hibernating
# check_timeout
# else
# final_action
# end
Style/CaseLikeIf:
Enabled: true
# This cop enforces the use of explicit block argument to avoid
# writing block literal that just passes its arguments to another
# block.
#
# NOTE: This cop only registers an offense if the block args match
# the yield args exactly.
#
# # bad
# def with_tmp_dir
# Dir.mktmpdir do |tmp_dir|
# Dir.chdir(tmp_dir) { |dir| yield dir } # block just passes arguments
# end
# end
#
# # bad
# def nine_times
# 9.times { yield }
# end
#
# # good
# def with_tmp_dir(&block)
# Dir.mktmpdir do |tmp_dir|
# Dir.chdir(tmp_dir, &block)
# end
# end
#
# with_tmp_dir do |dir|
# puts "dir is accessible as a parameter and pwd is set: #{dir}"
# end
#
# # good
# def nine_times(&block)
# 9.times(&block)
# end
Style/ExplicitBlockArgument:
Enabled: true
# This cop enforces consistency when using exponential notation for
# numbers in the code (eg 1.2e4). Different styles are supported:
#
# `scientific` which enforces a mantissa between 1 (inclusive) and 10
# (exclusive).
#
# `engineering` which enforces the exponent to be a multiple of 3 and
# the mantissa to be between 0.1 (inclusive) and 10 (exclusive).
#
# `integral` which enforces the mantissa to always be a whole number
# without trailing zeroes.
#
#
# EnforcedStyle: scientific (default)
#
# # Enforces a mantissa between 1 (inclusive) and 10 (exclusive).
#
# # bad
# 10e6
# 0.3e4
# 11.7e5
# 3.14e0
#
# # good
# 1e7
# 3e3
# 1.17e6
# 3.14
Style/ExponentialNotation:
Enabled: true
# This cop enforces the use of `$stdout/$stderr/$stdin` instead of
# `STDOUT/STDERR/STDIN`. `STDOUT/STDERR/STDIN` are constants, and
# while you can actually reassign (possibly to redirect some stream)
# constants in Ruby, you'll get an interpreter warning if you do so.
#
# # bad
# STDOUT.puts('hello')
#
# hash = { out: STDOUT, key: value }
#
# def m(out = STDOUT)
# out.puts('hello')
# end
#
# # good
# $stdout.puts('hello')
#
# hash = { out: $stdout, key: value }
#
# def m(out = $stdout)
# out.puts('hello')
# end
Style/GlobalStdStream:
Enabled: true
# Checks for presence or absence of braces around hash literal as a
# last array item depending on configuration.
#
# NOTE: This cop will ignore arrays where all items are hashes,
# regardless of EnforcedStyle.
#
# EnforcedStyle: braces (default)
#
# # bad
# [1, 2, one: 1, two: 2]
#
# # good
# [1, 2, { one: 1, two: 2 }]
#
# # good
# [{ one: 1 }, { two: 2 }]
Style/HashAsLastArrayItem:
Enabled: true
# This cop checks for uses of `each_key` and `each_value` Hash
# methods.
#
# NOTE: If you have an array of two-element arrays, you can put
#
# ```
# parentheses around the block arguments to indicate that you're not
# working with a hash, and suppress RuboCop offenses.
# ```
#
# # bad
# hash.keys.each { |k| p k }
# hash.values.each { |v| p v }
#
# # good
# hash.each_key { |k| p k }
# hash.each_value { |v| p v }
Style/HashEachMethods:
Enabled: true
# This cop checks for places where `case-when` represents a simple
# 1:1 mapping and can be replaced with a hash lookup.
#
# MinBranchesCount: 3 (default)
#
# # bad
# case country
# when 'europe'
# 'http://eu.example.com'
# when 'america'
# 'http://us.example.com'
# when 'australia'
# 'http://au.example.com'
# end
#
# # good
# SITES = {
# 'europe' => 'http://eu.example.com',
# 'america' => 'http://us.example.com',
# 'australia' => 'http://au.example.com'
# }
# SITES[country]
Style/HashLikeCase:
Enabled: true
# This cop looks for uses of
# `_.each_with_object({}) …`, `_.map ….to_h`, and `Hash[_.map …]`
# that are actually just transforming the keys of a hash, and tries
# to use a simpler & faster call to `transform_keys` instead.
#
# # bad
# {a: 1, b: 2}.each_with_object({}) { |(k, v), h| h[foo(k)] = v }
# Hash[{a: 1, b: 2}.collect { |k, v| [foo(k), v] }]
# {a: 1, b: 2}.map { |k, v| [k.to_s, v] }.to_h
# {a: 1, b: 2}.to_h { |k, v| [k.to_s, v] }
#
# # good
# {a: 1, b: 2}.transform_keys { |k| foo(k) }
# {a: 1, b: 2}.transform_keys { |k| k.to_s }
Style/HashTransformKeys:
Enabled: true
# This cop looks for uses of
# `_.each_with_object({}) …`, `_.map ….to_h`, and `Hash[_.map …]`
# that are actually just transforming the values of a hash, and tries
# to use a simpler & faster call to `transform_values` instead.
#
# # bad
# {a: 1, b: 2}.each_with_object({}) { |(k, v), h| h[k] = foo(v) }
# Hash[{a: 1, b: 2}.collect { |k, v| [k, foo(v)] }]
# {a: 1, b: 2}.map { |k, v| [k, v * v] }.to_h
# {a: 1, b: 2}.to_h { |k, v| [k, v * v] }
#
# # good
# {a: 1, b: 2}.transform_values { |v| foo(v) }
# {a: 1, b: 2}.transform_values { |v| v * v }
Style/HashTransformValues:
Enabled: true
# This cop checks for places where keyword arguments can be used
# instead of boolean arguments when defining methods.
# `respond_to_missing?` method is allowed by default. These are
# customizable with `AllowedMethods` option.
#
# # bad
# def some_method(bar = false)
# puts bar
# end
#
# # bad - common hack before keyword args were introduced
# def some_method(options = {})
# bar = options.fetch(:bar, false)
# puts bar
# end
#
# # good
# def some_method(bar: false)
# puts bar
# end
Style/OptionalBooleanParameter:
Enabled: true
# This cop checks for redundant assignment before returning.
#
# # bad
# def test
# x = foo
# x
# end
#
# # bad
# def test
# if x
# z = foo
# z
# elsif y
# z = bar
# z
# end
# end
#
# # good
# def test
# foo
# end
#
# # good
# def test
# if x
# foo
# elsif y
# bar
# end
# end
Style/RedundantAssignment:
Enabled: true
# This cop identifies places where `fetch(key) { value }` can be replaced by `fetch(key, value)`.
#
# In such cases `fetch(key, value)` method is faster than `fetch(key) { value }`.
#
# SafeForConstants: true
# # bad
# ENV.fetch(:key) { VALUE }
#
# # good
# ENV.fetch(:key, VALUE)
Style/RedundantFetchBlock:
Enabled: true
# This cop checks for the presence of superfluous `.rb` extension in the filename provided to `require` and `require_relative`.
#
# Note: If the extension is omitted, Ruby tries adding '.rb', '.so',
#
# ```
# and so on to the name until found. If the file named cannot be found,
# a `LoadError` will be raised.
# There is an edge case where `foo.so` file is loaded instead of a `LoadError`
# if `foo.so` file exists when `require 'foo.rb'` will be changed to `require 'foo'`,
# but that seems harmless.
# ```
#
# # bad
# require 'foo.rb'
# require_relative '../foo.rb'
#
# # good
# require 'foo'
# require 'foo.so'
# require_relative '../foo'
# require_relative '../foo.so'
Style/RedundantFileExtensionInRequire:
Enabled: true
# This cop checks for unnecessary single-element Regexp character classes.
#
# # bad
# r = /[x]/
#
# # good
# r = /x/
#
# # bad
# r = /[\s]/
#
# # good
# r = /\s/
#
# # bad
# r = %r{/[b]}
#
# # good
# r = %r{/b}
#
# # good
# r = /[ab]/
Style/RedundantRegexpCharacterClass:
Enabled: true
# This cop checks for redundant escapes inside Regexp literals.
#
# # bad
# %r{foo\/bar}
#
# # good
# %r{foo/bar}
#
# # good
# /foo\/bar/
#
# # good
# %r/foo\/bar/
#
# # good
# %r!foo\!bar!
#
# # bad
# /a\-b/
#
# # good
# /a-b/
#
# # bad
# /[\+\-]\d/
#
# # good
# /[+\-]\d/
Style/RedundantRegexpEscape:
Enabled: true
# Sometimes using dig method ends up with just a single argument.
# In such cases, dig should be replaced with [].
#
# # bad
# { key: 'value' }.dig(:key)
# [1, 2, 3].dig(0)
#
# # good
# { key: 'value' }[:key]
# [1, 2, 3][0]
#
# # good
# { key1: { key2: 'value' } }.dig(:key1, :key2)
# [1, [2, [3]]].dig(1, 1)
#
# # good
# keys = %i[key1 key2]
# { key1: { key2: 'value' } }.dig(*keys)
Style/SingleArgumentDig:
Enabled: true
# This cop checks that arrays are sliced with endless ranges instead of `ary` on Ruby 2.6+.
#
# # bad
# items[1..-1]
#
# # good
# items[1..]
Style/SlicingWithRange:
Enabled: true
# This cop checks for places where string concatenation can be
# replaced with string interpolation.
#
# The cop can autocorrect simple cases but will skip autocorrecting
# more complex cases where the resulting code would be harder to
# read. In those cases, it might be useful to extract statements to
# local variables or methods which you can then interpolate in a
# string.
#
# NOTE: When concatenation between two strings is broken over multiple
# lines, this cop does not register an offense; instead,
# `Style/LineEndConcatenation` will pick up the offense if enabled.
#
# Two modes are supported:
#
# `aggressive` style checks and corrects all occurrences of `+` where
#
# either the left or right side of `+` is a string literal.
#
# `conservative` style on the other hand, checks and corrects only if
#
# left side (receiver of `+` method call) is a string literal. This
# is useful when the receiver is some expression that returns string
# like `Pathname` instead of a string literal.
#
#
# Mode: aggressive (default)
# # bad
# email_with_name = user.name + ' <' + user.email + '>'
# Pathname.new('/') + 'test'
#
# # good
# email_with_name = "#{user.name} <#{user.email}>"
# email_with_name = format('%s <%s>', user.name, user.email)
# "#{Pathname.new('/')}test"
#
# # accepted, line-end concatenation
# name = 'First' +
# 'Last'
Style/StringConcatenation:
Enabled: true
# 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 ################################
# Checks for a newline after an attribute accessor or a group of them
# . `alias` syntax and `alias_method`, `public`, `protected`, and
# `private` methods are allowed by default. These are customizable
# with `AllowAliasSyntax` and `AllowedMethods` options.
#
# # bad
# attr_accessor :foo
# def do_something
# end
#
# # good
# attr_accessor :foo
#
# def do_something
# end
#
# # good
# attr_accessor :foo
# attr_reader :bar
# attr_writer :baz
# attr :qux
#
# def do_something
# end
#
# AllowAliasSyntax: true (default)
#
# # good
# attr_accessor :foo
# alias :foo? :foo
#
# def do_something
# end
Layout/EmptyLinesAroundAttributeAccessor:
Enabled: true
# Checks method call operators to not have spaces around them.
#
# # bad
# foo. bar
# foo .bar
# foo . bar
# foo. bar .buzz
# foo
# . bar
# . buzz
# foo&. bar
# foo &.bar
# foo &. bar
# foo &. bar&. buzz
# RuboCop:: Cop
# RuboCop:: Cop:: Cop
# :: RuboCop::Cop
#
# # good
# foo.bar
# foo.bar.buzz
# foo
# .bar
# .buzz
# foo&.bar
# foo&.bar&.buzz
# RuboCop::Cop
# RuboCop::Cop::Cop
# ::RuboCop::Cop
Layout/SpaceAroundMethodCallOperator:
Enabled: true
# 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/HashAlignment:
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/ParameterAlignment:
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/FirstArrayElementIndentation:
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/FirstHashElementIndentation:
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
# This cop checks for places where binary operator has identical
# operands.
# It covers arithmetic operators: `-`, `/`, `%`;
# comparison operators: `==`, `===`, `=~`, `>`, `>=`, `<`, `<=`;
# bitwise operators: `|`, `^`, `&`;
# boolean operators: `&&`, `||` and “spaceship” operator - `<=>`.
#
# Simple arithmetic operations are allowed by this cop: `+`, `*`,
# `**`, `<<` and `>>`. Although these can be rewritten in a
# different way, it should not be necessary to do so. This does not
# include operations such as `-` or `/` where the result will always
# be the same (`x - x` will always be 0; `x / x` will always be 1),
# and thus are legitimate offenses.
#
# bad
# x / x
# x.top >= x.top
#
# if a.x != 0 && a.x != 0
# do_something
# end
#
# def child?
# left_child || left_child
# end
#
# # good
# x + x
# 1 << 1
Lint/BinaryOperatorWithIdenticalOperands:
Enabled: true
# Algorithmic constants for `OpenSSL::Cipher` and `OpenSSL::Digest`
# deprecated since OpenSSL version 2.2.0. Prefer passing a string
# instead.
#
# # Example for OpenSSL::Cipher instantiation.
#
# # bad
# OpenSSL::Cipher::AES.new(128, :GCM)
#
# # good
# OpenSSL::Cipher.new('aes-128-gcm')
#
# # Example for OpenSSL::Digest instantiation.
#
# # bad
# OpenSSL::Digest::SHA256.new
#
# # good
# OpenSSL::Digest.new('SHA256')
#
# # Example for ::Digest inherited class methods.