.rubocop.yml 20.2 KB
Newer Older
1
2
3
require:
  - rubocop-rspec
  - ./rubocop/rubocop
Robert Speicher's avatar
Robert Speicher committed
4

Z.J. van de Weg's avatar
Z.J. van de Weg committed
5
6
inherit_from: .rubocop_todo.yml

7
AllCops:
Z.J. van de Weg's avatar
Z.J. van de Weg committed
8
  TargetRubyVersion: 2.3
Z.J. van de Weg's avatar
Z.J. van de Weg committed
9
  # Cop names are not d§splayed in offense messages by default. Change behavior
10
11
12
13
14
15
16
17
18
19
  # by overriding DisplayCopNames, or by giving the -D/--display-cop-names
  # option.
  DisplayCopNames: true
  # Style guide URLs are not displayed in offense messages by default. Change
  # behavior by overriding DisplayStyleGuide, or by giving the
  # -S/--display-style-guide option.
  DisplayStyleGuide: false
  # Exclude some GitLab files
  Exclude:
    - 'vendor/**/*'
Mike Greiling's avatar
Mike Greiling committed
20
    - 'node_modules/**/*'
Sean McGivern's avatar
Sean McGivern committed
21
22
    - 'db/*'
    - 'db/fixtures/**/*'
23
24
25
26
27
28
29
30
31
    - 'tmp/**/*'
    - 'bin/**/*'
    - 'lib/backup/**/*'
    - 'lib/ci/backup/**/*'
    - 'lib/tasks/**/*'
    - 'lib/ci/migrate/**/*'
    - 'lib/email_validator.rb'
    - 'lib/gitlab/upgrader.rb'
    - 'lib/gitlab/seeder.rb'
32
    - 'generator_templates/**/*'
33

34
# Style #######################################################################
35
36

# Check indentation of private/protected visibility modifiers.
37
Style/AccessModifierIndentation:
38
  Enabled: true
39

Connor Shea's avatar
Connor Shea committed
40
41
42
43
# Check the naming of accessor methods for get_/set_.
Style/AccessorMethodName:
  Enabled: false

44
# Use alias_method instead of alias.
45
Style/Alias:
46
  EnforcedStyle: prefer_alias_method
47
  Enabled: true
48

49
# Align the elements of an array literal if they span more than one line.
50
Style/AlignArray:
51
  Enabled: true
52

53
# Align the elements of a hash literal if they span more than one line.
54
Style/AlignHash:
55
  Enabled: true
56

Douwe Maan's avatar
Douwe Maan committed
57
58
59
60
61
# Whether `and` and `or` are banned only in conditionals (conditionals)
# or completely (always).
Style/AndOr:
  Enabled: true

62
# Use `Array#join` instead of `Array#*`.
63
Style/ArrayJoin:
64
  Enabled: true
65

66
# Use only ascii symbols in comments.
67
Style/AsciiComments:
68
  Enabled: true
69

70
# Use only ascii symbols in identifiers.
71
Style/AsciiIdentifiers:
72
  Enabled: true
73

74
# Checks for uses of Module#attr.
75
Style/Attr:
76
  Enabled: true
77

78
# Avoid the use of BEGIN blocks.
79
Style/BeginBlock:
80
  Enabled: true
81

82
# Do not use block comments.
83
Style/BlockComments:
84
  Enabled: true
85

86
# Put end statement of multiline block on its own line.
87
Style/BlockEndNewline:
88
  Enabled: true
89

90
91
# Avoid using {...} for multi-line blocks (multiline chaining is # always
# ugly). Prefer {...} over do...end for single-line blocks.
92
Style/BlockDelimiters:
93
  Enabled: true
94

95
# Indentation of when in a case/when/[else/]end.
96
Style/CaseIndentation:
97
  Enabled: true
98

99
# Checks for uses of character literals.
100
Style/CharacterLiteral:
101
  Enabled: true
102

