.rubocop.yml 18.9 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
8
9
10
11
12
13
14
15
16
17
18
19
AllCops:
  TargetRubyVersion: 2.1
  # Cop names are not displayed in offense messages by default. Change behavior
  # 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/**/*'
Sean McGivern's avatar
Sean McGivern committed
20
21
    - 'db/*'
    - 'db/fixtures/**/*'
22
23
24
25
26
27
28
29
30
    - 'tmp/**/*'
    - 'bin/**/*'
    - 'lib/backup/**/*'
    - 'lib/ci/backup/**/*'
    - 'lib/tasks/**/*'
    - 'lib/ci/migrate/**/*'
    - 'lib/email_validator.rb'
    - 'lib/gitlab/upgrader.rb'
    - 'lib/gitlab/seeder.rb'
31
    - 'generator_templates/**/*'
32
33
34
35
36


##################### Style ##################################

# 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

57
# Use `Array#join` instead of `Array#*`.
58
Style/ArrayJoin:
59
  Enabled: true
60

61
# Use only ascii symbols in comments.
62
Style/AsciiComments:
63
  Enabled: true
64

65
# Use only ascii symbols in identifiers.
66
Style/AsciiIdentifiers:
67
  Enabled: true
68

69
# Checks for uses of Module#attr.
70
Style/Attr:
71
  Enabled: true
72

73
# Avoid the use of BEGIN blocks.
74
Style/BeginBlock:
75
  Enabled: true
76

77
# Do not use block comments.
78
Style/BlockComments:
79
  Enabled: true
80

81
# Put end statement of multiline block on its own line.
82
Style/BlockEndNewline:
83
  Enabled: true
84

85
86
# Avoid using {...} for multi-line blocks (multiline chaining is # always
# ugly). Prefer {...} over do...end for single-line blocks.
87
Style/BlockDelimiters:
88
  Enabled: true
89

90
# Indentation of when in a case/when/[else/]end.
91
Style/CaseIndentation:
92
  Enabled: true
93

94
# Checks for uses of character literals.
95
Style/CharacterLiteral:
96
  Enabled: true
97

98
# Use CamelCase for classes and modules.'
99
Style/ClassAndModuleCamelCase:
100
  Enabled: true
101

102
# Checks style of children classes and modules.
103
104
105
Style/ClassAndModuleChildren:
  Enabled: false

106
# Enforces consistent use of `Object#is_a?` or `Object#kind_of?`.
107
108
109
Style/ClassCheck:
  Enabled: false

110
# Use self when defining module/class methods.
111
Style/ClassMethods:
112
  Enabled: true
113

114
# Avoid the use of class variables.
115
Style/ClassVars:
116
  Enabled: true
117

118
# Indentation of comments.
119
Style/CommentIndentation:
120
  Enabled: true
121

122
# Constants should use SCREAMING_SNAKE_CASE.
123
Style/ConstantName:
124
  Enabled: true
125

126
# Use def with parentheses when there are arguments.
127
Style/DefWithParentheses:
128
  Enabled: true
129

130
# Document classes and non-namespace modules.
131
132
133
Style/Documentation:
  Enabled: false

134
# Align elses and elsifs correctly.
135
Style/ElseAlignment:
136
  Enabled: true
137

138
# Use empty lines between defs.
139
140
141
Style/EmptyLineBetweenDefs:
  Enabled: false

142
# Don't use several empty lines in a row.
143
Style/EmptyLines:
144
  Enabled: true
145

146
# Keep blank lines around access modifiers.
147
Style/EmptyLinesAroundAccessModifier:
148
  Enabled: true
149

150
# Keeps track of empty lines around block bodies.
151
Style/EmptyLinesAroundBlockBody:
152
  Enabled: true
153

154
# Keeps track of empty lines around class bodies.
155
156
157
Style/EmptyLinesAroundClassBody:
  Enabled: false

158
# Keeps track of empty lines around module bodies.
159
160
161
Style/EmptyLinesAroundModuleBody:
  Enabled: false

