.rubocop.yml 11.5 KB
Newer Older
Rémy Coutable's avatar
Rémy Coutable committed
1 2 3
inherit_gem:
  gitlab-styles:
    - rubocop-default.yml
Robert Speicher's avatar
Robert Speicher committed
4

5 6 7
require:
  - ./rubocop/rubocop
  - rubocop-rspec
Z.J. van de Weg's avatar
Z.J. van de Weg committed
8

9 10 11
inherit_from:
  - .rubocop_todo.yml
  - ./rubocop/rubocop-migrations.yml
12
  - ./rubocop/rubocop-usage-data.yml
13

Tan Le's avatar
Tan Le committed
14 15 16 17
inherit_mode:
  merge:
    - Include

18
AllCops:
19
  TargetRubyVersion: 2.6
Doug Stull's avatar
Doug Stull committed
20
  TargetRailsVersion: 6.0
21 22
  Exclude:
    - 'vendor/**/*'
23
    - 'node_modules/**/*'
Sean McGivern's avatar
Sean McGivern committed
24
    - 'db/fixtures/**/*'
25 26
    - 'db/schema.rb'
    - 'ee/db/geo/schema.rb'
27 28
    - 'tmp/**/*'
    - 'bin/**/*'
29
    - 'generator_templates/**/*'
30
    - 'builds/**/*'
31
    - 'plugins/**/*'
32
    - 'file_hooks/**/*'
Lin Jen-Shin's avatar
Lin Jen-Shin committed
33
  CacheRootDirectory: tmp
34
  MaxFilesInCache: 18000
35

36 37 38 39 40 41
Cop/AvoidKeywordArgumentsInSidekiqWorkers:
  Enabled: true
  Include:
    - 'app/workers/**/*'
    - 'ee/app/workers/**/*'

42 43 44 45 46 47
Cop/StaticTranslationDefinition:
  Enabled: true
  Exclude:
    - 'spec/**/*'
    - 'ee/spec/**/*'

48 49 50 51 52 53 54 55 56 57 58
# This cop checks whether some constant value isn't a
# mutable literal (e.g. array or hash).
Style/MutableConstant:
  Enabled: true
  Exclude:
    - 'db/migrate/**/*'
    - 'db/post_migrate/**/*'
    - 'ee/db/migrate/**/*'
    - 'ee/db/post_migrate/**/*'
    - 'ee/db/geo/migrate/**/*'

59 60 61 62
# TODO: Move this to gitlab-styles
Style/SafeNavigation:
  Enabled: false

63 64 65
Style/AccessModifierDeclarations:
  AllowModifiersOnSymbols: true

gfyoung's avatar
gfyoung committed
66 67 68 69 70 71 72 73 74 75 76 77
# Frozen String Literal
Style/FrozenStringLiteralComment:
  Enabled: true
  Exclude:
    - 'config.ru'
    - 'Dangerfile'
    - 'Gemfile'
    - 'Rakefile'
    - 'app/views/**/*'
    - 'config/**/*'
    - 'danger/**/*'
    - 'db/**/*'
Robert Speicher's avatar
Robert Speicher committed
78 79
    - 'ee/db/**/*'
    - 'ee/lib/tasks/**/*'
80
    - 'lib/tasks/**/*'
gfyoung's avatar
gfyoung committed
81 82 83 84
    - 'qa/**/*'
    - 'rubocop/**/*'
    - 'scripts/**/*'

85 86 87
RSpec/FilePath:
  Exclude:
    - 'qa/**/*'
88 89
    - 'spec/frontend/fixtures/*'
    - 'ee/spec/frontend/fixtures/*'
90 91
    - 'spec/requests/api/v3/*'

92 93 94
Naming/FileName:
  ExpectMatchingDefinition: true
  Exclude:
95 96
    - 'db/**/*'
    - 'ee/db/**/*'
97 98 99 100 101 102
    - 'spec/**/*'
    - 'features/**/*'
    - 'ee/spec/**/*'
    - 'qa/spec/**/*'
    - 'qa/qa/specs/**/*'
    - 'qa/bin/*'