103
# Use CamelCase for classes and modules.'
104
Style/ClassAndModuleCamelCase:
105
  Enabled: true
106

107
# Checks style of children classes and modules.
108
109
110
Style/ClassAndModuleChildren:
  Enabled: false

111
# Enforces consistent use of `Object#is_a?` or `Object#kind_of?`.
112
113
114
Style/ClassCheck:
  Enabled: false

115
# Use self when defining module/class methods.
116
Style/ClassMethods:
117
  Enabled: true
118

119
# Avoid the use of class variables.
120
Style/ClassVars:
121
  Enabled: true
122

123
# Indentation of comments.
124
Style/CommentIndentation:
125
  Enabled: true
126

127
# Constants should use SCREAMING_SNAKE_CASE.
128
Style/ConstantName:
129
  Enabled: true
130

131
# Use def with parentheses when there are arguments.
132
Style/DefWithParentheses:
133
  Enabled: true
134

135
# Document classes and non-namespace modules.
136
137
138
Style/Documentation:
  Enabled: false

Douwe Maan's avatar
Douwe Maan committed
139
140
141
142
Style/DotPosition:
  Enabled: true
  EnforcedStyle: trailing

143
# Align elses and elsifs correctly.
144
Style/ElseAlignment:
145
  Enabled: true
146

147
# Use empty lines between defs.
148
149
150
Style/EmptyLineBetweenDefs:
  Enabled: false

151
# Don't use several empty lines in a row.
152
Style/EmptyLines:
153
  Enabled: true
154

155
# Keep blank lines around access modifiers.
156
Style/EmptyLinesAroundAccessModifier:
157
  Enabled: true
158

159
# Keeps track of empty lines around block bodies.
160
Style/EmptyLinesAroundBlockBody:
161
  Enabled: true
162

163
# Keeps track of empty lines around class bodies.
164
Style/EmptyLinesAroundClassBody:
165
  Enabled: true
166

167
# Keeps track of empty lines around module bodies.
168
Style/EmptyLinesAroundModuleBody:
169
  Enabled: true
170

171
# Keeps track of empty lines around method bodies.
172
Style/EmptyLinesAroundMethodBody:
173
  Enabled: true
174

175
# Avoid the use of END blocks.
176
Style/EndBlock:
177
  Enabled: true
178

179
# Use Unix-style line endings.
180
Style/EndOfLine:
181
  Enabled: true
182

183
# Favor the use of Fixnum#even? && Fixnum#odd?
184
Style/EvenOdd:
185
  Enabled: true
186

187
# Use snake_case for source file names.
188
Style/FileName:
189
190
191
  Enabled: true

# Checks for a line break before the first parameter in a multi-line method
192
# parameter definition.
193
194
Style/FirstMethodParameterLineBreak:
  Enabled: true
195

196
# Checks for flip flops.
197
Style/FlipFlop:
198
  Enabled: true
199

200
# Checks use of for or each in multiline loops.
201
Style/For:
Grzegorz Bizon's avatar
Grzegorz Bizon committed
202
  Enabled: true
203

Z.J. van de Weg's avatar
Z.J. van de Weg committed
204
205
206
# Checks if there is a magic comment to enforce string literals
Style/FrozenStringLiteralComment:
  Enabled: false
207
# Do not introduce global variables.
208
Style/GlobalVars:
209
  Enabled: true
210

211
212
# Prefer Ruby 1.9 hash syntax `{ a: 1, b: 2 }`
# over 1.8 syntax `{ :a => 1, :b => 2 }`.
213
Style/HashSyntax:
214
  Enabled: true
215

216
# Do not use if x; .... Use the ternary operator instead.
217
Style/IfWithSemicolon:
218
  Enabled: true
219

220
221
222
# Checks that conditional statements do not have an identical line at the
# end of each branch, which can validly be moved out of the conditional.
Style/IdenticalConditionalBranches:
223
  Enabled: true
224
225

