.rubocop.yml 19.3 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:
8
  TargetRubyVersion: 2.1
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/**/*'
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

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
Style/EmptyLinesAroundClassBody:
156
  Enabled: true
157

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

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:
193
  Enabled: true
194

Z.J. van de Weg's avatar
Z.J. van de Weg committed
195 196 197
# Checks if there is a magic comment to enforce string literals
Style/FrozenStringLiteralComment:
  Enabled: false
198
# Do not introduce global variables.
199
Style/GlobalVars:
200
  Enabled: true
201

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

207
# Do not use if x; .... Use the ternary operator instead.
208
Style/IfWithSemicolon:
209
  Enabled: true
210

211 212 213
# 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:
214
  Enabled: true
215 216

# Checks the indentation of the first line of the right-hand-side of a
217
# multi-line assignment.
218
Style/IndentAssignment:
219
  Enabled: true
220 221

# Keep indentation straight.
222
Style/IndentationConsistency:
223
  Enabled: true
224

225
# Use 2 spaces for indentation.
226
Style/IndentationWidth:
227
  Enabled: true
228

229
# Use Kernel#loop for infinite loops.
230
Style/InfiniteLoop:
231
  Enabled: true
232

233
# Use lambda.call(...) instead of lambda.(...).
234
Style/LambdaCall:
235
  Enabled: true
236

237
# Comments should start with a space.
238
Style/LeadingCommentSpace:
Felipe Artur's avatar
Felipe Artur committed
239
  Enabled: true
240

241
# Checks if the method definitions have or don't have parentheses.
242
Style/MethodDefParentheses:
243
  Enabled: true
244

245
# Use the configured style when naming methods.
246
Style/MethodName:
247
  Enabled: true
248

249 250 251 252
# Checks for usage of `extend self` in modules.
Style/ModuleFunction:
  Enabled: false

Robert Speicher's avatar
Robert Speicher committed
253 254 255 256 257 258
# 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

259
# Avoid multi-line chains of blocks.
260
Style/MultilineBlockChain:
261
  Enabled: true
262

263
# Ensures newlines after multiline block do statements.
264
Style/MultilineBlockLayout:
265
  Enabled: true
266

Robert Speicher's avatar
Robert Speicher committed
267 268 269 270 271 272
# 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

273
# Do not use then for multi-line if/unless.
274
Style/MultilineIfThen:
275
  Enabled: true
276

Robert Speicher's avatar
Robert Speicher committed
277 278 279 280 281 282
# 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

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

288 289 290 291 292
# 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

293
# Checks indentation of binary operations that span more than one line.
294
Style/MultilineOperationIndentation:
295 296
  Enabled: true
  EnforcedStyle: indented
297

298 299 300 301
# Avoid multi-line `? :` (the ternary operator), use if/unless instead.
Style/MultilineTernaryOperator:
  Enabled: true

302
# Favor unless over if for negative conditions (or control flow or).
303
Style/NegatedIf:
304
  Enabled: true
305

306 307
# Avoid using nested modifiers.
Style/NestedModifier:
308
  Enabled: true
309 310

# Use one expression per branch in a ternary operator.
311
Style/NestedTernaryOperator:
312
  Enabled: true
313

314
# Prefer x.nil? to x == nil.
315
Style/NilComparison:
316
  Enabled: true
317

318
# Checks for redundant nil checks.
319
Style/NonNilCheck:
320
  Enabled: true
321

322
# Use ! instead of not.
323
Style/Not:
324
  Enabled: true
325

326
# Add underscores to large numeric literals to improve their readability.
327 328 329
Style/NumericLiterals:
  Enabled: false

330
# Favor the ternary operator(?:) over if/then/else/end constructs.
331
Style/OneLineConditional:
332
  Enabled: true
333

334
# When defining binary operators, name the argument other.
335
Style/OpMethod:
336
  Enabled: true
337

338
# Don't use parentheses around the condition of an if/unless/while.
339
Style/ParenthesesAroundCondition:
340
  Enabled: true
341

342 343
# Checks for parentheses that seem not to serve any purpose.
Style/RedundantParentheses:
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 378 379
# Use space around equals in parameter default
Style/SpaceAroundEqualsInParameterDefault:
  Enabled: true

380 381
# Use a space around keywords if appropriate.
Style/SpaceAroundKeyword:
382
  Enabled: true
383

384 385
# Use a single space around operators.
Style/SpaceAroundOperators:
386
  Enabled: true
387

388 389
# No spaces before commas.
Style/SpaceBeforeComma:
390
  Enabled: true
391

392 393
# Checks for missing space between code and a comment on the same line.
Style/SpaceBeforeComment:
394
  Enabled: true
395

396 397
# No spaces before semicolons.
Style/SpaceBeforeSemicolon:
398
  Enabled: true
399

400
# Use spaces inside hash literal braces - or don't.
401
Style/SpaceInsideHashLiteralBraces:
402
  Enabled: true
403

404
# No spaces inside range literals.
405
Style/SpaceInsideRangeLiteral:
406
  Enabled: true
407