103
    - 'ee/bin/*'
104
    - 'config/**/*'
105
    - 'ee/config/**/*'
106
    - 'lib/generators/**/*'
Mark Chao's avatar
Mark Chao committed
107 108
    - 'locale/unfound_translations.rb'
    - 'ee/locale/unfound_translations.rb'
109
    - 'ee/lib/generators/**/*'
Sanad Liaquat's avatar
Sanad Liaquat committed
110 111
    - 'qa/qa/scenario/test/integration/ldap_no_tls.rb'
    - 'qa/qa/scenario/test/integration/ldap_tls.rb'
Sanad Liaquat's avatar
Sanad Liaquat committed
112

113 114 115 116 117
  IgnoreExecutableScripts: true
  AllowedAcronyms:
    - EE
    - JSON
    - LDAP
Sanad Liaquat's avatar
Sanad Liaquat committed
118
    - SAML
Robert Speicher's avatar
Robert Speicher committed
119
    - SSO
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
    - IO
    - HMAC
    - QA
    - ENV
    - STL
    - PDF
    - SVG
    - CTE
    - DN
    - RSA
    - CI
    - CD
    - OAuth
    # default ones:
    - 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
174
    - GRPC
175

176 177 178 179 180 181 182
Rails/ApplicationRecord:
  Enabled: true
  Exclude:
    # Models in database migrations should not subclass from ApplicationRecord
    # as they need to be as decoupled from application code as possible
    - db/**/*.rb
    - lib/gitlab/background_migration/**/*.rb
183
    - ee/lib/ee/gitlab/background_migration/**/*.rb
184 185 186 187 188
    - lib/gitlab/database/**/*.rb
    - spec/**/*.rb
    - ee/db/**/*.rb
    - ee/spec/**/*.rb

Nick Thomas's avatar
Nick Thomas committed
189 190 191
Cop/DefaultScope:
  Enabled: true

Tan Le's avatar
Tan Le committed
192 193 194 195 196 197 198 199
Rails/FindBy:
  Enabled: true
  Include:
    - 'ee/app/**/*.rb'
    - 'ee/lib/**/*.rb'
    - 'spec/**/*.rb'
    - 'ee/spec/**/*.rb'

Doug Stull's avatar
Doug Stull committed
200 201 202 203 204 205 206 207
# This is currently exiting with a rubocop exception error and should be
# resolved hopefully a future update
# An error occurred while Rails/UniqueValidationWithoutIndex cop was inspecting
# app/models/abuse_report.rb:15:2.
# To see the complete backtrace run rubocop -d.
Rails/UniqueValidationWithoutIndex:
  Enabled: false

208
# GitLab ###################################################################
209 210 211 212 213

Gitlab/ModuleWithInstanceVariables:
  Enable: true
  Exclude:
    # We ignore Rails helpers right now because it's hard to workaround it
Lin Jen-Shin's avatar
Lin Jen-Shin committed
214
    - app/helpers/**/*_helper.rb
215
    - ee/app/helpers/**/*_helper.rb
216
    # We ignore Rails mailers right now because it's hard to workaround it
Lin Jen-Shin's avatar
Lin Jen-Shin committed
217
    - app/mailers/emails/**/*.rb
218
    - ee/**/emails/**/*.rb
219 220 221
    # We ignore spec helpers because it usually doesn't matter
    - spec/support/**/*.rb
    - features/steps/**/*.rb
222

223 224 225 226 227
Gitlab/ConstGetInheritFalse:
  Enabled: true
  Exclude:
    - 'qa/bin/*'

228 229 230 231 232
Gitlab/ChangeTimezone:
  Enabled: true
  Exclude:
    - config/initializers/time_zone.rb

233 234
Gitlab/HTTParty:
  Enabled: true
235 236 237
  Exclude:
    - 'spec/**/*'
    - 'ee/spec/**/*'
238

Robert May's avatar
Robert May committed
239
Gitlab/Json:
Robert May's avatar
Robert May committed
240
  Enabled: true