# Checks the indentation of the first line of the right-hand-side of a
226
# multi-line assignment.
227
Style/IndentAssignment:
228
  Enabled: true
229
230

# Keep indentation straight.
231
Style/IndentationConsistency:
232
  Enabled: true
233

234
# Use 2 spaces for indentation.
235
Style/IndentationWidth:
236
  Enabled: true
237

238
# Use Kernel#loop for infinite loops.
239
Style/InfiniteLoop:
240
  Enabled: true
241

242
# Use lambda.call(...) instead of lambda.(...).
243
Style/LambdaCall:
244
  Enabled: true
245

246
# Comments should start with a space.
247
Style/LeadingCommentSpace:
Felipe Artur's avatar
Felipe Artur committed
248
  Enabled: true
249

250
# Checks if the method definitions have or don't have parentheses.
251
Style/MethodDefParentheses:
252
  Enabled: true
253

254
# Use the configured style when naming methods.
255
Style/MethodName:
256
  Enabled: true
257

Connor Shea's avatar
Connor Shea committed
258
259
260
261
# Checks for usage of `extend self` in modules.
Style/ModuleFunction:
  Enabled: false

Robert Speicher's avatar
Robert Speicher committed
262
263
264
265
266
267
# Checks that the closing brace in an array literal is either on the same line
# as the last array element, or a new line.
Style/MultilineArrayBraceLayout:
  Enabled: false
  EnforcedStyle: symmetrical

268
# Avoid multi-line chains of blocks.
269
Style/MultilineBlockChain:
270
  Enabled: true
271

272
# Ensures newlines after multiline block do statements.
273
Style/MultilineBlockLayout:
274
  Enabled: true
275

Robert Speicher's avatar
Robert Speicher committed
276
277
278
279
280
281
# Checks that the closing brace in a hash literal is either on the same line as
# the last hash element, or a new line.
Style/MultilineHashBraceLayout:
  Enabled: false
  EnforcedStyle: symmetrical

282
# Do not use then for multi-line if/unless.
283
Style/MultilineIfThen:
284
  Enabled: true
285

Robert Speicher's avatar
Robert Speicher committed
286
287
288
289
290
291
# Checks that the closing brace in a method call is either on the same line as
# the last method argument, or a new line.
Style/MultilineMethodCallBraceLayout:
  Enabled: false
  EnforcedStyle: symmetrical

292
293
294
295
296
# Checks indentation of method calls with the dot operator that span more than
# one line.
Style/MultilineMethodCallIndentation:
  Enabled: false

297
298
299
300
301
# Checks that the closing brace in a method definition is symmetrical with
# respect to the opening brace and the method parameters.
Style/MultilineMethodDefinitionBraceLayout:
  Enabled: false

302
# Checks indentation of binary operations that span more than one line.
303
Style/MultilineOperationIndentation:
304
305
  Enabled: true
  EnforcedStyle: indented
306

307
308
309
310
# Avoid multi-line `? :` (the ternary operator), use if/unless instead.
Style/MultilineTernaryOperator:
  Enabled: true

Douwe Maan's avatar
Douwe Maan committed
311
312
313
Style/MutableConstant:
  Enabled: true

314
# Favor unless over if for negative conditions (or control flow or).
315
Style/NegatedIf:
316
  Enabled: true
317

318
319
# Avoid using nested modifiers.
Style/NestedModifier:
320
  Enabled: true
321
322

# Use one expression per branch in a ternary operator.
323
Style/NestedTernaryOperator:
324
  Enabled: true
325

326
# Prefer x.nil? to x == nil.
327
Style/NilComparison:
328
  Enabled: true
329

330
# Checks for redundant nil checks.
331
Style/NonNilCheck:
332
  Enabled: true
333

334
# Use ! instead of not.
335
Style/Not:
336
  Enabled: true
337

338
# Add underscores to large numeric literals to improve their readability.
339
340
341
Style/NumericLiterals:
  Enabled: false