408 409
# Checks for padding/surrounding spaces inside string interpolation.
Style/SpaceInsideStringInterpolation:
410 411
  EnforcedStyle: no_space
  Enabled: true
412 413 414

# Check for the usage of parentheses around stabby lambda arguments.
Style/StabbyLambdaParentheses:
415 416
  EnforcedStyle: require_parentheses
  Enabled: true
417 418

# Checks if uses of quotes match the configured preference.
419 420 421
Style/StringLiterals:
  Enabled: false

422 423
# Checks if configured preferred methods are used over non-preferred.
Style/StringMethods:
424 425 426
  PreferredMethods:
    intern: to_sym
  Enabled: true
427 428

# No hard tabs.
429
Style/Tab:
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
430
  Enabled: true
431

432
# Checks trailing blank lines and final newline.
433
Style/TrailingBlankLines:
434
  Enabled: true
435

436
# Checks for %W when interpolation is not needed.
437
Style/UnneededCapitalW:
438
  Enabled: true
439

440
# Checks for %q/%Q when single quotes or double quotes would do.
441 442 443
Style/UnneededPercentQ:
  Enabled: false

444
# Don't interpolate global, instance and class variables directly in strings.
445
Style/VariableInterpolation:
446
  Enabled: true
447

448
# Use the configured style when naming variables.
449
Style/VariableName:
450 451
  EnforcedStyle: snake_case
  Enabled: true
452

453 454 455 456
# Use the configured style when numbering variables.
Style/VariableNumber:
  Enabled: false

457
# Use when x then ... for one-line cases.
458
Style/WhenThen:
459
  Enabled: true
460

461
# Checks for redundant do after while or until.
462
Style/WhileUntilDo:
463
  Enabled: true
464

465
# Favor modifier while/until usage when you have a single-line body.
466
Style/WhileUntilModifier:
467
  Enabled: true
468

469
# Use %w or %W for arrays of words.
470 471 472 473 474
Style/WordArray:
  Enabled: false

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

475 476
# A calculated magnitude based on number of assignments,
# branches, and conditions.
477
Metrics/AbcSize:
Grzegorz Bizon's avatar
Grzegorz Bizon committed
478
  Enabled: true
479
  Max: 60
Grzegorz Bizon's avatar
Grzegorz Bizon committed
480

481
# Avoid excessive block nesting.
482
Metrics/BlockNesting:
Grzegorz Bizon's avatar
Grzegorz Bizon committed
483 484
  Enabled: true
  Max: 4
485

486
# Avoid classes longer than 100 lines of code.
487 488 489
Metrics/ClassLength:
  Enabled: false

490 491 492 493 494 495 496
# 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.
497 498 499
Metrics/LineLength:
  Enabled: false

500
# Avoid methods longer than 10 lines of code.
501 502 503
Metrics/MethodLength:
  Enabled: false

504
# Avoid modules longer than 100 lines of code.
505 506 507
Metrics/ModuleLength:
  Enabled: false

508 509 510 511 512 513 514 515
# 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
516
  Max: 18
517 518


519 520
#################### Lint ################################

521 522 523 524 525 526 527 528 529
# 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

530 531
# Checks for ambiguous operators in the first argument of a method invocation
# without parentheses.
532
Lint/AmbiguousOperator:
533
  Enabled: true
534

535
# Align block ends correctly.
536
Lint/BlockAlignment:
537
  Enabled: true
538

539 540 541
# Default values in optional keyword arguments and optional ordinal arguments
# should not refer back to the name of the argument.
Lint/CircularArgumentReference:
542
  Enabled: true
543 544

# Checks for condition placed in a confusing position relative to the keyword.
545
Lint/ConditionPosition:
546
  Enabled: true
547

548
# Check for debugger calls.
549
Lint/Debugger:
550
  Enabled: true
551

552
# Align ends corresponding to defs correctly.
553
Lint/DefEndAlignment:
554
  Enabled: true
555

556
# Check for deprecated class method calls.
557
Lint/DeprecatedClassMethods:
558
  Enabled: true
559

560 561
# Check for immutable argument given to each_with_object.
Lint/EachWithObjectArgument:
562
  Enabled: true
563 564

# Check for odd code arrangement in an else block.
565
Lint/ElseLayout:
566
  Enabled: true
567

568
# Checks for empty ensure block.
569
Lint/EmptyEnsure:
570
  Enabled: true
571

572
# Align ends correctly.
573
Lint/EndAlignment:
574
  Enabled: true
575

576
# END blocks should not be placed inside method definitions.
577
Lint/EndInMethod:
578
  Enabled: true
579

580
# Do not use return in an ensure block.
581
Lint/EnsureReturn:
582
  Enabled: true
583

584
# The use of eval represents a serious security risk.
585
Lint/Eval:
586
  Enabled: true
587

588 589
# Catches floating-point literals too large or small for Ruby to represent.
Lint/FloatOutOfRange:
590
  Enabled: true
591 592 593

# The number of parameters to format/sprint must match the fields.
Lint/FormatParameterMismatch:
594
  Enabled: true
595 596 597 598