162
# Keeps track of empty lines around method bodies.
163
Style/EmptyLinesAroundMethodBody:
164
  Enabled: true
165

166
# Avoid the use of END blocks.
167
Style/EndBlock:
168
  Enabled: true
169

170
# Use Unix-style line endings.
171
Style/EndOfLine:
172
  Enabled: true
173

174
# Favor the use of Fixnum#even? && Fixnum#odd?
175
Style/EvenOdd:
176
  Enabled: true
177

178
# Use snake_case for source file names.
179
Style/FileName:
180
181
182
  Enabled: true

# Checks for a line break before the first parameter in a multi-line method
183
# parameter definition.
184
185
Style/FirstMethodParameterLineBreak:
  Enabled: true
186

187
# Checks for flip flops.
188
Style/FlipFlop:
189
  Enabled: true
190

191
# Checks use of for or each in multiline loops.
192
Style/For:
Grzegorz Bizon's avatar
Grzegorz Bizon committed
193
  Enabled: true
194

195
# Do not introduce global variables.
196
Style/GlobalVars:
197
  Enabled: true
198

199
200
# Prefer Ruby 1.9 hash syntax `{ a: 1, b: 2 }`
# over 1.8 syntax `{ :a => 1, :b => 2 }`.
201
Style/HashSyntax:
202
  Enabled: true
203

204
# Do not use if x; .... Use the ternary operator instead.
205
Style/IfWithSemicolon:
206
  Enabled: true
207

208
209
210
# 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:
211
  Enabled: true
212
213

# Checks the indentation of the first line of the right-hand-side of a
214
# multi-line assignment.
215
Style/IndentAssignment:
216
  Enabled: true
217
218

# Keep indentation straight.
219
Style/IndentationConsistency:
220
  Enabled: true
221

222
# Use 2 spaces for indentation.
223
Style/IndentationWidth:
224
  Enabled: true
225

226
# Use Kernel#loop for infinite loops.
227
Style/InfiniteLoop:
228
  Enabled: true
229

230
# Use lambda.call(...) instead of lambda.(...).
231
Style/LambdaCall:
232
  Enabled: true
233

234
# Comments should start with a space.
235
Style/LeadingCommentSpace:
Felipe Artur's avatar
Felipe Artur committed
236
  Enabled: true
237

238
# Checks if the method definitions have or don't have parentheses.
239
Style/MethodDefParentheses:
240
  Enabled: true
241

242
# Use the configured style when naming methods.
243
Style/MethodName:
244
  Enabled: true
245

Connor Shea's avatar
Connor Shea committed
246
247
248
249
# Checks for usage of `extend self` in modules.
Style/ModuleFunction:
  Enabled: false

Robert Speicher's avatar
Robert Speicher committed
250
251
252
253
254
255
# 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

256
# Avoid multi-line chains of blocks.
257
Style/MultilineBlockChain:
258
  Enabled: true
259

260
# Ensures newlines after multiline block do statements.
261
Style/MultilineBlockLayout:
262
  Enabled: true
263

Robert Speicher's avatar
Robert Speicher committed
264
265
266
267
268
269
# 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

270
# Do not use then for multi-line if/unless.
271
Style/MultilineIfThen:
272
  Enabled: true
273

Robert Speicher's avatar
Robert Speicher committed
274
275
276
277
278
279
# 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

280
281
282
283
284
# Checks indentation of method calls with the dot operator that span more than
# one line.
Style/MultilineMethodCallIndentation:
  Enabled: false

285
286
287
288
289
# 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

290
# Checks indentation of binary operations that span more than one line.
291
292
293
Style/MultilineOperationIndentation:
  Enabled: false

294
295
296
297
# Avoid multi-line `? :` (the ternary operator), use if/unless instead.
Style/MultilineTernaryOperator:
  Enabled: true

298
# Favor unless over if for negative conditions (or control flow or).
299
Style/NegatedIf:
300
  Enabled: true
301

302
303
# Avoid using nested modifiers.
Style/NestedModifier:
304
  Enabled: true