Robert May's avatar
Robert May committed
241 242 243 244
  Exclude:
    - 'db/**/*'
    - 'qa/**/*'
    - 'scripts/**/*'
245
    - 'lib/rspec_flaky/**/*'
246
    - 'lib/quality/**/*'
247
    - 'lib/gitlab/danger/**/*'
Robert May's avatar
Robert May committed
248

249 250 251 252 253 254 255
Gitlab/AvoidUploadedFileFromParams:
  Enabled: true
  Exclude:
    - 'lib/gitlab/middleware/multipart.rb'
    - 'spec/**/*'
    - 'ee/spec/**/*'

256 257 258 259 260 261 262 263 264 265 266 267
GitlabSecurity/PublicSend:
  Enabled: true
  Exclude:
    - 'config/**/*'
    - 'db/**/*'
    - 'features/**/*'
    - 'lib/**/*.rake'
    - 'qa/**/*'
    - 'spec/**/*'
    - 'ee/db/**/*'
    - 'ee/lib/**/*.rake'
    - 'ee/spec/**/*'
268

269
Gitlab/DuplicateSpecLocation:
270
  Enabled: true
271

272 273 274 275 276
Cop/InjectEnterpriseEditionModule:
  Enabled: true
  Exclude:
    - 'spec/**/*'
    - 'ee/spec/**/*'
277 278 279

Style/ReturnNil:
  Enabled: true
280 281 282 283 284

# It isn't always safe to replace `=~` with `.match?`, especially when there are
# nil values on the left hand side
Performance/RegexpMatch:
  Enabled: false
285

Doug Stull's avatar
Doug Stull committed
286
Cop/ActiveRecordAssociationReload:
287 288 289 290
  Enabled: true
  Exclude:
    - 'spec/**/*'
    - 'ee/spec/**/*'
291

292 293 294
Gitlab/AvoidFeatureGet:
  Enabled: true

295
RSpec/TimecopFreeze:
296
  Enabled: true
297 298 299 300 301 302
  AutoCorrect: true
  Include:
    - 'spec/**/*.rb'
    - 'ee/spec/**/*.rb'
    - 'qa/spec/**/*.rb'

Simon Knox's avatar
Simon Knox committed
303 304 305 306 307 308
Naming/PredicateName:
  Enabled: true
  Exclude:
    - 'spec/**/*'
    - 'ee/spec/**/*'

309 310 311 312 313 314
RSpec/FactoriesInMigrationSpecs:
  Enabled: true
  Include:
    - 'spec/migrations/**/*.rb'
    - 'ee/spec/migrations/**/*.rb'
    - 'spec/lib/gitlab/background_migration/**/*.rb'
315 316
    - 'spec/lib/ee/gitlab/background_migration/**/*.rb'
    - 'ee/spec/lib/ee/gitlab/background_migration/**/*.rb'
317 318 319 320 321 322 323 324 325 326 327 328 329

Cop/IncludeSidekiqWorker:
  Enabled: true
  Exclude:
    - 'spec/**/*'
    - 'ee/spec/**/*'

Gitlab/Union:
  Enabled: true
  Exclude:
    - 'spec/**/*'
    - 'ee/spec/**/*'

Stan Hu's avatar
Stan Hu committed
330 331 332 333 334 335 336 337 338 339 340 341
API/GrapeAPIInstance:
  Enabled: true
  Include:
    - 'lib/**/api/**/*.rb'
    - 'ee/**/api/**/*.rb'

API/GrapeArrayMissingCoerce:
  Enabled: true
  Include:
    - 'lib/**/api/**/*.rb'
    - 'ee/**/api/**/*.rb'

342 343 344 345 346 347 348 349
Cop/SidekiqOptionsQueue:
  Enabled: true
  Exclude:
    - 'spec/**/*.rb'
    - 'ee/spec/**/*.rb'

Graphql/AuthorizeTypes:
  Enabled: true
