-
Notifications
You must be signed in to change notification settings - Fork 1
/
common_rubocop.yml
875 lines (794 loc) · 30.5 KB
/
common_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
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
AllCops:
TargetRubyVersion: 2.7.0
# We choose to opt-in to new checks by default. This allows us to update
# version by version without having to worry about adding an entry for each
# new "enabled by default" check. If we want to jump multiple versions and
# wish to be notified of all the enw check, then we'll need to change
# `NewCops` to `pending`.
NewCops: enable
Exclude:
# Exclude generated binstubs
- 'bin/bundle'
- 'bin/bundler-travis'
- 'bin/pronto'
- 'bin/pry'
- 'bin/radius-cli'
- 'bin/rake'
- 'bin/rspec'
- 'bin/rubocop'
- 'bin/travis'
- 'bin/webpack'
- 'bin/webpack-dev-server'
- 'bin/yard'
- 'bin/yarn'
# Exclude vendored content
- 'vendor/**/*'
# We would like to disallow http for bundler sources and enforce https
# as it is more secure.
Bundler/InsecureProtocolSource:
AllowHttpProtocol: false
# We prefer outdented access modifiers as we feel they provide demarcation of
# the class similar to `rescue` and `ensure` in a method.
#
# Configuration parameters: EnforcedStyle, IndentationWidth.
# SupportedStyles: outdent, indent
Layout/AccessModifierIndentation:
Details: |
Prefer outdented access modifiers to provide demarcation of the class
similar to `rescue` and `ensure` in a method.
EnforcedStyle: outdent
# This cop checks whether the end keyword of begin is aligned properly.
#
# Two modes are supported through the EnforcedStyleAlignWith configuration parameter. If it’s set to
# begin, the end shall be aligned with the begin keyword. We chose this to be consistent with our if
# statement styles, if you want the end to be aligned with the start of the line just put the begin
# on the next line.
#
# Configuration parameters: EnforcedStyleAlignWith
# SupportedStyles: start_of_line, begin
Layout/BeginEndAlignment:
EnforcedStyleAlignWith: begin
# Rubocop 0.60.0 changed how it handled value alignments in this cop. This
# breaks our preference for wanting keys to be aligned, but allowing values to
# either use the `key` or `table` style:
#
# key_style = {
# key: :value,
# another: :value,
# yet_another: :value
# }
# table_style = {
# key: :value,
# another: :value
# yet_another: :value
# }
#
# This is logged with Rubocop: https://github.com/rubocop-hq/rubocop/issues/6410
#
# Until Rubocop resolves this we've decided to enforce the key style so that we
# do not lose all associated formatting checks. Additionally, in response to
# the referenced issue the Rubocop disables the alignment check by default. To
# continue using it we force enable it here.
#
# Configuration parameters: EnforcedHashRocketStyle, EnforcedColonStyle, EnforcedLastArgumentHashStyle.
# SupportedHashRocketStyles: key, separator, table
# SupportedColonStyles: key, separator, table
# SupportedLastArgumentHashStyles: always_inspect, always_ignore, ignore_implicit, ignore_explicit
Layout/HashAlignment:
Enabled: true
EnforcedHashRocketStyle: key
EnforcedColonStyle: key
# Disabling this until it is fixed to support multi-line block chains using the
# semantic style.
#
# See https://github.com/bbatsov/rubocop/issues/5655
#
# Configuration parameters: EnforcedStyleAlignWith.
# SupportedStylesAlignWith: either, start_of_block, start_of_line
Layout/BlockAlignment:
Enabled: false
# Disabling this until it is fixed to handle multi-line method chains where the
# first method call is multi-line.
#
# See https://github.com/bbatsov/rubocop/issues/5650
#
# Configuration parameters: EnforcedStyle, IndentationWidth.
# SupportedStyles: consistent, consistent_relative_to_receiver,
# special_for_inner_method_call, special_for_inner_method_call_in_parentheses
#
# TODO: At some point this is split into both Layout/FirstArgumentIndentation
# and Layout/FirstParameterIndentation
Layout/FirstArgumentIndentation:
Enabled: false
# We generally prefer to use the default line length of 80. Though sometimes
# we just need a little extra space because it makes it easier to read.
#
# The only way to disable Rubocop for a single line is either to wrap the line
# with two comments or append the disable comment to the end of the line. For
# guard clauses, we tend to prefer trailing comments to avoid adding two lines
# just to disable a cop on one line.
#
# Sometimes comments include ASCII diagrams, flow charts, etc. These cannot
# always be reformatted to fit within the 80 column limit. Also, we write most
# comments in markdown format. Rubocop isn't very good at understanding when
# the line is long because of a URL in a markdown link. Instead of requiring
# additional comments to turn this cop off for comments we ignore any long
# lines which are only comments.
#
# There are also cases where for one valid reason or another we have a trailing
# comment that extends a little too far. We'd like to be able to ignore those
# as well. This _attempts_ to do that, however, as this uses simple regular
# expressions we can only attempt to match so much. We probably should change
# this for a node pattern matcher in the future.
#
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes,
# IgnoreCopDirectives, AllowedPatterns.
# URISchemes: http, https
Layout/LineLength:
IgnoreCopDirectives: true
AllowedPatterns:
# Leading comments
- '\A\s*#'
# Attempt at trailing comments
- '\A.{1,78}\s#\s.*\z'
Max: 120
Exclude:
- '**/*.gemspec'
# We tend to indent multi-line operation statements. I think this is because it
# tends to be the default style auto-formatted by VIM (which many of us use).
# It also helps show the continuation of the statement instead of it
# potentially blending in with the start of the next statement.
#
# Configuration parameters: EnforcedStyle, IndentationWidth.
# SupportedStyles: aligned, indented
Layout/MultilineOperationIndentation:
Details: "This helps show expression continuation setting it apart from the following LOC."
EnforcedStyle: indented
# In our specs Rubocop inconsistently complains when using the block form of
# `expect` and `change`. It accepts code when a method is chained onto
# `change`, but otherwise it complains. Since this is a widely used pattern in
# our specs we just tell Rubocop to ignore our spec files.
#
# # Acceptable to Rubocop
# expect {
# some_action
# }.to change {
# object.state
# }.from(:original).to(:updated)
#
# # Rubocop complains
# expect {
# some_action
# }.to change {
# object.state
# }
#
# WARNING TO FUTURE READERS (future being after 2021-12-10):
# We tried to allowlist certain methods using the IgnoredMethods option (introduced 1.13.0),
# and Rubocop successfully ignored `change` and `not_change` constructions, but it flag false
# positives against code like
#
# expect { something }
# .to enqueue_job(SomeJobClass)
# .with { custom expectations about the enqueued payload }
#
# no matter what combination of `enqueue_job` and `with` we tried to add to the IgnoredMethods
# array. We suspect the AST matching is somewhat half-baked.
Lint/AmbiguousBlockAssociation:
Exclude:
- 'spec/**/*_spec.rb'
# We prefer to enforce a consistent usage for readability
#
# <<~SQL.strip
# bar
# SQL
#
# display(<<~SQL.strip)
# bar
# SQL
#
# Alternatively, refactoring the heredoc into a local also improves
# readability:
#
# custom_sql = <<~SQL
# bar
# SQL
# display(custom_sql.strip)
Lint/HeredocMethodCallPosition:
Enabled: true
# We prefer people suggesting people subclass `StandardError` for their custom
# exceptions as this is a relatively common Ruby idiom.
Lint/InheritException:
EnforcedStyle: standard_error
# Make developers explain themselves in a comment if they want their rescue block to do nothing.
Lint/SuppressedException:
AllowNil: false
# Often with benchmarking we don't explicitly "use" a variable or return value.
# We simply need to perform the operation which generates said value for the
# benchmark.
#
# Configuration parameters: CheckForMethodsWithNoSideEffects.
Lint/Void:
Exclude:
- 'benchmarks/**/*'
Metrics/AbcSize:
CountRepeatedAttributes: false
Max: 17
# Configuration parameters: CountComments, IgnoredMethods, Max.
# IgnoredMethods: refine
Metrics/BlockLength:
CountAsOne:
- 'array'
- 'hash'
- 'heredoc'
Exclude:
- '**/Rakefile'
- '**/*.rake'
- 'spec/spec_helper.rb'
- 'spec/**/*_spec.rb'
- 'spec/support/model_factories.rb'
AllowedMethods:
- 'chdir'
- 'describe'
- 'refine'
- 'shared_context'
- 'shared_examples'
- 'Capybara.register_driver'
- 'RSpec.configure'
- 'RSpec.describe'
- 'RSpec.shared_context'
- 'RSpec.shared_examples'
- 'VCR.configure'
# We want length related code metrics to count Hashs, Arrays, and
# Heredocs as one "line"
Metrics/ClassLength:
CountAsOne:
- 'array'
- 'hash'
- 'heredoc'
Metrics/ModuleLength:
CountAsOne:
- 'array'
- 'hash'
- 'heredoc'
Metrics/MethodLength:
CountAsOne:
- 'array'
- 'hash'
- 'heredoc'
# This is overly pedantic (only allowing `other` as the parameter name). Ruby
# core doesn't follow this consistently either. Looking at several classes
# throughout Ruby core we do often see `other`, but also often `obj` or
# `other_*`. In some cases, the parameter is named more meaningfully with names
# like `real`, `numeric`, or `str`.
Naming/BinaryOperatorParameterName:
Enabled: false
# We don't need this configured just yet, because we dont have any applications on
# Ruby 3.1, but pre-emptively, we want to configure this to prefer the explicit style.
#
# bad
# def foo(&)
# bar(&)
# end
# good
# def foo(&block)
# bar(&block)
# end
Naming/BlockForwarding:
EnforcedStyle: explicit
# Configuration parameters: ExpectMatchingDefinition, Regex, IgnoreExecutableScripts, AllowedAcronyms.
# AllowedAcronyms: CLI, DSL, ACL, API, ASCII, CPU, CSS, DNS, EOF, GUID, HTML, HTTP, HTTPS, ID, IP, JSON, LHS, QPS, RAM, RHS, RPC, SLA, SMTP, SQL, SSH, TCP, TLS, TTL, UDP, UI, UID, UUID, URI, URL, UTF8, VM, XML, XMPP, XSRF, XSS
Naming/FileName:
Exclude:
- '**/Gemfile'
- '**/*.gemspec'
- '**/Brewfile'
# This allows `EOF` as the only `EO*` variant.
#
# `EOF` is a common terminal abbreviate indicating end-of-file. We allow this
# for those heredocs which represent "file" text.
#
# Configuration parameters: ForbiddenDelimiters.
# ForbiddenDelimiters: (?-mix:(^|\s)(EO[A-Z]{1}|END)(\s|$))
Naming/HeredocDelimiterNaming:
Details: |
Use meaningful delimiter names to provide context to the text. The only
allowed `EO*` variant if `EOF` which has specific meaning for file content.
ForbiddenDelimiters:
- !ruby/regexp '/(^|\s)(EO[A-EG-Z]{1}|END)(\s|$)/'
# It is generally a good idea to match the instance variable names with their
# methods to keep consistent with the attribute reader / writer pattern.
# However, this can pose an issue in Rails. Most notably, when writing modules
# that will be used as controller plugins. The reason is that the Rails
# controllers-to-view interface is ivars. Using a leading underscore can help
# avoid accidental controller ivar naming conflicts.
#
# Configuration parameters: EnforcedStyleForLeadingUnderscores.
# SupportedStylesForLeadingUnderscores: disallowed, required, optional
Naming/MemoizedInstanceVariableName:
Details: |
It is generally a good idea to match the instance variable names with their
methods to keep consistent with the attribute reader / writer pattern. An
exception can be made for modules that want to avoid naming conflicts with
classes that include them. In this case a single leading underscore is
acceptable.
EnforcedStyleForLeadingUnderscores: optional
# We don't really care about this check. Sometimes using something simple such
# as `err` is just fine. Other times it may improve readability to have a more
# descriptive name. We feel this is a personal judgement call and not something
# that needs to be enforced.
Naming/RescuedExceptionsVariableName:
Enabled: false
# `alias` behavior changes on scope. In general we expect the behavior to be
# that which is defined by `alias_method`.
#
# See https://stackoverflow.com/questions/4763121/should-i-use-alias-or-alias-method
#
# Configuration parameters: EnforcedStyle.
# SupportedStyles: prefer_alias, prefer_alias_method
Style/Alias:
Details: |
Prefer `alias_method` because `alias` behavior changes based on scope.
See:
- https://stackoverflow.com/questions/4763121/should-i-use-alias-or-alias-method
- https://blog.bigbinary.com/2012/01/08/alias-vs-alias-method.html
EnforcedStyle: prefer_alias_method
# Keeping with our semantic style we allow use of `and` / `or` conditionals
# when it is used for control flow:
#
# system("some command") or system("another command")
#
# Used in this manner it provides additional semantic clues to the intent of
# the code. However, when there is a conditional, or the intent is to perform
# a boolean comparison, the `&&` / `||` style should be used.
#
# Configuration parameters: EnforcedStyle.
# SupportedStyles: always, conditionals
Style/AndOr:
Details: |
Use `&&` / `||` for conditionals or general comparison. Use `and` / `or`
for control flow to provide additional semantic hints:
system("some command") or system("another command")
EnforcedStyle: conditionals
# These days most people have editors which support unicode and other
# non-ASCII characters.
#
# In version 1.21.0, this is disabled by default. We've chosen to leave
# it in the config, in case it changes in future versions.
#
# Configuration parameters: AllowedChars.
Style/AsciiComments:
Enabled: false
# Use semantic style for blocks:
# - Prefer `do...end` over `{...}` for procedural blocks.
# - Prefer `{...}` over `do...end` for functional blocks.
#
# When the return value of the method receiving the block is important prefer
# `{...}` over `do...end`.
#
# Some people enjoy the compact readability of `{...}` for one-liners so we
# allow that style as well.
#
# Configuration parameters: EnforcedStyle, ProceduralMethods, FunctionalMethods, IgnoredMethods.
# SupportedStyles: line_count_based, semantic, braces_for_chaining
Style/BlockDelimiters:
Details: |
Use semantic style for blocks:
- Prefer `do...end` over `{...}` for procedural blocks.
- Prefer `{...}` over `do...end` for functional blocks.
When the return value of the method receiving the block is important prefer
`{..}` over `do..end`.
AllowBracesOnProceduralOneLiners: true
Enabled: true
EnforcedStyle: semantic
ProceduralMethods:
- benchmark
- bm
- bmbm
- measure
- realtime
- with_object
FunctionalMethods:
- create
- create!
- build
- build!
- default_scope
- each_with_object
- filter_sensitive_data
- find
- git_source
- let
- let!
- new
- subject
- tap
- watch
AllowedMethods:
- lambda
- proc
- it
# As a team we prefer the more explicit `def self.method_name` style. We find
# the explicitness easier to read and grep for on the CLI.
#
# Configuration parameters: EnforcedStyle.
# SupportedStyles: def_self, self_class
Style/ClassMethodsDefinitions:
Enabled: true
EnforcedStyle: def_self
# Prefer `Time` over `DateTime`.
#
# While these are not necessarily interchangeable we prefer `Time`. According
# to the Ruby docs `DateTime` is meant more for historical dates; it also does
# not consider leap seconds or summer time rules.
#
# Lastly, `DateTime` is part of the stdlib which is written in Ruby; where as
# `Time` is part of core and written in C.
#
# Configuration parameters: AllowCoercion
Style/DateTime:
Enabled: true
# The double negation idiom is a common Ruby-ism. All languages have various
# idioms and part of learning the language is learning the common idioms. Once
# learning the meaning it is not cryptic as Rubocop implies.
#
# > Double negation converts converts a value to boolean.
# >
# > It converts "truthy" values to `true` and "falsey" values, `nil` and
# > `false`, to `false`.
#
# The [Rubocop style guide](https://github.com/rubocop-hq/ruby-style-guide#no-bang-bang)
# does have a valid complaint about it's use in a conditional:
#
# > you don't need this explicit conversion in the condition of a control
# > expression; using it only obscures your intention...
# >
# > ```ruby
# > # bad
# > x = 'test'
# > # obscure nil check
# > if !!x
# > # body omitted
# > end
# >
# > # good
# > x = 'test'
# > if x
# > # body omitted
# > end
# > ```
#
# This is true and we completely agree. However the check isn't limited to just
# conditional control expressions. It affects any use of the idiom.
#
# We believe using the idiom is completely valid for predicate methods to
# ensure either a `true` or `false` return, instead of just a "truthy" or
# "falsey" response. As it is an op it is a bit faster than the alternative of
# sending `nil?` to the object and more concise than using `obj == nil`. It
# also works with something that is potentially `false` as expected.
#
# As we cannot customize this to only limit it to the conditional control
# expressions, or instances which may be better replaced with something else
# (like `blank?`), we are disabling it.
Style/DoubleNegation:
Enabled: false
# Using `case` instead of an `if` expression when the case condition is empty
# can be more expressive of intent. Using multiple "cases" informs the reader
# that all of the conditions are related or coupled in a meaningful way.
# Multi-branch `if` expressions do not necessarily convey this relation. They
# may simply be separate branching logic and possibly only flattened for
# readability.
Style/EmptyCaseCondition:
Enabled: false
# Always write methods on multiple lines.
#
# Configuration parameters: EnforcedStyle.
# SupportedStyles: compact, expanded
Style/EmptyMethod:
EnforcedStyle: expanded
# Always require the pragma comment to be true
#
# Configuration parameters: EnforcedStyle.
# SupportedStyles: always, always_true, never
Style/FrozenStringLiteralComment:
EnforcedStyle: always_true
# If we're using consecutive conditionals we probably know what we're doing. The good thing is this
# cop will still flag consecutive conditionals that are identical.
Style/GuardClause:
AllowConsecutiveConditionals: true
# Prefer symbol keys using the 1.9 hash syntax. However, when keys are mixed
# use a consistent mapping style; which generally means using hash rockets:
#
# # bad
# {:a => 2}
# {b: 1, :c => 2}
# {d: 1, 'e' => 2}
#
# # good
# {a: 2, b: 1}
# {:c => 2, 'd' => 2} # acceptable since 'd' isn't a symbol
#
# Configuration parameters: EnforcedStyle, UseHashRocketsWithSymbolValues, PreferHashRocketsForNonAlnumEndingSymbols.
# SupportedStyles: ruby19, hash_rockets, no_mixed_keys, ruby19_no_mixed_keys
Style/HashSyntax:
Details: |
Prefer symbol keys using the 1.9 hash syntax. However, when keys are mixed
use a consistent mapping style; which generally means using hash rockets.
EnforcedStyle: ruby19_no_mixed_keys
EnforcedShorthandSyntax: either
# As part of our semantic style we generally use the literal `-> { }` format to
# indicate this is a function with a return value we care about. As this cop
# doesn't have a more flexible setting we prefer the literal syntax to the
# lambda version.
#
# Configuration parameters: EnforcedStyle.
# SupportedStyles: line_count_dependent, lambda, literal
Style/Lambda:
Details: |
As part of our semantic style we generally use the literal `-> { }` format
to indicate this is a function with a return value we care about. As this
cop doesn't have a more flexible setting we prefer the literal syntax to
the lambda version.
EnforcedStyle: literal
# Avoid chaining a method call on a do...end block. This breaks semantic style
# reducing contextual information.
Style/MethodCalledOnDoEndBlock:
Details: "This breaks semantic style reducing contextual information."
Enabled: true
# With semantic style (functional blocks) it's common to chain several methods
# to avoid creating multiple intermediate local variables. Block length is
# generally not an issue here as these types of usage tend to produce short (<
# 5 LOC) multi-line blocks.
Style/MultilineBlockChain:
Enabled: false
# Disallowing numbered parameter usage because we dont prefer this style.
# We would rather name the paramaters to clearly communicate intent.
Style/NumberedParameters:
EnforcedStyle: disallow
# Context for this cop is too dependent.
#
# Often using the numeric comparison is faster. Also, depending on the context
# a numeric comparison may produce a more consistent style:
#
# # numeric comparison is more natural and consistent
# if n < 0
# elsif n < 5
# elsif n < 20
# end
#
# Configuration parameters: AutoCorrect, EnforcedStyle.
# SupportedStyles: predicate, comparison
Style/NumericPredicate:
Enabled: false
# As a general rule, we want to be explicit here instead of requiring readers
# of our code to know what the default arguments to methods like `#join` and
# and `#split` so we disable this cop here.
Style/RedundantArgument:
Enabled: false
# In Ruby every method returns a value. Implicitly this is the value of the
# last line of the method. This means using `return` is often redundant.
# However, there isn't anything inherently wrong about doing so. In fact, in
# some cases it can help with a consistent style in a method:
#
# def transform(value)
# return value.call if value.is_a?(Proc)
# return value if value.frozen?
# return value.dup
# end
#
# Other times it can add context to a seemingly oddly place value:
#
# def munge(data)
# data.slice! 5
# return nil
# end
#
# We often omit the explicit `return` in our code. Though sometimes we include
# it for improved contextual clues and we don't want Rubocop to complain for
# those cases.
#
# Configuration parameters: AllowMultipleReturnValues.
Style/RedundantReturn:
Enabled: false
# Prefer slashes for simple expressions. For multi-line use percent literal
# to support comments and other advanced features. By using the mixed style we
# are choosing to use `%r{}` for multi-line regexps. In general we are not a
# fan of single vs multi-line dictating a style. We do make an exception in
# this case because of the parity the braces give to general code block
# grouping:
#
# regex = %r{
# foo
# (bar)
# (baz)
# }x
#
# Configuration parameters: EnforcedStyle, AllowInnerSlashes.
# SupportedStyles: slashes, percent_r, mixed
Style/RegexpLiteral:
Details: |
Prefer slashes for simple expressions. Use `%r` for expressions containing
slashes and for complex expressions so then can be written across multiple
lines (allowing advanced features such as comments). Use of `%r` for
expressions spanning multiple lines provides some comprehension parity with
general code blocks.
EnforcedStyle: mixed
# If you only need to rescue a single, or predefined set of exceptions, then
# catch the exceptions explicitly. However, when you need to include a general
# error handler / "catch-all" use the "unspecified rescue".
#
# Using the unspecified `rescue` on blocks is common Ruby practice. It is a
# core feature of the language which has semantic meaning. The Rubocop docs do
# not provide much justification for defaulting to an explicit style and there
# is no real mention of this in the associated style guide except the following
# buried in an example for [_Avoid rescuing the `Exception`
# class_](https://github.com/bbatsov/ruby-style-guide#no-blind-rescues) though
# the anchor suggests this is for "no blind rescues":
#
# > # a blind rescue rescues from StandardError, not Exception as many
# > # programmers assume.
#
# Our general rule for Ruby exceptions is to create your custom errors from
# `StandardError`. Creating custom errors off of `Exception` is reserved for
# special edge cases where you don't intend for someone to normally catch it
# (such as system resource issues; e.g. `NoMemoryError`, `SecurityError`).
#
# With that in mind, we can make the same counter argument that since
# programmers generally assume the unspecified rescue rescues `Exception`,
# which they normally should not be rescuing, system errors are more likely to
# noticed.
#
# Additionally, use of the unspecified rescue looks and behaves like a
# "catch-all" or the `else` clause in a `case` statement:
#
# begin
# # do something that may cause a standard error
# rescue TypeError
# handle_type_error
# rescue => e
# handle_error e
# end
#
# Configuration parameters: EnforcedStyle.
# SupportedStyles: implicit, explicit
Style/RescueStandardError:
Details: |
If you only need to rescue a single, or predefined set of exceptions, then
catch each exception explicitly. When you need to include a general error
handler or "catch-all" use the "unspecified rescue":
begin
# do something that may cause a standard error
rescue TypeError
handle_type_error
rescue => e
handle_error e
end
Avoid rescuing `Exception` as this may hide system errors.
EnforcedStyle: implicit
# We don't really care which style we use here and would prefer rubocop not
# complain about this.
Style/SlicingWithRange:
Enabled: false
# We want to turn this cop on so that rubocop can yell at us instead of Aaron
# yelling at us.
Style/StaticClass:
Enabled: true
# Enable Style/StringChars
Style/StringChars:
Enabled: true
# We generally prefer double quotes but many generators use single quotes. We
# don't view the performance difference to be all that much so we don't care
# if the style is mixed or double quotes are used for static strings.
#
# Configuration parameters: EnforcedStyle, ConsistentQuotesInMultiline.
# SupportedStyles: single_quotes, double_quotes
Style/StringLiterals:
Enabled: false
# As with regular string literals we have no real preference for this. Forcing
# one style of strings over others for this case just adds to Rubocop noise and
# in our experience developer frustration.
#
# Configuration parameters: EnforcedStyle.
# SupportedStyles: single_quotes, double_quotes
Style/StringLiteralsInInterpolation:
Enabled: false
# We don't feel too strongly about percent vs bracket array style. We tend to
# use the percent style, which also happens to be Rubocop's default. So for
# pedantic consistency we'll enforce this.
#
# However, as we don't feel that strongly about this we'll increase the
# minimum size to 3 to allow very small arrays to exist either way.
#
# Configuration parameters: EnforcedStyle, MinSize.
# SupportedStyles: percent, brackets
Style/SymbolArray:
MinSize: 3
# Allow either
# something.do_something(foo, &:bar)
# or
# something.do_something(foo) { |s| s.bar }
Style/SymbolProc:
AllowMethodsWithArguments: true
# When ternaries become complex they can be difficult to read due to increased
# cognitive load parsing the expression. Cognitive load can increase further
# when assignment is involved.
#
# Configuration parameters: EnforcedStyle, AllowSafeAssignment.
# SupportedStyles: require_parentheses, require_no_parentheses, require_parentheses_when_complex
Style/TernaryParentheses:
AllowSafeAssignment: false
Details: |
When ternaries become complex they can be difficult to read due to
increased cognitive load parsing the expression. Cognitive load can
increase further when assignment is involved. To help reduce this cognitive
use parentheses for complex expressions.
EnforcedStyle: require_parentheses_when_complex
# Always use trailing commas for multiline. This makes git diffs easier to read
# by cutting down on noise when commas are appended.
#
# However, specs often multi-line `expect()` for readability with long lines.
# We don't want to enforce a trailing comma in that case. Ideally, there would
# be another option to only enforce a consistent comma when there is more than
# one argument.
#
# Configuration parameters: EnforcedStyleForMultiline.
# SupportedStylesForMultiline: comma, consistent_comma, no_comma
Style/TrailingCommaInArguments:
Details: |
Always use trailing commas for multiline arguments. This makes git diffs
easier to read by cutting down on noise when commas are appended. It also
simplifies adding, removing, and swapping argument orders.
EnforcedStyleForMultiline: consistent_comma
Exclude:
- 'spec/**/*_spec.rb'
# Always use trailing commas for multiline. This makes git diffs easier to read
# by cutting down on noise when commas are appended.
#
# Configuration parameters: EnforcedStyleForMultiline.
# SupportedStylesForMultiline: comma, consistent_comma, no_comma
Style/TrailingCommaInArrayLiteral:
Details: |
Always use trailing commas for multiline arrays. This makes git diffs
easier to read by cutting down on noise when commas are appended. It also
simplifies adding, removing, and re-arranging the elements.
EnforcedStyleForMultiline: consistent_comma
# Always use trailing commas for multiline. This makes git diffs easier to read
# by cutting down on noise when commas are appended.
#
# Configuration parameters: EnforcedStyleForMultiline.
# SupportedStylesForMultiline: comma, consistent_comma, no_comma
Style/TrailingCommaInHashLiteral:
Details: |
Always use trailing commas for multiline hashes. This makes git diffs
easier to read by cutting down on noise when commas are appended. It also
simplifies adding, removing, and re-arranging the elements.
EnforcedStyleForMultiline: consistent_comma
# Don't combine && & || inside the same `unless` guard clause.
Style/UnlessLogicalOperators:
Enabled: true
EnforcedStyle: forbid_mixed_logical_operators
# We don't feel too strongly about percent vs bracket array style. We tend to
# use the percent style, which also happens to be Rubocop's default. So for
# pedantic consistency we'll enforce this.
#
# However, as we don't feel that strongly about this we'll increase the
# minimum size to 3 to allow very small arrays to exist either way.
#
# Configuration parameters: EnforcedStyle, MinSize, WordRegex.
# SupportedStyles: percent, brackets
Style/WordArray:
MinSize: 3
# When it comes to constants it's safer to place the constant on the right-hand
# side. With a constant accidental assignment will produce a syntax error.
#
# Configuration parameters: EnforcedStyle.
# SupportedStyles: all_comparison_operators, equality_operators_only
Style/YodaCondition:
Enabled: false
# Forbids Yoda expressions, i.e. binary operations (using *, +, &, |, and ^ operators)
# where the order of expression is reversed, eg. 1 + x.
Style/YodaExpression:
Enabled: true
# Disabled in 1.21.0. Radius Networks has chosen to enable it.
Naming/InclusiveLanguage:
Enabled: true