305
306

# Use one expression per branch in a ternary operator.
307
Style/NestedTernaryOperator:
308
  Enabled: true
309

310
# Prefer x.nil? to x == nil.
311
Style/NilComparison:
312
  Enabled: true
313

314
# Checks for redundant nil checks.
315
Style/NonNilCheck:
316
  Enabled: true
317

318
# Use ! instead of not.
319
Style/Not:
320
  Enabled: true
321

322
# Add underscores to large numeric literals to improve their readability.
323
324
325
Style/NumericLiterals:
  Enabled: false

326
# Favor the ternary operator(?:) over if/then/else/end constructs.
327
Style/OneLineConditional:
328
  Enabled: true
329

330
# When defining binary operators, name the argument other.
331
Style/OpMethod:
332
  Enabled: true
333

334
# Don't use parentheses around the condition of an if/unless/while.
335
Style/ParenthesesAroundCondition:
336
  Enabled: true
337

338
339
# Checks for parentheses that seem not to serve any purpose.
Style/RedundantParentheses:
340
  Enabled: true
341
342

# Don't use return where it's not required.
343
Style/RedundantReturn:
344
  Enabled: true
345

346
# Don't use semicolons to terminate expressions.
347
Style/Semicolon:
348
  Enabled: true
349

350
# Checks for proper usage of fail and raise.
351
Style/SignalException:
352
353
  EnforcedStyle: only_raise
  Enabled: true
354

355
# Use spaces after colons.
356
Style/SpaceAfterColon:
357
  Enabled: true
358

359
# Use spaces after commas.
360
Style/SpaceAfterComma:
361
  Enabled: true
362

363
364
# Do not put a space between a method name and the opening parenthesis in a
# method definition.
365
Style/SpaceAfterMethodName:
366
  Enabled: true
367

368
# Tracks redundant space after the ! operator.
369
Style/SpaceAfterNot:
370
  Enabled: true
371

372
# Use spaces after semicolons.
373
Style/SpaceAfterSemicolon:
374
  Enabled: true
375

376
377
# Use a space around keywords if appropriate.
Style/SpaceAroundKeyword:
378
  Enabled: true
379

380
381
# Use a single space around operators.
Style/SpaceAroundOperators:
382
  Enabled: true
383

384
385
# No spaces before commas.
Style/SpaceBeforeComma:
386
  Enabled: true
387

388
389
# Checks for missing space between code and a comment on the same line.
Style/SpaceBeforeComment:
390
  Enabled: true
391

392
393
# No spaces before semicolons.
Style/SpaceBeforeSemicolon:
394
  Enabled: true
395

396
# Use spaces inside hash literal braces - or don't.
397
Style/SpaceInsideHashLiteralBraces:
398
  Enabled: true
399

400
# No spaces inside range literals.
401
Style/SpaceInsideRangeLiteral:
402
  Enabled: true
403

404
405
# Checks for padding/surrounding spaces inside string interpolation.
Style/SpaceInsideStringInterpolation:
406
407
  EnforcedStyle: no_space
  Enabled: true
408
409
410

# Check for the usage of parentheses around stabby lambda arguments.
Style/StabbyLambdaParentheses:
411
412
  EnforcedStyle: require_parentheses
  Enabled: true
413
414

# Checks if uses of quotes match the configured preference.
415
416
417
Style/StringLiterals:
  Enabled: false

418
419
# Checks if configured preferred methods are used over non-preferred.
Style/StringMethods:
420
421
422
  PreferredMethods:
    intern: to_sym
  Enabled: true
423
424

# No hard tabs.
425
Style/Tab:
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
426
  Enabled: true
427

428
# Checks trailing blank lines and final newline.
429
Style/TrailingBlankLines:
430
  Enabled: true
431

432
# Checks for %W when interpolation is not needed.
433
Style/UnneededCapitalW:
434
  Enabled: true
435

436
# Checks for %q/%Q when single quotes or double quotes would do.
437
438
439
Style/UnneededPercentQ:
  Enabled: false

