1inherit_gem:
2  gitlab-styles:
3    - rubocop-default.yml
4
5require:
6  - ./rubocop/rubocop
7  - rubocop-rspec
8
9inherit_from:
10  <% unless ENV['REVEAL_RUBOCOP_TODO'] == '1' %>
11    <% Dir.glob('.rubocop_todo/**/*.yml').each do |rubocop_todo_yaml| %>
12  - '<%= rubocop_todo_yaml %>'
13    <% end %>
14  - '.rubocop_todo.yml'
15  <% end %>
16  - ./rubocop/rubocop-migrations.yml
17  - ./rubocop/rubocop-usage-data.yml
18  - ./rubocop/rubocop-code_reuse.yml
19
20inherit_mode:
21  merge:
22    - Include
23    - Exclude
24
25AllCops:
26  TargetRubyVersion: 2.7
27  TargetRailsVersion: 6.0
28  Exclude:
29    - 'vendor/**/*'
30    - 'node_modules/**/*'
31    - 'db/fixtures/**/*'
32    - 'db/schema.rb'
33    - 'tmp/**/*'
34    - 'bin/**/*'
35    - 'generator_templates/**/*'
36    - 'builds/**/*'
37    - 'plugins/**/*'
38    - 'file_hooks/**/*'
39    - 'workhorse/**/*'
40    - 'spec/support/*.git/**/*'  # e.g. spec/support/gitlab-git-test.git
41    - 'db/ci_migrate/*.rb'      # since the `db/ci_migrate` is a symlinked to `db/migrate`
42  # Use absolute path to avoid orphan directories with changed workspace root.
43  CacheRootDirectory: <%= Dir.getwd %>/tmp
44  MaxFilesInCache: 30000
45
46Cop/AvoidKeywordArgumentsInSidekiqWorkers:
47  Enabled: true
48  Include:
49    - 'app/workers/**/*'
50    - 'ee/app/workers/**/*'
51
52Cop/StaticTranslationDefinition:
53  Enabled: true
54  Exclude:
55    - 'spec/**/*'
56    - 'ee/spec/**/*'
57
58InternalAffairs/DeprecateCopHelper:
59  Enabled: true
60  Include:
61    - spec/rubocop/**/*.rb
62
63Lint/LastKeywordArgument:
64  Enabled: true
65  Safe: false
66
67# This cop checks whether some constant value isn't a
68# mutable literal (e.g. array or hash).
69Style/MutableConstant:
70  Enabled: true
71  Exclude:
72    - 'db/migrate/**/*'
73    - 'db/post_migrate/**/*'
74    - 'ee/db/migrate/**/*'
75    - 'ee/db/post_migrate/**/*'
76    - 'ee/db/geo/migrate/**/*'
77
78# TODO: Move this to gitlab-styles
79Style/SafeNavigation:
80  Enabled: false
81
82Style/AccessModifierDeclarations:
83  AllowModifiersOnSymbols: true
84
85# Frozen String Literal
86Style/FrozenStringLiteralComment:
87  Enabled: true
88  EnforcedStyle: always_true
89
90RSpec/FilePath:
91  Exclude:
92    - 'qa/**/*'
93    - 'spec/frontend/fixtures/*'
94    - 'ee/spec/frontend/fixtures/*'
95    - 'spec/requests/api/v3/*'
96    - 'spec/fixtures/**/*'
97
98# Configuration parameters: AllowSubject.
99RSpec/MultipleMemoizedHelpers:
100  Max: 28
101  AllowSubject: true
102  Exclude:
103    - 'spec/migrations/**/*.rb'
104    - 'spec/lib/gitlab/background_migration/populate_project_snippet_statistics_spec.rb'
105    - 'spec/lib/gitlab/background_migration/populate_finding_uuid_for_vulnerability_feedback_spec.rb'
106    - 'ee/spec/lib/ee/gitlab/background_migration/populate_uuids_for_security_findings_spec.rb'
107    - 'ee/spec/lib/gitlab/background_migration/user_mentions/create_resource_user_mention_spec.rb'
108
109Naming/FileName:
110  ExpectMatchingDefinition: true
111  CheckDefinitionPathHierarchy: false
112  Exclude:
113    - '**/*/*.builder'
114    - 'ee/bin/*'
115    - 'config.ru'
116    - 'config/**/*'
117    - 'ee/config/**/*'
118    - 'jh/config/**/*'
119    - 'db/**/*'
120    - 'ee/db/**/*'
121    - 'ee/elastic/migrate/*'
122    - 'lib/tasks/**/*.rake'
123    - 'ee/lib/tasks/**/*.rake'
124    - 'lib/generators/**/*'
125    - 'ee/lib/generators/**/*'
126    - 'scripts/**/*'
127    - 'spec/**/*'
128    - 'tooling/bin/**/*'
129    - 'ee/spec/**/*'
130    - 'jh/spec/**/*'
131    - 'qa/bin/*'
132    - 'qa/spec/**/*'
133    - 'qa/qa/specs/**/*'
134    - 'qa/tasks/**/*.rake'
135    - '**/*.ru'
136
137  IgnoreExecutableScripts: true
138  AllowedAcronyms:
139    - EE
140    - JSON
141    - LDAP
142    - SAML
143    - SSO
144    - IO
145    - HMAC
146    - QA
147    - ENV
148    - STL
149    - PDF
150    - SVG
151    - CTE
152    - DN
153    - RSA
154    - CI
155    - CD
156    - OAuth
157    - CSP
158    - CSV
159    - SCA
160    - SAN
161    - CIDR
162    - SPDX
163    - MR
164    - SSE
165    - JWT
166    - HLL
167    - GPG
168    - OTP
169    - GID
170    - AR
171    - RSpec
172    - ECDSA
173    - ED25519
174    - GitLab
175    - JavaScript
176    - VSCode
177    # default ones:
178    - CLI
179    - DSL
180    - ACL
181    - API
182    - ASCII
183    - CPU
184    - CSS
185    - DNS
186    - EOF
187    - GUID
188    - HTML
189    - HTTP
190    - HTTPS
191    - ID
192    - IP
193    - JSON
194    - LHS
195    - QPS
196    - RAM
197    - RHS
198    - RPC
199    - SLA
200    - SMTP
201    - SQL
202    - SSH
203    - TCP
204    - TLS
205    - TTL
206    - UDP
207    - UI
208    - UID
209    - UUID
210    - URI
211    - URL
212    - UTF8
213    - VM
214    - XML
215    - XMPP
216    - XSRF
217    - XSS
218    - GRPC
219
220Rails/ApplicationRecord:
221  Enabled: true
222  Exclude:
223    # Models in database migrations should not subclass from ApplicationRecord
224    # as they need to be as decoupled from application code as possible
225    - db/**/*.rb
226    - lib/gitlab/background_migration/**/*.rb
227    - ee/lib/ee/gitlab/background_migration/**/*.rb
228    - lib/gitlab/database/**/*.rb
229    - spec/**/*.rb
230    - ee/db/**/*.rb
231    - ee/spec/**/*.rb
232
233Cop/DefaultScope:
234  Enabled: true
235
236Rails/FindBy:
237  Enabled: true
238  Include:
239    - 'ee/app/**/*.rb'
240    - 'ee/lib/**/*.rb'
241    - 'spec/**/*.rb'
242    - 'ee/spec/**/*.rb'
243
244# This is currently exiting with a rubocop exception error and should be
245# resolved hopefully a future update
246# An error occurred while Rails/UniqueValidationWithoutIndex cop was inspecting
247# app/models/abuse_report.rb:15:2.
248# To see the complete backtrace run rubocop -d.
249Rails/UniqueValidationWithoutIndex:
250  Enabled: false
251
252# GitLab ###################################################################
253
254Gitlab/ModuleWithInstanceVariables:
255  Enable: true
256  Exclude:
257    # We ignore Rails helpers right now because it's hard to workaround it
258    - app/helpers/**/*_helper.rb
259    - ee/app/helpers/**/*_helper.rb
260    # We ignore Rails mailers right now because it's hard to workaround it
261    - app/mailers/emails/**/*.rb
262    - ee/**/emails/**/*.rb
263    # We ignore spec helpers because it usually doesn't matter
264    - spec/support/**/*.rb
265    - features/steps/**/*.rb
266
267Gitlab/ConstGetInheritFalse:
268  Enabled: true
269  Exclude:
270    - 'qa/bin/*'
271
272Gitlab/ChangeTimezone:
273  Enabled: true
274  Exclude:
275    - config/initializers/time_zone.rb
276
277Gitlab/HTTParty:
278  Enabled: true
279  Exclude:
280    - 'spec/**/*'
281    - 'ee/spec/**/*'
282
283Gitlab/Json:
284  Enabled: true
285  Exclude:
286    - 'qa/**/*'
287    - 'scripts/**/*'
288    - 'tooling/rspec_flaky/**/*'
289    - 'lib/quality/**/*'
290    - 'tooling/danger/**/*'
291
292Gitlab/AvoidUploadedFileFromParams:
293  Enabled: true
294  Exclude:
295    - 'lib/gitlab/middleware/multipart.rb'
296    - 'spec/**/*'
297    - 'ee/spec/**/*'
298
299GitlabSecurity/PublicSend:
300  Enabled: true
301  Exclude:
302    - 'config/**/*'
303    - 'db/**/*'
304    - 'features/**/*'
305    - 'lib/**/*.rake'
306    - 'qa/**/*'
307    - 'spec/**/*'
308    - 'ee/db/**/*'
309    - 'ee/lib/**/*.rake'
310    - 'ee/spec/**/*'
311
312Database/MultipleDatabases:
313  Enabled: true
314  Include:
315    - 'app/**/*.rb'
316    - 'ee/app/**/*.rb'
317    - 'lib/**/*.rb'
318    - 'ee/lib/**/*.rb'
319    - 'spec/**/*.rb'
320    - 'ee/spec/**/*.rb'
321  Exclude:
322    - 'ee/db/**/*.rb'
323    - 'spec/migrations/**/*.rb'
324    - 'lib/gitlab/background_migration/**/*.rb'
325    - 'spec/lib/gitlab/background_migration/**/*.rb'
326    - 'spec/lib/gitlab/database/**/*.rb'
327
328Gitlab/DuplicateSpecLocation:
329  Enabled: true
330
331Gitlab/PolicyRuleBoolean:
332  Enabled: true
333  Include:
334    - 'app/policies/**/*'
335    - 'ee/app/policies/**/*'
336
337Cop/InjectEnterpriseEditionModule:
338  Enabled: true
339  Exclude:
340    - 'spec/**/*'
341    - 'ee/spec/**/*'
342
343Style/ReturnNil:
344  Enabled: true
345
346# It isn't always safe to replace `=~` with `.match?`, especially when there are
347# nil values on the left hand side
348Performance/RegexpMatch:
349  Enabled: false
350
351Cop/ActiveRecordAssociationReload:
352  Enabled: true
353  Exclude:
354    - 'spec/**/*'
355    - 'ee/spec/**/*'
356
357Cop/ActiveModelErrorsDirectManipulation:
358  Enabled: true
359
360Gitlab/AvoidFeatureGet:
361  Enabled: true
362
363RSpec/TimecopFreeze:
364  Enabled: true
365  AutoCorrect: true
366  Include:
367    - 'spec/**/*.rb'
368    - 'ee/spec/**/*.rb'
369    - 'qa/spec/**/*.rb'
370
371RSpec/TimecopTravel:
372  Enabled: true
373  AutoCorrect: true
374  Include:
375    - 'spec/**/*.rb'
376    - 'ee/spec/**/*.rb'
377    - 'qa/spec/**/*.rb'
378
379RSpec/WebMockEnable:
380  Enabled: true
381  Include:
382    - 'spec/**/*.rb'
383    - 'ee/spec/**/*.rb'
384  Exclude:
385    - 'spec/support/webmock.rb'
386
387Naming/PredicateName:
388  Enabled: true
389  Exclude:
390    - 'spec/**/*'
391    - 'ee/spec/**/*'
392
393RSpec/FactoriesInMigrationSpecs:
394  Enabled: true
395  Include:
396    - 'spec/migrations/**/*.rb'
397    - 'ee/spec/migrations/**/*.rb'
398    - 'spec/lib/gitlab/background_migration/**/*.rb'
399    - 'spec/lib/ee/gitlab/background_migration/**/*.rb'
400    - 'ee/spec/lib/ee/gitlab/background_migration/**/*.rb'
401
402Cop/IncludeSidekiqWorker:
403  Enabled: true
404  Exclude:
405    - 'spec/**/*'
406    - 'ee/spec/**/*'
407
408Gitlab/Union:
409  Enabled: true
410  Exclude:
411    - 'spec/**/*'
412    - 'ee/spec/**/*'
413
414API/Base:
415  Enabled: true
416  Include:
417    - 'lib/**/api/**/*.rb'
418    - 'ee/**/api/**/*.rb'
419
420API/GrapeArrayMissingCoerce:
421  Enabled: true
422  Include:
423    - 'lib/**/api/**/*.rb'
424    - 'ee/**/api/**/*.rb'
425
426Cop/SidekiqOptionsQueue:
427  Enabled: true
428  Exclude:
429    - 'spec/**/*.rb'
430    - 'ee/spec/**/*.rb'
431
432Graphql/ResolverType:
433  Enabled: true
434  Exclude:
435    - 'app/graphql/resolvers/base_resolver.rb'
436  Include:
437    - 'app/graphql/resolvers/**/*'
438    - 'ee/app/graphql/resolvers/**/*'
439
440Graphql/AuthorizeTypes:
441  Enabled: true
442  Include:
443    - 'app/graphql/types/**/*'
444    - 'ee/app/graphql/types/**/*'
445  Exclude:
446    - 'spec/**/*.rb'
447    - 'ee/spec/**/*.rb'
448
449Graphql/GIDExpectedType:
450  Enabled: true
451  Include:
452    - 'app/graphql/**/*'
453    - 'ee/app/graphql/**/*'
454  Exclude:
455    - 'spec/**/*.rb'
456    - 'ee/spec/**/*.rb'
457
458Graphql/IDType:
459  Enabled: true
460  Include:
461    - 'app/graphql/**/*'
462    - 'ee/app/graphql/**/*'
463
464Graphql/JSONType:
465  Enabled: true
466  Include:
467    - 'app/graphql/**/*'
468    - 'ee/app/graphql/**/*'
469  Exclude:
470    - 'spec/**/*.rb'
471    - 'ee/spec/**/*.rb'
472
473Graphql/OldTypes:
474  Enabled: true
475  Include:
476    - 'app/graphql/**/*'
477    - 'ee/app/graphql/**/*'
478    - 'spec/graphql/**/*'
479    - 'spec/requests/api/graphql/**/*'
480    - 'ee/spec/graphql/**/*'
481    - 'ee/spec/requests/api/graphql/**/*'
482
483RSpec/EnvAssignment:
484  Enable: true
485  Include:
486    - 'spec/**/*.rb'
487    - 'ee/spec/**/*.rb'
488  Exclude:
489    - 'spec/**/fast_spec_helper.rb'
490    - 'ee/spec/**/fast_spec_helper.rb'
491    - 'spec/**/spec_helper.rb'
492    - 'ee/spec/**/spec_helper.rb'
493RSpec/BeSuccessMatcher:
494  Enabled: true
495  Include:
496    - 'spec/controllers/**/*'
497    - 'ee/spec/controllers/**/*'
498    - 'spec/support/shared_examples/controllers/**/*'
499    - 'ee/spec/support/shared_examples/controllers/**/*'
500    - 'spec/support/controllers/**/*'
501    - 'ee/spec/support/controllers/**/*'
502
503Scalability/FileUploads:
504  Enabled: true
505  Include:
506    - 'lib/api/**/*.rb'
507    - 'ee/lib/api/**/*.rb'
508
509Graphql/Descriptions:
510  Enabled: true
511  AutoCorrect: true
512  Include:
513    - 'app/graphql/**/*'
514    - 'ee/app/graphql/**/*'
515
516# Cops for upgrade to gitlab-styles 3.1.0
517RSpec/ImplicitSubject:
518  Enabled: false
519
520# WIP See https://gitlab.com/gitlab-org/gitlab/-/issues/211580
521RSpec/LeakyConstantDeclaration:
522  Enabled: true
523  Exclude:
524    - 'spec/db/schema_spec.rb'
525    - 'spec/lib/feature_spec.rb'
526    - 'spec/lib/gitlab/config/entry/simplifiable_spec.rb'
527    - 'spec/lib/gitlab/quick_actions/dsl_spec.rb'
528    - 'spec/lib/marginalia_spec.rb'
529    - 'spec/mailers/notify_spec.rb'
530    - 'spec/models/concerns/batch_destroy_dependent_associations_spec.rb'
531    - 'spec/models/concerns/bulk_insert_safe_spec.rb'
532    - 'spec/models/concerns/bulk_insertable_associations_spec.rb'
533    - 'spec/models/concerns/triggerable_hooks_spec.rb'
534    - 'spec/models/repository_spec.rb'
535    - 'spec/services/clusters/applications/check_installation_progress_service_spec.rb'
536    - 'spec/support/shared_examples/quick_actions/issuable/issuable_quick_actions_shared_examples.rb'
537
538RSpec/EmptyLineAfterHook:
539  Enabled: false
540
541RSpec/HooksBeforeExamples:
542  Enabled: false
543
544RSpec/EmptyLineAfterExample:
545  Enabled: false
546
547RSpec/Be:
548  Enabled: false
549
550RSpec/DescribedClass:
551  Enabled: false
552
553RSpec/SharedExamples:
554  Enabled: false
555
556RSpec/EmptyLineAfterExampleGroup:
557  Enabled: false
558
559RSpec/ReceiveNever:
560  Enabled: false
561
562RSpec/MissingExampleGroupArgument:
563  Enabled: false
564
565RSpec/UnspecifiedException:
566  Enabled: false
567
568RSpec/HaveGitlabHttpStatus:
569  Enabled: true
570  Exclude:
571    - 'spec/support/matchers/have_gitlab_http_status.rb'
572  Include:
573    - 'spec/**/*'
574    - 'ee/spec/**/*'
575
576Style/MultilineWhenThen:
577  Enabled: false
578
579# We use EnforcedStyle of comparison here due to it being better
580# performing code as seen in https://gitlab.com/gitlab-org/gitlab/-/merge_requests/36221#note_375659681
581Style/NumericPredicate:
582  EnforcedStyle: comparison
583
584Style/FloatDivision:
585  Enabled: false
586
587Cop/BanCatchThrow:
588  Enabled: true
589
590Performance/ReadlinesEach:
591  Enabled: true
592
593Performance/ChainArrayAllocation:
594  Enabled: true
595  Include:
596    - 'lib/gitlab/import_export/**/*'
597    - 'ee/lib/gitlab/import_export/**/*'
598    - 'ee/lib/ee/gitlab/import_export/**/*'
599
600Rails/TimeZone:
601  Enabled: true
602  EnforcedStyle: 'flexible'
603  Include:
604    - 'app/controllers/**/*'
605    - 'app/services/**/*'
606    - 'lib/**/*'
607    - 'spec/controllers/**/*'
608    - 'spec/services/**/*'
609    - 'spec/lib/**/*'
610    - 'ee/app/controllers/**/*'
611    - 'ee/app/services/**/*'
612    - 'ee/spec/controllers/**/*'
613    - 'ee/spec/services/**/*'
614    - 'app/models/**/*'
615    - 'spec/models/**/*'
616    - 'ee/app/models/**/*'
617    - 'ee/spec/models/**/*'
618    - 'app/workers/**/*'
619    - 'spec/workers/**/*'
620    - 'ee/app/workers/**/*'
621    - 'ee/spec/workers/**/*'
622    - 'ee/lib/**/*'
623    - 'ee/spec/lib/**/*'
624
625# WIP: See https://gitlab.com/gitlab-org/gitlab/-/issues/220040
626Rails/SaveBang:
627  Enabled: true
628  AllowImplicitReturn: false
629  AllowedReceivers: ['ActionDispatch::TestRequest']
630  Include:
631    - 'spec/**/*.rb'
632    - 'ee/spec/**/*.rb'
633    - 'qa/spec/**/*.rb'
634    - 'qa/qa/specs/**/*.rb'
635  Exclude:
636  - spec/models/wiki_page/**/*
637  - spec/models/wiki_page_spec.rb
638
639Cop/PutProjectRoutesUnderScope:
640  Include:
641    - 'config/routes/project.rb'
642    - 'ee/config/routes/project.rb'
643
644Cop/PutGroupRoutesUnderScope:
645  Include:
646    - 'config/routes/group.rb'
647    - 'ee/config/routes/group.rb'
648
649Migration/ComplexIndexesRequireName:
650  Exclude:
651    - !ruby/regexp /\Adb\/(post_)?migrate\/201.*\.rb\z/
652    - !ruby/regexp /\Adb\/(post_)?migrate\/20200[1-7].*\.rb\z/
653
654Migration/ReferToIndexByName:
655  Exclude:
656    - !ruby/regexp /\Adb\/(post_)?migrate\/201.*\.rb\z/
657    - !ruby/regexp /\Adb\/(post_)?migrate\/20200[1-7].*\.rb\z/
658    - !ruby/regexp /\Aee\/db\/geo\/(post_)?migrate\/201.*\.rb\z/
659
660Migration/CreateTableWithForeignKeys:
661  # Disable this cop for all the existing migrations
662  Exclude:
663    - !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/
664
665Migration/PreventIndexCreation:
666  Exclude:
667    - !ruby/regexp /\Adb\/(post_)?migrate\/201.*\.rb\z/
668    - !ruby/regexp /\Adb\/(post_)?migrate\/2020.*\.rb\z/
669    - !ruby/regexp /\Adb\/(post_)?migrate\/20210[1-6].*\.rb\z/
670
671Gitlab/RailsLogger:
672  Exclude:
673    - 'spec/**/*.rb'
674    - 'ee/spec/**/*.rb'
675
676# WIP See https://gitlab.com/gitlab-org/gitlab/-/issues/267606
677FactoryBot/InlineAssociation:
678  Include:
679    - 'spec/factories/**/*.rb'
680    - 'ee/spec/factories/**/*.rb'
681
682# WIP: https://gitlab.com/gitlab-org/gitlab/-/issues/321982
683Gitlab/NamespacedClass:
684  Exclude:
685    - 'config/**/*.rb'
686    - 'db/**/*.rb'
687    - 'ee/bin/**/*'
688    - 'ee/db/**/*.rb'
689    - 'ee/elastic/**/*.rb'
690    - 'scripts/**/*'
691    - 'spec/migrations/**/*.rb'
692
693Lint/HashCompareByIdentity:
694  Enabled: true
695
696Lint/RedundantSafeNavigation:
697  Enabled: true
698
699Style/ClassEqualityComparison:
700  Enabled: true
701
702# WIP See https://gitlab.com/gitlab-org/gitlab/-/issues/207950
703Cop/UserAdmin:
704  Enabled: true
705  Exclude:
706    - 'app/controllers/admin/sessions_controller.rb'
707    - 'app/controllers/concerns/enforces_admin_authentication.rb'
708    - 'app/policies/base_policy.rb'
709    - 'lib/gitlab/auth/current_user_mode.rb'
710    - 'spec/**/*.rb'
711    - 'ee/spec/**/*.rb'
712
713# See https://gitlab.com/gitlab-org/gitlab/-/issues/327495
714Style/RegexpLiteral:
715  Enabled: false
716
717Style/RegexpLiteralMixedPreserve:
718  Enabled: true
719  SupportedStyles:
720    - slashes
721    - percent_r
722    - mixed
723    - mixed_preserve
724  EnforcedStyle: mixed_preserve
725
726RSpec/TopLevelDescribePath:
727  Exclude:
728    - 'spec/fixtures/**/*.rb'
729    - 'ee/spec/fixtures/**/*.rb'
730
731QA/SelectorUsage:
732  Enabled: true
733  Include:
734    - 'spec/**/*.rb'
735    - 'ee/spec/**/*.rb'
736  Exclude:
737    - 'spec/rubocop/**/*_spec.rb'
738
739QA/DuplicateTestcaseLink:
740  # this cop is executed in static-analysis.gitlab-ci.yml since it cannot be run in parallel
741  Enabled: false
742
743Performance/ActiveRecordSubtransactions:
744  Exclude:
745    - 'spec/**/*.rb'
746    - 'ee/spec/**/*.rb'
747
748Performance/ActiveRecordSubtransactionMethods:
749  Exclude:
750    - 'spec/**/*.rb'
751    - 'ee/spec/**/*.rb'
752