342
# Favor the ternary operator(?:) over if/then/else/end constructs.
343
Style/OneLineConditional:
344
  Enabled: true
345

346
# When defining binary operators, name the argument other.
347
Style/OpMethod:
348
  Enabled: true
349

350
# Don't use parentheses around the condition of an if/unless/while.
351
Style/ParenthesesAroundCondition:
352
  Enabled: true
353

354
355
356
357
# Checks for an obsolete RuntimeException argument in raise/fail.
Style/RedundantException:
  Enabled: true

358
359
# Checks for parentheses that seem not to serve any purpose.
Style/RedundantParentheses:
360
  Enabled: true
361
362

# Don't use semicolons to terminate expressions.
363
Style/Semicolon:
364
  Enabled: true
365

366
# Checks for proper usage of fail and raise.
367
Style/SignalException:
368
369
  EnforcedStyle: only_raise
  Enabled: true
370

371
# Use spaces after colons.
372
Style/SpaceAfterColon:
373
  Enabled: true
374

375
# Use spaces after commas.
376
Style/SpaceAfterComma:
377
  Enabled: true
378

379
380
# Do not put a space between a method name and the opening parenthesis in a
# method definition.
381
Style/SpaceAfterMethodName:
382
  Enabled: true
383

384
# Tracks redundant space after the ! operator.
385
Style/SpaceAfterNot:
386
  Enabled: true
387

388
# Use spaces after semicolons.
389
Style/SpaceAfterSemicolon:
390
  Enabled: true
391

392
393
394
395
# Use space around equals in parameter default
Style/SpaceAroundEqualsInParameterDefault:
  Enabled: true

396
397
# Use a space around keywords if appropriate.
Style/SpaceAroundKeyword:
398
  Enabled: true
399

400
401
# Use a single space around operators.
Style/SpaceAroundOperators:
402
  Enabled: true
403

404
405
# No spaces before commas.
Style/SpaceBeforeComma:
406
  Enabled: true
407

408
409
# Checks for missing space between code and a comment on the same line.
Style/SpaceBeforeComment:
410
  Enabled: true
411

412
413
# No spaces before semicolons.
Style/SpaceBeforeSemicolon:
414
  Enabled: true
415

416
# Use spaces inside hash literal braces - or don't.
417
Style/SpaceInsideHashLiteralBraces:
418
  Enabled: true
419

420
# No spaces inside range literals.
421
Style/SpaceInsideRangeLiteral:
422
  Enabled: true
423

424
425
# Checks for padding/surrounding spaces inside string interpolation.
Style/SpaceInsideStringInterpolation:
426
427
  EnforcedStyle: no_space
  Enabled: true
428
429
430

# Check for the usage of parentheses around stabby lambda arguments.
Style/StabbyLambdaParentheses:
431
432
  EnforcedStyle: require_parentheses
  Enabled: true
433
434

# Checks if uses of quotes match the configured preference.
435
436
437
Style/StringLiterals:
  Enabled: false

438
439
# Checks if configured preferred methods are used over non-preferred.
Style/StringMethods:
440
441
442
  PreferredMethods:
    intern: to_sym
  Enabled: true
443
444

# No hard tabs.
445
Style/Tab:
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
446
  Enabled: true
447

448
# Checks trailing blank lines and final newline.
449
Style/TrailingBlankLines:
450
  Enabled: true
451

452
# Checks for %W when interpolation is not needed.
453
Style/UnneededCapitalW:
454
  Enabled: true
455

456
# Checks for %q/%Q when single quotes or double quotes would do.
457
458
459
Style/UnneededPercentQ:
  Enabled: false

460
# Don't interpolate global, instance and class variables directly in strings.
461
Style/VariableInterpolation:
462
  Enabled: true
463

464
# Use the configured style when naming variables.
465
Style/VariableName:
466
467
  EnforcedStyle: snake_case
  Enabled: true
468

469
470
471
472
# Use the configured style when numbering variables.
Style/VariableNumber:
  Enabled: false