440
# Don't interpolate global, instance and class variables directly in strings.
441
Style/VariableInterpolation:
442
  Enabled: true
443

444
# Use the configured style when naming variables.
445
Style/VariableName:
446
447
  EnforcedStyle: snake_case
  Enabled: true
448

449
# Use when x then ... for one-line cases.
450
Style/WhenThen:
451
  Enabled: true
452

453
# Checks for redundant do after while or until.
454
Style/WhileUntilDo:
455
  Enabled: true
456

457
# Favor modifier while/until usage when you have a single-line body.
458
Style/WhileUntilModifier:
459
  Enabled: true
460

461
# Use %w or %W for arrays of words.
462
463
464
465
466
Style/WordArray:
  Enabled: false

#################### Metrics ################################

467
468
# A calculated magnitude based on number of assignments,
# branches, and conditions.
469
Metrics/AbcSize:
Grzegorz Bizon's avatar
Grzegorz Bizon committed
470
  Enabled: true
471
  Max: 60
Grzegorz Bizon's avatar
Grzegorz Bizon committed
472

473
# Avoid excessive block nesting.
474
Metrics/BlockNesting:
Grzegorz Bizon's avatar
Grzegorz Bizon committed
475
476
  Enabled: true
  Max: 4
477

478
# Avoid classes longer than 100 lines of code.
479
480
481
Metrics/ClassLength:
  Enabled: false

482
483
484
485
486
487
488
# 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.
489
490
491
Metrics/LineLength:
  Enabled: false

492
# Avoid methods longer than 10 lines of code.
493
494
495
Metrics/MethodLength:
  Enabled: false

496
# Avoid modules longer than 100 lines of code.
497
498
499
Metrics/ModuleLength:
  Enabled: false

500
501
502
503
504
505
506
507
# 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
508
  Max: 18
509
510


511
512
#################### Lint ################################

513
514
515
516
517
518
519
520
521
# 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

522
523
# Checks for ambiguous operators in the first argument of a method invocation
# without parentheses.
524
Lint/AmbiguousOperator:
525
  Enabled: true
526

527
# Align block ends correctly.
528
Lint/BlockAlignment:
529
  Enabled: true
530

531
532
533
# Default values in optional keyword arguments and optional ordinal arguments
# should not refer back to the name of the argument.
Lint/CircularArgumentReference:
534
  Enabled: true
535
536

# Checks for condition placed in a confusing position relative to the keyword.
537
Lint/ConditionPosition:
538
  Enabled: true
539

540
# Check for debugger calls.
541
Lint/Debugger:
542
  Enabled: true
543

544
# Align ends corresponding to defs correctly.
545
Lint/DefEndAlignment:
546
  Enabled: true
547

548
# Check for deprecated class method calls.
549
Lint/DeprecatedClassMethods:
550
  Enabled: true
551

552
553
# Check for immutable argument given to each_with_object.
Lint/EachWithObjectArgument:
554
  Enabled: true
555
556

# Check for odd code arrangement in an else block.
557
Lint/ElseLayout:
558
  Enabled: true
559

560
# Checks for empty ensure block.
561
Lint/EmptyEnsure:
562
  Enabled: true
563

564
# Align ends correctly.
565
Lint/EndAlignment:
566
  Enabled: true
567

568
# END blocks should not be placed inside method definitions.
569
Lint/EndInMethod:
570
  Enabled: true
571

572
# Do not use return in an ensure block.
573
Lint/EnsureReturn:
574
  Enabled: true
575

576
# The use of eval represents a serious security risk.
577
Lint/Eval:
578
  Enabled: true
579

580
581
# Catches floating-point literals too large or small for Ruby to represent.
Lint/FloatOutOfRange:
582
  Enabled: true
583
584
585

# The number of parameters to format/sprint must match the fields.
Lint/FormatParameterMismatch:
586
  Enabled: true
587
588
589
590