# Checks for adjacent string literals on the same line, which could better be
# represented as a single string literal.
Lint/ImplicitStringConcatenation:
599
  Enabled: true
600 601 602

# Checks for invalid character literals with a non-escaped whitespace
# character.
603
Lint/InvalidCharacterLiteral:
604
  Enabled: true
605

606
# Checks of literals used in conditions.
607
Lint/LiteralInCondition:
608
  Enabled: true
609

610
# Checks for literals used in interpolation.
611
Lint/LiteralInInterpolation:
612
  Enabled: true
613

614 615
# Do not use nested method definitions.
Lint/NestedMethodDefinition:
616
  Enabled: true
617 618 619

# Do not omit the accumulator when calling `next` in a `reduce`/`inject` block.
Lint/NextWithoutAccumulator:
620
  Enabled: true
621 622

# Checks for method calls with a space before the opening parenthesis.
623
Lint/ParenthesesAsGroupedExpression:
624
  Enabled: true
625

626 627 628
# Checks for `rand(1)` calls. Such calls always return `0` and most likely
# a mistake.
Lint/RandOne:
629
  Enabled: true
630 631

# Use parentheses in the method call to avoid confusion about precedence.
632
Lint/RequireParentheses:
633
  Enabled: true
634

635
# Avoid rescuing the Exception class.
636
Lint/RescueException:
637
  Enabled: true
638

Connor Shea's avatar
Connor Shea committed
639 640
# Checks for the order which exceptions are rescued to avoid rescueing a less specific exception before a more specific exception.
Lint/ShadowedException:
641 642
  Enabled: false

643 644 645 646
# Checks for Object#to_s usage in string interpolation.
Lint/StringConversionInInterpolation:
  Enabled: true

647
# Do not use prefix `_` for a variable that is used.
648
Lint/UnderscorePrefixedVariableName:
649
  Enabled: true
650

651 652 653 654 655 656 657
# 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.
658
Lint/UnreachableCode:
659
  Enabled: true
660

661
# Checks for useless assignment to a local variable.
662
Lint/UselessAssignment:
663
  Enabled: true
664

665
# Checks for comparison of something with itself.
666
Lint/UselessComparison:
667
  Enabled: true
668

669
# Checks for useless `else` in `begin..end` without `rescue`.
670
Lint/UselessElseWithoutRescue:
671
  Enabled: true
672

673
# Checks for useless setter call to a local variable.
674
Lint/UselessSetterCall:
675
  Enabled: true
676

677
# Possible use of operator/literal/variable in void context.
678
Lint/Void:
679
  Enabled: true
680

681 682 683 684 685

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

# Use `casecmp` rather than `downcase ==`.
Performance/Casecmp:
686
  Enabled: true
687 688 689 690

# Use `str.{start,end}_with?(x, ..., y, ...)` instead of
# `str.{start,end}_with?(x, ...) || str.{start,end}_with?(y, ...)`.
Performance/DoubleStartEndWith:
691
  Enabled: true
692 693 694

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

# Use `Range#cover?` instead of `Range#include?`.
Performance/RangeInclude:
699
  Enabled: true
700 701 702

# Use `sort` instead of `sort_by { |x| x }`.
Performance/RedundantSortBy:
703
  Enabled: true
704 705 706 707

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

710 711 712 713
# 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:
714
  Enabled: true
715 716 717

# Checks for `.times.map` calls.
Performance/TimesMap:
718
  Enabled: true
719 720


721 722
##################### Rails ##################################

723 724 725 726 727
# Enables Rails cops.
Rails:
  Enabled: true

# Enforces consistent use of action filter methods.
728
Rails/ActionFilter:
729
  Enabled: true
730
  EnforcedStyle: action
731

732 733
# Checks the correct usage of date aware methods, such as `Date.today`,
# `Date.current`, etc.
Gabriel Mazetto's avatar
Gabriel Mazetto committed
734 735 736
Rails/Date:
  Enabled: false

737 738
# Prefer delegate method for delegations.
Rails/Delegate:
739 740
  Enabled: false

741 742
# Prefer `find_by` over `where.first`.
Rails/FindBy:
743
  Enabled: true
744 745 746

# Prefer `all.find_each` over `all.find`.
Rails/FindEach:
747
  Enabled: true
748

749
# Prefer has_many :through to has_and_belongs_to_many.
750
Rails/HasAndBelongsToMany:
751
  Enabled: true
752

753
# Checks for calls to puts, print, etc.
754
Rails/Output:
755
  Enabled: true
756

757 758
# Checks for incorrect grammar when using methods like `3.day.ago`.
Rails/PluralizationGrammar:
759
  Enabled: true
760 761

# Checks for `read_attribute(:attr)` and `write_attribute(:attr, val)`.
762 763 764
Rails/ReadWriteAttribute:
  Enabled: false

765
# Checks the arguments of ActiveRecord scopes.
766
Rails/ScopeArgs:
767
  Enabled: true
768

Robert Speicher's avatar
Robert Speicher committed
769 770
##################### RSpec ##################################

771
# Check that instances are not being stubbed globally.
Robert Speicher's avatar
Robert Speicher committed