473
# Use when x then ... for one-line cases.
474
Style/WhenThen:
475
  Enabled: true
476

477
# Checks for redundant do after while or until.
478
Style/WhileUntilDo:
479
  Enabled: true
480

481
# Favor modifier while/until usage when you have a single-line body.
482
Style/WhileUntilModifier:
483
  Enabled: true
484

485
# Use %w or %W for arrays of words.
486
487
488
Style/WordArray:
  Enabled: false

489
# Metrics #####################################################################
490

491
492
# A calculated magnitude based on number of assignments,
# branches, and conditions.
493
Metrics/AbcSize:
Grzegorz Bizon's avatar
Grzegorz Bizon committed
494
  Enabled: true
495
  Max: 60
Grzegorz Bizon's avatar
Grzegorz Bizon committed
496

497
# Avoid excessive block nesting.
498
Metrics/BlockNesting:
Grzegorz Bizon's avatar
Grzegorz Bizon committed
499
500
  Enabled: true
  Max: 4
501

502
# Avoid classes longer than 100 lines of code.
503
504
505
Metrics/ClassLength:
  Enabled: false

506
507
508
509
510
511
512
# A complexity metric that is strongly correlated to the number
# of test cases needed to validate a method.
Metrics/CyclomaticComplexity:
  Enabled: true
  Max: 17

# Limit lines to 80 characters.
513
514
515
Metrics/LineLength:
  Enabled: false

516
# Avoid methods longer than 10 lines of code.
517
518
519
Metrics/MethodLength:
  Enabled: false

520
# Avoid modules longer than 100 lines of code.
521
522
523
Metrics/ModuleLength:
  Enabled: false

524
525
526
527
528
529
530
531
# Avoid parameter lists longer than three or four parameters.
Metrics/ParameterLists:
  Enabled: true
  Max: 8

# A complexity metric geared towards measuring complexity for a human reader.
Metrics/PerceivedComplexity:
  Enabled: true
Valery Sizov's avatar
Valery Sizov committed
532
  Max: 18
533

534
# Lint ########################################################################
535

536
537
538
539
540
541
542
543
544
# Checks for useless access modifiers.
Lint/UselessAccessModifier:
  Enabled: true

# Checks for attempts to use `private` or `protected` to set the visibility
# of a class method, which does not work.
Lint/IneffectiveAccessModifier:
  Enabled: false

545
546
# Checks for ambiguous operators in the first argument of a method invocation
# without parentheses.
547
Lint/AmbiguousOperator:
548
  Enabled: true
549

550
# Align block ends correctly.
551
Lint/BlockAlignment:
552
  Enabled: true
553

554
555
556
# Default values in optional keyword arguments and optional ordinal arguments
# should not refer back to the name of the argument.
Lint/CircularArgumentReference:
557
  Enabled: true
558
559

# Checks for condition placed in a confusing position relative to the keyword.
560
Lint/ConditionPosition:
561
  Enabled: true
562

563
# Check for debugger calls.
564
Lint/Debugger:
565
  Enabled: true
566

567
# Align ends corresponding to defs correctly.
568
Lint/DefEndAlignment:
569
  Enabled: true
570

571
# Check for deprecated class method calls.
572
Lint/DeprecatedClassMethods:
573
  Enabled: true
574

575
576
# Check for immutable argument given to each_with_object.
Lint/EachWithObjectArgument:
577
  Enabled: true
578
579

# Check for odd code arrangement in an else block.
580
Lint/ElseLayout:
581
  Enabled: true
582

583
# Checks for empty ensure block.
584
Lint/EmptyEnsure:
585
  Enabled: true
586

587
588
589
590
# Checks for the presence of `when` branches without a body.
Lint/EmptyWhen:
  Enabled: true

591
# Align ends correctly.
592
Lint/EndAlignment:
593
  Enabled: true
594

595
# END blocks should not be placed inside method definitions.
596
Lint/EndInMethod:
597
  Enabled: true
