-
Notifications
You must be signed in to change notification settings - Fork 0
/
.rubocop.yml
619 lines (555 loc) · 15.8 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
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
# cspell:Disable
AllCops:
TargetRubyVersion: 3.2.4
# RuboCop has a bunch of cops enabled by default. This setting tells RuboCop
# to ignore them, so only the ones explicitly set in this file are enabled.
DisabledByDefault: true
# From time to time rubocop adds new cops to say rails etc.
# So rather than disabling them it's better to enable them,
# try it out and then disable them manually one by one.
NewCops: enable
# Disable extension suggestions
SuggestExtensions: false
Exclude:
- "app/javascript/**/*"
- "test/dummy/app/javascript/**/*"
- "app/assets/**/*"
- "test/dummy/app/assets/**/*"
- "app/views/**/*.erb"
- "test/dummy/app/views/**/*.erb"
- "lib/tasks/**/*"
- "test/dummy/lib/tasks/**/*"
- ".vscode/**/*"
- ".husky/**/*"
- ".bundle/**/*"
- ".circleci/**/*"
- ".semaphore/**/*"
- "**/log/**/*"
- "**/public/**/*"
- "**/tmp/**/*"
- "**/templates/**/*"
- "**/vendor/**/*"
- "node_modules/**/*"
- "bin/**/*"
- "test/dummy/bin/**/*"
- "config/webpack/**/*"
- "db/schema.rb"
- "test/dummy/db/schema.rb"
- "db/data_schema.rb"
- "test/dummy/db/data_schema.rb"
- "*.gemspec"
- "*.yml"
# ====================================================================================================
# All access modifier related rules
# ====================================================================================================
# Add a newline before and after private keyword or other access modifiers
Layout/EmptyLinesAroundAccessModifier:
Enabled: true
# This cop checks for redundant access modifiers, including those with no code,
# those which are repeated, and leading `public` modifiers in a class or module body.
Lint/UselessAccessModifier:
Enabled: true
# Checks for debug calls
Lint/Debugger:
Enabled: true
# # bad
# class Foo
# private def bar; end
# private def baz; end
# end
# # good
# class Foo
# private
#
# def bar; end
# def baz; end
# end
Style/AccessModifierDeclarations:
Enabled: true
# # bad
# class Plumbus
# private
# def smooth; end
# end
# # good
# class Plumbus
# private
# def smooth; end
# end
Layout/AccessModifierIndentation:
Enabled: true
# ====================================================================================================
# All comment related rules
# ====================================================================================================
# Align comments with method definitions.
Layout/CommentIndentation:
Enabled: true
# Requires an empty line after frozen_string_literal: true comment
Layout/EmptyLineAfterMagicComment:
Enabled: true
# frozen_string_literal: true magic comment is required on the top of files
Style/FrozenStringLiteralComment:
Enabled: true
EnforcedStyle: always
SafeAutoCorrect: true
# ====================================================================================================
# All Class related rules
# ====================================================================================================
# Helps in brining the include statements etc to top of the class definition
Layout/ClassStructure:
Enabled: true
Description: "Enforces a canonical order of definitions within a class body."
StyleGuide: "https://github.com/rubocop/rails-style-guide#macro-style-methods"
Categories:
module_inclusions:
- include
- prepend
- extend
third_party:
- neeto_sso_track_widget_tokens
- devise
- serialize
scopes:
- default_scope
- scope
attributes:
- attribute
- attr_reader
- attr_writer
- attr_accessor
enum:
- enum
store:
# https://api.rubyonrails.org/classes/ActiveRecord/Store.html
- store
other_macros:
- delegate
- delegate_missing_to
- accepts_nested_attributes_for
validations:
- validate
- validates
- validates_acceptance_of
- validates_associated
- validates_confirmation_of
- validates_exclusion_of
- validates_format_of
- validates_inclusion_of
- validates_length_of
- validates_numericality_of
- validates_presence_of
- validates_uniqueness_of
- validates_each
- validate_with
callbacks:
- before_validation
- after_validation
- before_save
- around_save
- after_save
- before_update
- around_update
- after_update
- before_create
- after_create
- before_destroy
- around_destroy
- after_destroy
- after_commit
- after_update_commit
- after_create_commit
ExpectedOrder:
- module_inclusions
- third_party
- scopes
- constants
- attributes
- enum
- store
- associations
- validations
- callbacks
- other_macros
- initializer
- public_class_methods
- public_methods
- protected_methods
- private_methods
# In a regular class definition, no empty lines around the body.
# bad
# class Foo
#
# def bar
# # ...
# end
#
# end
#
# good
# class Foo
# def bar
# # ...
# end
# end
Layout/EmptyLinesAroundClassBody:
Enabled: true
# ====================================================================================================
# All Method related rules
# ====================================================================================================
# This cop checks whether class/module/method definitions are separated by one or more empty lines.
Layout/EmptyLineBetweenDefs:
Enabled: true
# This cop checks the . position in multi-line method calls.
# The dot should be leading rather than trailing.
Layout/DotPosition:
Enabled: true
EnforcedStyle: leading
# No space in method name and the arguments
Lint/ParenthesesAsGroupedExpression:
Enabled: true
# Use my_method(my_arg) not my_method( my_arg ) or my_method my_arg,
# when a boolean operator, && or ||, is chained along with this method/argument
Lint/RequireParentheses:
Enabled: true
# avoid redundant `return` expressions
Style/RedundantReturn:
Enabled: true
AllowMultipleReturnValues: true
# Ensures that exactly one space is used between a method name and the
# first argument for method calls without parentheses
Layout/SpaceBeforeFirstArg:
Enabled: true
# Methods that doesn't take any parameters shouldn't have paranthesis in its definition
Style/DefWithParentheses:
Enabled: true
# Defining a method with parameters needs parentheses.
Style/MethodDefParentheses:
Enabled: true
# # bad
# def some_method(arg1=:default, arg2=nil, arg3=[])
# # good
# def some_method(arg1 = :default, arg2 = nil, arg3 = [])
Layout/SpaceAroundEqualsInParameterDefault:
Enabled: true
# This cop checks for a line break before the first argument in a multi-line method call.
# # bad
# method(foo, bar,
# baz)
# # good
# method(
# foo, bar,
# baz)
Layout/FirstMethodArgumentLineBreak:
Enabled: true
# Method definitions after `private` or `protected` isolated calls need one
# extra level of indentation.
Layout/IndentationConsistency:
Enabled: true
EnforcedStyle: indented_internal_methods
# This cop checks the indentation of the method name part in method calls that span more than one line.
# # bad
# while myvariable
# .instance_method_call1
# .instance_method_call2
# # do something
# end
#
# # good
# while myvariable
# .instance_method_call1
# .instance_method_call2
#
# # do something
# end
Layout/MultilineMethodCallIndentation:
Enabled: true
EnforcedStyle: indented
# This cop ensures the indentation of the first parameter in a method definition.
Layout/FirstParameterIndentation:
Enabled: true
EnforcedStyle: consistent
# When we write method arguments in next line, indent it.
Layout/FirstArgumentIndentation:
Enabled: true
EnforcedStyle: consistent
# Alignment of args from second argument onwards should be indented
# # bad
# json.extract! comment,
# :id,
# :content,
# :created_at
# # good
# json.extract! comment,
# :id,
# :content,
# :created_at
Layout/ArgumentAlignment:
Enabled: true
EnforcedStyle: with_fixed_indentation
# In a regular method definition, no empty lines around the body.
Layout/EmptyLinesAroundMethodBody:
Enabled: true
# ====================================================================================================
# All Hash related rules
# ====================================================================================================
# EnforcedColonStyle: key
# # bad
# {
# foo: bar,
# ba: baz
# }
# {
# foo: bar,
# ba: baz
# }
# # good
# {
# foo: bar,
# ba: baz
# }
# EnforcedLastArgumentHashStyle: always_inspect
# # bad
# do_something({foo: 1,
# bar: 2})
# # good
# do_something(foo: 1,
# bar: 2)
Layout/HashAlignment:
Enabled: true
EnforcedColonStyle: key
EnforcedLastArgumentHashStyle: always_inspect
# This cop checks for a line break before the first element in a multi-line hash.
# # bad
# { a: 1,
# b: 2}
# # good
# {
# a: 1,
# b: 2 }
Layout/FirstHashElementLineBreak:
Enabled: true
# When using the `new_line` style:
# The closing brace of a multi-line hash literal must be on
# the line after the last element of the hash.
Layout/MultilineHashBraceLayout:
Enabled: true
EnforcedStyle: new_line
# # bad
# hash = {
# key: :value
# }
# but_in_a_method_call({
# its_like: :this
# })
# # good
# hash = {
# key: :value
# }
# and_in_a_method_call({
# no: :difference
# })
Layout/FirstHashElementIndentation:
Enabled: true
EnforcedStyle: consistent
# Use Ruby >= 1.9 syntax for hashes. Prefer { a: :b } over { :a => :b }.
Style/HashSyntax:
Enabled: true
# Use `{ a: 1 }` not `{a:1}`.
Layout/SpaceInsideHashLiteralBraces:
Enabled: true
# `no_comma`: Does not requires a comma after the last item in a hash
Style/TrailingCommaInHashLiteral:
Enabled: true
# ====================================================================================================
# All misc whitespace related rules
# ====================================================================================================
# bad
# def f(a:, b:2); {a:3}; end
# good
# def f(a:, b: 2); {a: 3}; end
Layout/SpaceAfterColon:
Enabled: true
# Ensures comma (,) is followed by some kind of space.
Layout/SpaceAfterComma:
Enabled: true
# Every ruby keyword should be surrounded by spaces
Layout/SpaceAroundKeyword:
Enabled: true
# Requires proper spacing around ruby operator symbols.
Layout/SpaceAroundOperators:
Enabled: true
## Allows multiple spaces for keeping alignment
# {
# 1 => 2,
# 11 => 3
# }
AllowForAlignment: true
# Ensures comma symbol is not preceded by space
Layout/SpaceBeforeComma:
Enabled: true
# Use `foo {}` not `foo{}`.
Layout/SpaceBeforeBlockBraces:
Enabled: true
# Use `foo { bar }` not `foo {bar}`.
Layout/SpaceInsideBlockBraces:
Enabled: true
# enforces that parentheses do not have spaces
Layout/SpaceInsideParens:
Enabled: true
# No trailing whitespace.
Layout/TrailingWhitespace:
Enabled: true
# Require a space after comment
Layout/LeadingCommentSpace:
Enabled: true
# ====================================================================================================
# All empty lines related rules
# ====================================================================================================
# The `lf` style means that LF (Line Feed) is enforced on
# all platforms.
# # bad
# puts 'Hello' # Return character is CR+LF on all platfoms.
#
# # good
# puts 'Hello' # Return character is LF on all platfoms.
Layout/EndOfLine:
Enabled: true
EnforcedStyle: lf
# In a regular module definition, no empty lines around the body.
Layout/EmptyLinesAroundModuleBody:
Enabled: true
# # bad
# def foo
# return if need_return?
# bar
# end
#
# # good
# def foo
# return if need_return?
#
# bar
# end
Layout/EmptyLineAfterGuardClause:
Enabled: true
# Requires a single final blank line to the file.
# `final_blank_line` ensures a blank line before EOF.
# # bad
# class Foo; end # EOF
#
# # good
# class Foo; end
#
# # EOF
Layout/TrailingEmptyLines:
Enabled: true
# This cop checks for two or more consecutive blank lines.
# This rule is not same as TrailingEmptyLines, because:
# 1) It looks for empty lines throughout the file. Not just the end.
# # bad - It has two empty lines.
# some_method
# # one empty line
# # two empty lines
# some_method
#
# # good
# some_method
# # one empty line
# some_method
Layout/EmptyLines:
Enabled: true
# ====================================================================================================
# All naming convetion related rules for variables
# ====================================================================================================
# Refer: https://www.bigbinary.com/learn-rubyonrails-book/n+1-queries-and-memoization#bb-generated-p-id-44
# Sadly this cannot be auto-corrected.
Naming/MemoizedInstanceVariableName:
Enabled: true
EnforcedStyleForLeadingUnderscores: required
Severity: info
# ====================================================================================================
# All misc rules that don't fall into other categories
# ====================================================================================================
# Prefer &&/|| over and/or.
Style/AndOr:
Enabled: true
# Align `when` with `case`.
Layout/CaseIndentation:
Enabled: true
Layout/LineLength:
Enabled: true
Max: 120
AllowedPatterns: [
'^\s*#', # line that begins with comment
'^\s*"', # line that begins with double quote (long string literal)
'^\s*%{', # line that begins with percent literals (long string literal)
"^\\s*'", # line that begins with single quote (long string literal)
'"$', # line that ends with double quote (long string variable assignment)
"'$", # line that ends with single quote (long string variable assignment)
"}$", # line that ends with percent literals (long regex variable assignment)
'\/$', # line that ends with slash (long regex variable assignment)
]
# Indent using two spaces
Layout/IndentationWidth:
Enabled: true
Width: 2
# Use spaces for indentation. Not tabs
Layout/IndentationStyle:
Enabled: true
EnforcedStyle: spaces
# Remove extra/unnecessary whitespace which's used for alignment.
# A developer shouldn't waste time indenting code with whitespaces.
Layout/ExtraSpacing:
Enabled: true
AllowForAlignment: false
# Helps in removing unwanted parentheses.
# # bad
# x += 1 while (x < 10)
# foo unless (bar || baz)
#
# if (x > 10)
# elsif (x < 3)
# end
#
# # good
# x += 1 while x < 10
# foo unless bar || baz
#
# if x > 10
# elsif x < 3
# end
Style/ParenthesesAroundCondition:
Enabled: true
# Enforce string literals to use double quotes everywhere
Style/StringLiterals:
Enabled: true
EnforcedStyle: double_quotes
# Use quotes for string literals when they are enough.
Style/RedundantPercentQ:
Enabled: true
# Align `end` with the matching keyword or starting expression except for
# assignments, where it should be aligned with the LHS.
Layout/EndAlignment:
AutoCorrect: true
Enabled: true
EnforcedStyleAlignWith: variable
# avoid lines terminated with a semicolon.
Style/Semicolon:
Enabled: true
# disallow multiple statements in a line
AllowAsExpressionSeparator: false
# Corrects usage of :true/:false to true/false
Lint/BooleanSymbol:
Enabled: true
# ====================================================================================================
# All flow(if/while/for/until) statements related
# ====================================================================================================
Lint/AssignmentInCondition:
Enabled: true
AllowSafeAssignment: true
# ====================================================================================================
# All Bundler cop rules
# ====================================================================================================
Bundler/OrderedGems:
Enabled: true
TreatCommentsAsGroupSeparators: true