# Checks for adjacent string literals on the same line, which could better be
# represented as a single string literal.
Lint/ImplicitStringConcatenation:
591
  Enabled: true
592
593
594

# Checks for invalid character literals with a non-escaped whitespace
# character.
595
Lint/InvalidCharacterLiteral:
596
  Enabled: true
597

598
# Checks of literals used in conditions.
599
Lint/LiteralInCondition:
600
  Enabled: true
601

602
# Checks for literals used in interpolation.
603
Lint/LiteralInInterpolation:
604
  Enabled: true
605

606
607
# Do not use nested method definitions.
Lint/NestedMethodDefinition:
608
  Enabled: true
609
610
611

# Do not omit the accumulator when calling `next` in a `reduce`/`inject` block.
Lint/NextWithoutAccumulator:
612
  Enabled: true
613
614

# Checks for method calls with a space before the opening parenthesis.
615
Lint/ParenthesesAsGroupedExpression:
616
  Enabled: true
617

618
619
620
# Checks for `rand(1)` calls. Such calls always return `0` and most likely
# a mistake.
Lint/RandOne:
621
  Enabled: true
622
623

# Use parentheses in the method call to avoid confusion about precedence.
624
Lint/RequireParentheses:
625
  Enabled: true
626

627
# Avoid rescuing the Exception class.
628
Lint/RescueException:
629
  Enabled: true
630

Connor Shea's avatar
Connor Shea committed
631
632
# Checks for the order which exceptions are rescued to avoid rescueing a less specific exception before a more specific exception.
Lint/ShadowedException:
633
634
  Enabled: false

635
# Do not use prefix `_` for a variable that is used.
636
Lint/UnderscorePrefixedVariableName:
637
  Enabled: true
638

639
640
641
642
643
644
645
# 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.
646
Lint/UnreachableCode:
647
  Enabled: true
648

649
# Checks for useless assignment to a local variable.
650
Lint/UselessAssignment:
651
  Enabled: true
652

653
# Checks for comparison of something with itself.
654
Lint/UselessComparison:
655
  Enabled: true
656

657
# Checks for useless `else` in `begin..end` without `rescue`.
658
Lint/UselessElseWithoutRescue:
659
  Enabled: true
660

661
# Checks for useless setter call to a local variable.
662
Lint/UselessSetterCall:
663
  Enabled: true
664

665
# Possible use of operator/literal/variable in void context.
666
Lint/Void:
667
  Enabled: true
668

669
670
671
672
673

##################### Performance ############################

# Use `casecmp` rather than `downcase ==`.
Performance/Casecmp:
674
  Enabled: true
675
676
677
678

# Use `str.{start,end}_with?(x, ..., y, ...)` instead of
# `str.{start,end}_with?(x, ...) || str.{start,end}_with?(y, ...)`.
Performance/DoubleStartEndWith:
679
  Enabled: true
680
681
682

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

# Use `Range#cover?` instead of `Range#include?`.
Performance/RangeInclude:
687
  Enabled: true
688
689
690

# Use `sort` instead of `sort_by { |x| x }`.
Performance/RedundantSortBy:
691
  Enabled: true
692
693
694
695

# Use `start_with?` instead of a regex match anchored to the beginning of a
# string.
Performance/StartWith:
696
  Enabled: true
697

698
699
700
701
# Use `tr` instead of `gsub` when you are replacing the same number of
# characters. Use `delete` instead of `gsub` when you are deleting
# characters.
Performance/StringReplacement:
702
  Enabled: true
703
704
705

# Checks for `.times.map` calls.
Performance/TimesMap:
706
  Enabled: true
707
708


709
710
##################### Rails ##################################

711
712
713
714
715
# Enables Rails cops.
Rails:
  Enabled: true

# Enforces consistent use of action filter methods.
716
Rails/ActionFilter:
717
  Enabled: true
718
  EnforcedStyle: action
719

720
721
# Checks the correct usage of date aware methods, such as `Date.today`,
# `Date.current`, etc.
Gabriel Mazetto's avatar
Gabriel Mazetto committed