598

599
# Do not use return in an ensure block.
600
Lint/EnsureReturn:
601
  Enabled: true
602

603
# The use of eval represents a serious security risk.
604
Lint/Eval:
605
  Enabled: true
606

607
608
# Catches floating-point literals too large or small for Ruby to represent.
Lint/FloatOutOfRange:
609
  Enabled: true
610
611
612

# The number of parameters to format/sprint must match the fields.
Lint/FormatParameterMismatch:
613
  Enabled: true
614
615
616
617

# Checks for adjacent string literals on the same line, which could better be
# represented as a single string literal.
Lint/ImplicitStringConcatenation:
618
  Enabled: true
619
620
621

# Checks for invalid character literals with a non-escaped whitespace
# character.
622
Lint/InvalidCharacterLiteral:
623
  Enabled: true
624

625
# Checks of literals used in conditions.
626
Lint/LiteralInCondition:
627
  Enabled: true
628

629
# Checks for literals used in interpolation.
630
Lint/LiteralInInterpolation:
631
  Enabled: true
632

633
634
# Do not use nested method definitions.
Lint/NestedMethodDefinition:
635
  Enabled: true
636
637
638

# Do not omit the accumulator when calling `next` in a `reduce`/`inject` block.
Lint/NextWithoutAccumulator:
639
  Enabled: true
640
641

# Checks for method calls with a space before the opening parenthesis.
642
Lint/ParenthesesAsGroupedExpression:
643
  Enabled: true
644

645
646
647
# Checks for `rand(1)` calls. Such calls always return `0` and most likely
# a mistake.
Lint/RandOne:
648
  Enabled: true
649
650

# Use parentheses in the method call to avoid confusion about precedence.
651
Lint/RequireParentheses:
652
  Enabled: true
653

654
# Avoid rescuing the Exception class.
655
Lint/RescueException:
656
  Enabled: true
657

Connor Shea's avatar
Connor Shea committed
658
659
# Checks for the order which exceptions are rescued to avoid rescueing a less specific exception before a more specific exception.
Lint/ShadowedException:
660
661
  Enabled: false

662
663
664
665
# Checks for Object#to_s usage in string interpolation.
Lint/StringConversionInInterpolation:
  Enabled: true

666
# Do not use prefix `_` for a variable that is used.
667
Lint/UnderscorePrefixedVariableName:
668
  Enabled: true
669

670
671
672
673
674
675
676
# Checks for rubocop:disable comments that can be removed.
# Note: this cop is not disabled when disabling all cops.
# It must be explicitly disabled.
Lint/UnneededDisable:
  Enabled: false

# Unreachable code.
677
Lint/UnreachableCode:
678
  Enabled: true
679

680
# Checks for useless assignment to a local variable.
681
Lint/UselessAssignment:
682
  Enabled: true
683

684
# Checks for comparison of something with itself.
685
Lint/UselessComparison:
686
  Enabled: true
687

688
# Checks for useless `else` in `begin..end` without `rescue`.
689
Lint/UselessElseWithoutRescue:
690
  Enabled: true
691

692
# Checks for useless setter call to a local variable.
693
Lint/UselessSetterCall:
694
  Enabled: true
695

696
# Possible use of operator/literal/variable in void context.
697
Lint/Void:
698
  Enabled: true
699

700
# Performance #################################################################
701
702
703

# Use `casecmp` rather than `downcase ==`.
Performance/Casecmp:
704
  Enabled: true
705
706
707
708

# Use `str.{start,end}_with?(x, ..., y, ...)` instead of
# `str.{start,end}_with?(x, ...) || str.{start,end}_with?(y, ...)`.
Performance/DoubleStartEndWith:
709
  Enabled: true
710
711
712

# Use `strip` instead of `lstrip.rstrip`.
Performance/LstripRstrip:
Connor Shea's avatar
Connor Shea committed
713
  Enabled: true