350 351 352
  Include:
    - 'app/graphql/types/**/*'
    - 'ee/app/graphql/types/**/*'
353 354 355 356
  Exclude:
    - 'spec/**/*.rb'
    - 'ee/spec/**/*.rb'

357 358 359
Graphql/JSONType:
  Enabled: true
  Include:
360 361
    - 'app/graphql/**/*'
    - 'ee/app/graphql/**/*'
362 363 364 365
  Exclude:
    - 'spec/**/*.rb'
    - 'ee/spec/**/*.rb'

366 367 368 369 370 371 372 373 374 375
RSpec/EnvAssignment:
  Enable: true
  Include:
    - 'spec/**/*.rb'
    - 'ee/spec/**/*.rb'
  Exclude:
    - 'spec/**/fast_spec_helper.rb'
    - 'ee/spec/**/fast_spec_helper.rb'
    - 'spec/**/spec_helper.rb'
    - 'ee/spec/**/spec_helper.rb'
376 377 378 379 380 381 382 383
RSpec/BeSuccessMatcher:
  Enabled: true
  Include:
    - 'spec/controllers/**/*'
    - 'ee/spec/controllers/**/*'
    - 'spec/support/shared_examples/controllers/**/*'
    - 'ee/spec/support/shared_examples/controllers/**/*'
    - 'spec/support/controllers/**/*'
384
    - 'ee/spec/support/controllers/**/*'
385

386 387 388 389 390
Scalability/FileUploads:
  Enabled: true
  Include:
    - 'lib/api/**/*.rb'
    - 'ee/lib/api/**/*.rb'
391 392 393 394 395 396

Graphql/Descriptions:
  Enabled: true
  Include:
    - 'app/graphql/**/*'
    - 'ee/app/graphql/**/*'
397 398 399

RSpec/AnyInstanceOf:
  Enabled: false
400 401 402 403 404

# Cops for upgrade to gitlab-styles 3.1.0
RSpec/ImplicitSubject:
  Enabled: false

405
# WIP See https://gitlab.com/gitlab-org/gitlab/-/issues/211580
Ryan Cobb's avatar
Ryan Cobb committed
406 407 408
RSpec/LeakyConstantDeclaration:
  Enabled: true
  Exclude:
409 410 411 412 413 414 415 416 417 418 419 420 421
    - 'spec/db/schema_spec.rb'
    - 'spec/lib/feature_spec.rb'
    - 'spec/lib/gitlab/config/entry/simplifiable_spec.rb'
    - 'spec/lib/gitlab/quick_actions/dsl_spec.rb'
    - 'spec/lib/marginalia_spec.rb'
    - 'spec/mailers/notify_spec.rb'
    - 'spec/models/concerns/batch_destroy_dependent_associations_spec.rb'
    - 'spec/models/concerns/bulk_insert_safe_spec.rb'
    - 'spec/models/concerns/bulk_insertable_associations_spec.rb'
    - 'spec/models/concerns/triggerable_hooks_spec.rb'
    - 'spec/models/repository_spec.rb'
    - 'spec/services/clusters/applications/check_installation_progress_service_spec.rb'
    - 'spec/support/shared_examples/quick_actions/issuable/issuable_quick_actions_shared_examples.rb'
Ryan Cobb's avatar
Ryan Cobb committed
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
RSpec/EmptyLineAfterHook:
  Enabled: false

RSpec/HooksBeforeExamples:
  Enabled: false

RSpec/EmptyLineAfterExample:
  Enabled: false

RSpec/Be:
  Enabled: false

RSpec/DescribedClass:
  Enabled: false

RSpec/SharedExamples:
  Enabled: false

RSpec/EmptyLineAfterExampleGroup:
  Enabled: false

RSpec/ReceiveNever:
  Enabled: false

RSpec/MissingExampleGroupArgument:
  Enabled: false

RSpec/UnspecifiedException:
  Enabled: false

453
RSpec/HaveGitlabHttpStatus:
454
  Enabled: true
455 456
  Exclude:
    - 'spec/support/matchers/have_gitlab_http_status.rb'
457
  Include:
458 459
    - 'spec/**/*'
    - 'ee/spec/**/*'
460

461 462 463
Style/MultilineWhenThen:
  Enabled: false

464 465 466 467 468
# We use EnforcedStyle of comparison here due to it being better
# performing code as seen in https://gitlab.com/gitlab-org/gitlab/-/merge_requests/36221#note_375659681
Style/NumericPredicate:
  EnforcedStyle: comparison

469
Style/FloatDivision:
470
  Enabled: false
Nick Thomas's avatar
Nick Thomas committed
471 472 473

Cop/BanCatchThrow:
  Enabled: true
474 475 476

Performance/ReadlinesEach:
  Enabled: true
477

478 479 480 481 482 483
Performance/ChainArrayAllocation:
  Enabled: true
  Include:
    - 'lib/gitlab/import_export/**/*'
    - 'ee/lib/gitlab/import_export/**/*'
    - 'ee/lib/ee/gitlab/import_export/**/*'
484 485 486 487 488

Rails/TimeZone:
  Enabled: true
  EnforcedStyle: 'flexible'
  Include:
489
    - 'app/controllers/**/*'
490
    - 'app/services/**/*'
491
    - 'lib/**/*'
492
    - 'spec/controllers/**/*'
493
    - 'spec/services/**/*'
494
    - 'spec/lib/**/*'
495
    - 'ee/app/controllers/**/*'
496
    - 'ee/app/services/**/*'
497
    - 'ee/spec/controllers/**/*'
498
    - 'ee/spec/services/**/*'
499 500 501 502
    - 'app/models/**/*'
    - 'spec/models/**/*'
    - 'ee/app/models/**/*'
    - 'ee/spec/models/**/*'
503 504 505 506
    - 'app/workers/**/*'
    - 'spec/workers/**/*'
    - 'ee/app/workers/**/*'
    - 'ee/spec/workers/**/*'
507 508
    - 'ee/lib/**/*'
    - 'ee/spec/lib/**/*'
509 510 511 512

# WIP: See https://gitlab.com/gitlab-org/gitlab/-/issues/220040
Rails/SaveBang:
  Enabled: true
513 514
  AllowImplicitReturn: false
  AllowedReceivers: ['ActionDispatch::TestRequest']
515 516 517 518 519
  Include:
    - 'spec/**/*.rb'
    - 'ee/spec/**/*.rb'
    - 'qa/spec/**/*.rb'
    - 'qa/qa/specs/**/*.rb'
520 521 522 523 524 525 526 527 528 529

Cop/PutProjectRoutesUnderScope:
  Include:
    - 'config/routes/project.rb'
    - 'ee/config/routes/project.rb'

Cop/PutGroupRoutesUnderScope:
  Include:
    - 'config/routes/group.rb'
    - 'ee/config/routes/group.rb'
530 531 532 533 534

Migration/ComplexIndexesRequireName:
  Exclude:
    - !ruby/regexp /\Adb\/(post_)?migrate\/201.*\.rb\z/
    - !ruby/regexp /\Adb\/(post_)?migrate\/20200[1-7].*\.rb\z/
535 536 537 538 539 540

Migration/ReferToIndexByName:
  Exclude:
    - !ruby/regexp /\Adb\/(post_)?migrate\/201.*\.rb\z/
    - !ruby/regexp /\Adb\/(post_)?migrate\/20200[1-7].*\.rb\z/
    - !ruby/regexp /\Aee\/db\/geo\/(post_)?migrate\/201.*\.rb\z/
541 542 543 544 545

Migration/CreateTableWithForeignKeys:
  # Disable this cop for all the existing migrations
  Exclude:
    - !ruby/regexp /\Adb\/(?:post_)?migrate\/(?:201[0-9]\d+|20200[0-8][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9])_.+\.rb\z/
546 547 548 549 550

Gitlab/RailsLogger:
  Exclude:
    - 'spec/**/*.rb'
    - 'ee/spec/**/*.rb'