gitlab/.rubocop.yml

746 lines
16 KiB
YAML
Raw Permalink Normal View History

inherit_gem:
gitlab-styles:
- rubocop-default.yml
require:
- ./rubocop/rubocop
- rubocop-rspec
inherit_from:
<% unless ENV['REVEAL_RUBOCOP_TODO'] == '1' %>
- '.rubocop_manual_todo.yml'
- '.rubocop_todo.yml'
<% end %>
- ./rubocop/rubocop-migrations.yml
- ./rubocop/rubocop-usage-data.yml
- ./rubocop/rubocop-code_reuse.yml
inherit_mode:
merge:
- Include
- Exclude
AllCops:
2020-11-03 22:29:11 +01:00
TargetRubyVersion: 2.7
TargetRailsVersion: 6.0
Exclude:
- 'vendor/**/*'
2017-02-02 19:40:49 +01:00
- 'node_modules/**/*'
- 'db/fixtures/**/*'
- 'db/schema.rb'
- 'tmp/**/*'
- 'bin/**/*'
- 'generator_templates/**/*'
- 'builds/**/*'
- 'plugins/**/*'
- 'file_hooks/**/*'
2020-11-27 16:07:34 +01:00
- 'workhorse/**/*'
- 'spec/support/*.git/**/*' # e.g. spec/support/gitlab-git-test.git
2021-08-04 14:33:32 +02:00
- 'db/ci_migrate/*.rb' # since the `db/ci_migrate` is a symlinked to `db/migrate`
# Use absolute path to avoid orphan directories with changed workspace root.
CacheRootDirectory: <%= Dir.getwd %>/tmp
MaxFilesInCache: 30000
Cop/AvoidKeywordArgumentsInSidekiqWorkers:
Enabled: true
Include:
- 'app/workers/**/*'
- 'ee/app/workers/**/*'
Cop/StaticTranslationDefinition:
Enabled: true
Exclude:
- 'spec/**/*'
- 'ee/spec/**/*'
InternalAffairs/DeprecateCopHelper:
Enabled: true
Include:
- spec/rubocop/**/*.rb
Lint/LastKeywordArgument:
Enabled: true
Safe: false
# 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/**/*'
# TODO: Move this to gitlab-styles
Style/SafeNavigation:
Enabled: false
Style/AccessModifierDeclarations:
AllowModifiersOnSymbols: true
2018-09-28 11:43:07 +02:00
# Frozen String Literal
Style/FrozenStringLiteralComment:
Enabled: true
EnforcedStyle: always_true
2018-09-28 11:43:07 +02:00
RSpec/FilePath:
Exclude:
- 'qa/**/*'
- 'spec/frontend/fixtures/*'
- 'ee/spec/frontend/fixtures/*'
- 'spec/requests/api/v3/*'
- 'spec/fixtures/**/*'
# Configuration parameters: AllowSubject.
RSpec/MultipleMemoizedHelpers:
Max: 28
AllowSubject: true
Exclude:
- 'spec/migrations/**/*.rb'
- 'spec/lib/gitlab/background_migration/populate_project_snippet_statistics_spec.rb'
- 'spec/lib/gitlab/background_migration/populate_finding_uuid_for_vulnerability_feedback_spec.rb'
- 'ee/spec/lib/ee/gitlab/background_migration/populate_uuids_for_security_findings_spec.rb'
- 'ee/spec/lib/gitlab/background_migration/user_mentions/create_resource_user_mention_spec.rb'
Naming/FileName:
ExpectMatchingDefinition: true
CheckDefinitionPathHierarchy: false
Exclude:
- '**/*/*.builder'
- 'ee/bin/*'
- 'config.ru'
- 'config/**/*'
- 'ee/config/**/*'
- 'jh/config/**/*'
- 'db/**/*'
- 'ee/db/**/*'
- 'ee/elastic/migrate/*'
- 'lib/tasks/**/*.rake'
- 'ee/lib/tasks/**/*.rake'
- 'lib/generators/**/*'
- 'ee/lib/generators/**/*'
- 'scripts/**/*'
- 'spec/**/*'
- 'tooling/bin/**/*'
- 'ee/spec/**/*'
- 'jh/spec/**/*'
- 'qa/bin/*'
- 'qa/spec/**/*'
- 'qa/qa/specs/**/*'
- 'qa/tasks/**/*.rake'
- '**/*.ru'
2018-10-24 15:17:29 +02:00
IgnoreExecutableScripts: true
AllowedAcronyms:
- EE
- JSON
- LDAP
- SAML
2019-08-27 19:46:42 +02:00
- SSO
- IO
- HMAC
- QA
- ENV
- STL
- PDF
- SVG
- CTE
- DN
- RSA
- CI
- CD
- OAuth
- CSP
- CSV
- SCA
- SAN
- CIDR
- SPDX
- MR
- SSE
- JWT
- HLL
- GPG
- OTP
- GID
- AR
- RSpec
- ECDSA
- ED25519
- GitLab
- JavaScript
- VSCode
# 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
- GRPC
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
- ee/lib/ee/gitlab/background_migration/**/*.rb
- lib/gitlab/database/**/*.rb
- spec/**/*.rb
- ee/db/**/*.rb
- ee/spec/**/*.rb
Cop/DefaultScope:
Enabled: true
Rails/FindBy:
Enabled: true
Include:
- 'ee/app/**/*.rb'
- 'ee/lib/**/*.rb'
- 'spec/**/*.rb'
- 'ee/spec/**/*.rb'
# 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
# GitLab ###################################################################
Gitlab/ModuleWithInstanceVariables:
Enable: true
Exclude:
# We ignore Rails helpers right now because it's hard to workaround it
2017-12-15 12:37:57 +01:00
- app/helpers/**/*_helper.rb
- ee/app/helpers/**/*_helper.rb
# We ignore Rails mailers right now because it's hard to workaround it
2017-12-15 12:37:57 +01:00
- app/mailers/emails/**/*.rb
- ee/**/emails/**/*.rb
# We ignore spec helpers because it usually doesn't matter
- spec/support/**/*.rb
- features/steps/**/*.rb
Gitlab/ConstGetInheritFalse:
Enabled: true
Exclude:
- 'qa/bin/*'
Gitlab/ChangeTimezone:
Enabled: true
Exclude:
- config/initializers/time_zone.rb
Gitlab/HTTParty:
Enabled: true
Exclude:
- 'spec/**/*'
- 'ee/spec/**/*'
2020-04-07 15:35:34 +02:00
Gitlab/Json:
2020-04-28 15:09:19 +02:00
Enabled: true
2020-04-07 15:35:34 +02:00
Exclude:
- 'qa/**/*'
- 'scripts/**/*'
- 'tooling/rspec_flaky/**/*'
- 'lib/quality/**/*'
- 'tooling/danger/**/*'
2020-04-07 15:35:34 +02:00
Gitlab/AvoidUploadedFileFromParams:
Enabled: true
Exclude:
- 'lib/gitlab/middleware/multipart.rb'
- 'spec/**/*'
- 'ee/spec/**/*'
GitlabSecurity/PublicSend:
Enabled: true
Exclude:
- 'config/**/*'
- 'db/**/*'
- 'features/**/*'
- 'lib/**/*.rake'
- 'qa/**/*'
- 'spec/**/*'
- 'ee/db/**/*'
- 'ee/lib/**/*.rake'
- 'ee/spec/**/*'
Database/MultipleDatabases:
Enabled: true
Include:
- 'app/**/*.rb'
- 'ee/app/**/*.rb'
- 'lib/**/*.rb'
- 'ee/lib/**/*.rb'
- 'spec/**/*.rb'
- 'ee/spec/**/*.rb'
Exclude:
- 'ee/db/**/*.rb'
- 'spec/migrations/**/*.rb'
- 'lib/gitlab/background_migration/**/*.rb'
- 'spec/lib/gitlab/background_migration/**/*.rb'
- 'spec/lib/gitlab/database/**/*.rb'
Gitlab/DuplicateSpecLocation:
Enabled: true
Gitlab/PolicyRuleBoolean:
Enabled: true
Include:
- 'app/policies/**/*'
- 'ee/app/policies/**/*'
Cop/InjectEnterpriseEditionModule:
Enabled: true
Exclude:
- 'spec/**/*'
- 'ee/spec/**/*'
Style/ReturnNil:
Enabled: true
2019-01-30 19:44:00 +01:00
# It isn't always safe to replace `=~` with `.match?`, especially when there are
# nil values on the left hand side
Performance/RegexpMatch:
Enabled: false
Cop/ActiveRecordAssociationReload:
Enabled: true
Exclude:
- 'spec/**/*'
- 'ee/spec/**/*'
Cop/ActiveModelErrorsDirectManipulation:
Enabled: true
Gitlab/AvoidFeatureGet:
Enabled: true
RSpec/TimecopFreeze:
2020-10-06 00:42:20 +02:00
Enabled: true
AutoCorrect: true
Include:
- 'spec/**/*.rb'
- 'ee/spec/**/*.rb'
- 'qa/spec/**/*.rb'
RSpec/TimecopTravel:
Enabled: true
AutoCorrect: true
Include:
- 'spec/**/*.rb'
- 'ee/spec/**/*.rb'
- 'qa/spec/**/*.rb'
RSpec/WebMockEnable:
Enabled: true
Include:
- 'spec/**/*.rb'
- 'ee/spec/**/*.rb'
Exclude:
- 'spec/support/webmock.rb'
Naming/PredicateName:
Enabled: true
Exclude:
- 'spec/**/*'
- 'ee/spec/**/*'
RSpec/FactoriesInMigrationSpecs:
Enabled: true
Include:
- 'spec/migrations/**/*.rb'
- 'ee/spec/migrations/**/*.rb'
- 'spec/lib/gitlab/background_migration/**/*.rb'
- 'spec/lib/ee/gitlab/background_migration/**/*.rb'
- 'ee/spec/lib/ee/gitlab/background_migration/**/*.rb'
Cop/IncludeSidekiqWorker:
Enabled: true
Exclude:
- 'spec/**/*'
- 'ee/spec/**/*'
Gitlab/Union:
Enabled: true
Exclude:
- 'spec/**/*'
- 'ee/spec/**/*'
API/Base:
Upgrade to Grape v1.3.3 This brings back many of the changes in https://gitlab.com/gitlab-org/gitlab/-/merge_requests/27276. This was reverted due to some failures in the QA tests with nil parameters. Grape v1.3.3 brings in Ruby 2.7 support and a number of fixes: https://github.com/ruby-grape/grape/blob/master/CHANGELOG.md 1. Move all inherited `Grape::API` -> `Grape::API::Instance` 2. Remove use of Virtus since this has been removed from Grape. 3. Extract `Rack::Response` from API error 4. Grape v1.2.3 pulled in a fix used in `SafeFile`: https://github.com/ruby-grape/grape/pull/1844, so we no longer need to maintain our custom type. 5. Adapt `WorkhorseFile` with the latest changes to make custom types work with Grape and dry-types. 6. Ensure `Array[String]` is coerced properly. The change from Virtus to dry-types now requires all strings to be coerced to arrays. Before this was done within Virtus. 7. Coerce `Array[Integer]` types to arrays of integers 8. Use a new helper, `coerce_nil_params_to_array!`, that coerces nil Array inputs to empty arrays to preserve previous behavior. If you have a parameter of type `Array[String]`, for example, Grape used to coerce a provided `nil` value to `[]`. Grape no longer does this for us, so we need a helper method that will automatically do this if the parameter is present. This merge request also introduces two Rubocop rules for Grape v1.3: 1. `Grape::API::Instance` instead of `Grape::API` is required, unless we solve https://gitlab.com/gitlab-org/gitlab/-/issues/215230. 2. Grape parameters defined with `Array` types (e.g. `Array[String]`, `Array[Integer]`) must have a `coerce_with` block or they will fail to parse properly. See https://github.com/ruby-grape/grape/blob/master/UPGRADING.md for more details.
2020-05-30 01:12:45 +02:00
Enabled: true
Include:
- 'lib/**/api/**/*.rb'
- 'ee/**/api/**/*.rb'
API/GrapeArrayMissingCoerce:
Enabled: true
Include:
- 'lib/**/api/**/*.rb'
- 'ee/**/api/**/*.rb'
Cop/SidekiqOptionsQueue:
Enabled: true
Exclude:
- 'spec/**/*.rb'
- 'ee/spec/**/*.rb'
Graphql/ResolverType:
Enabled: true
Exclude:
- 'app/graphql/resolvers/base_resolver.rb'
Include:
- 'app/graphql/resolvers/**/*'
- 'ee/app/graphql/resolvers/**/*'
Graphql/AuthorizeTypes:
Enabled: true
Include:
- 'app/graphql/types/**/*'
- 'ee/app/graphql/types/**/*'
Exclude:
- 'spec/**/*.rb'
- 'ee/spec/**/*.rb'
Graphql/GIDExpectedType:
Enabled: true
Include:
- 'app/graphql/**/*'
- 'ee/app/graphql/**/*'
Exclude:
- 'spec/**/*.rb'
- 'ee/spec/**/*.rb'
Graphql/IDType:
Enabled: true
Include:
- 'app/graphql/**/*'
- 'ee/app/graphql/**/*'
Graphql/JSONType:
Enabled: true
Include:
- 'app/graphql/**/*'
- 'ee/app/graphql/**/*'
Exclude:
- 'spec/**/*.rb'
- 'ee/spec/**/*.rb'
Graphql/OldTypes:
Enabled: true
Include:
- 'app/graphql/**/*'
- 'ee/app/graphql/**/*'
- 'spec/graphql/**/*'
- 'spec/requests/api/graphql/**/*'
- 'ee/spec/graphql/**/*'
- 'ee/spec/requests/api/graphql/**/*'
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'
RSpec/BeSuccessMatcher:
Enabled: true
Include:
- 'spec/controllers/**/*'
- 'ee/spec/controllers/**/*'
- 'spec/support/shared_examples/controllers/**/*'
- 'ee/spec/support/shared_examples/controllers/**/*'
- 'spec/support/controllers/**/*'
- 'ee/spec/support/controllers/**/*'
Scalability/FileUploads:
Enabled: true
Include:
- 'lib/api/**/*.rb'
- 'ee/lib/api/**/*.rb'
Graphql/Descriptions:
Enabled: true
AutoCorrect: true
Include:
- 'app/graphql/**/*'
- 'ee/app/graphql/**/*'
# Cops for upgrade to gitlab-styles 3.1.0
RSpec/ImplicitSubject:
Enabled: false
# WIP See https://gitlab.com/gitlab-org/gitlab/-/issues/211580
2020-03-17 01:06:58 +01:00
RSpec/LeakyConstantDeclaration:
Enabled: true
Exclude:
- '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'
2020-03-17 01:06:58 +01:00
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
RSpec/HaveGitlabHttpStatus:
Enabled: true
Exclude:
- 'spec/support/matchers/have_gitlab_http_status.rb'
Include:
- 'spec/**/*'
- 'ee/spec/**/*'
Style/MultilineWhenThen:
Enabled: false
# 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
Style/FloatDivision:
Enabled: false
Cop/BanCatchThrow:
Enabled: true
Performance/ReadlinesEach:
Enabled: true
Performance/ChainArrayAllocation:
Enabled: true
Include:
- 'lib/gitlab/import_export/**/*'
- 'ee/lib/gitlab/import_export/**/*'
- 'ee/lib/ee/gitlab/import_export/**/*'
2020-05-15 04:07:27 +02:00
Rails/TimeZone:
Enabled: true
EnforcedStyle: 'flexible'
Include:
- 'app/controllers/**/*'
2020-05-15 04:07:27 +02:00
- 'app/services/**/*'
- 'lib/**/*'
- 'spec/controllers/**/*'
2020-05-15 04:07:27 +02:00
- 'spec/services/**/*'
- 'spec/lib/**/*'
- 'ee/app/controllers/**/*'
2020-05-15 04:07:27 +02:00
- 'ee/app/services/**/*'
- 'ee/spec/controllers/**/*'
2020-05-15 04:07:27 +02:00
- 'ee/spec/services/**/*'
2020-05-20 07:43:31 +02:00
- 'app/models/**/*'
- 'spec/models/**/*'
- 'ee/app/models/**/*'
- 'ee/spec/models/**/*'
2020-06-23 07:10:35 +02:00
- 'app/workers/**/*'
- 'spec/workers/**/*'
- 'ee/app/workers/**/*'
- 'ee/spec/workers/**/*'
- 'ee/lib/**/*'
- 'ee/spec/lib/**/*'
# WIP: See https://gitlab.com/gitlab-org/gitlab/-/issues/220040
Rails/SaveBang:
Enabled: true
AllowImplicitReturn: false
AllowedReceivers: ['ActionDispatch::TestRequest']
Include:
- 'spec/**/*.rb'
- 'ee/spec/**/*.rb'
- 'qa/spec/**/*.rb'
- 'qa/qa/specs/**/*.rb'
Exclude:
- spec/models/wiki_page/**/*
- spec/models/wiki_page_spec.rb
Cop/PutProjectRoutesUnderScope:
Include:
- 'config/routes/project.rb'
- 'ee/config/routes/project.rb'
Cop/PutGroupRoutesUnderScope:
Include:
- 'config/routes/group.rb'
- 'ee/config/routes/group.rb'
Migration/ComplexIndexesRequireName:
Exclude:
- !ruby/regexp /\Adb\/(post_)?migrate\/201.*\.rb\z/
- !ruby/regexp /\Adb\/(post_)?migrate\/20200[1-7].*\.rb\z/
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/
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/
Migration/PreventIndexCreation:
Exclude:
- !ruby/regexp /\Adb\/(post_)?migrate\/201.*\.rb\z/
- !ruby/regexp /\Adb\/(post_)?migrate\/2020.*\.rb\z/
- !ruby/regexp /\Adb\/(post_)?migrate\/20210[1-6].*\.rb\z/
Gitlab/RailsLogger:
Exclude:
- 'spec/**/*.rb'
- 'ee/spec/**/*.rb'
# WIP See https://gitlab.com/gitlab-org/gitlab/-/issues/267606
FactoryBot/InlineAssociation:
Include:
- 'spec/factories/**/*.rb'
- 'ee/spec/factories/**/*.rb'
# WIP: https://gitlab.com/gitlab-org/gitlab/-/issues/321982
Gitlab/NamespacedClass:
Exclude:
- 'config/**/*.rb'
- 'db/**/*.rb'
- 'ee/bin/**/*'
- 'ee/db/**/*.rb'
- 'ee/elastic/**/*.rb'
- 'scripts/**/*'
- 'spec/migrations/**/*.rb'
Lint/HashCompareByIdentity:
Enabled: true
Lint/RedundantSafeNavigation:
Enabled: true
Style/ClassEqualityComparison:
Enabled: true
# WIP See https://gitlab.com/gitlab-org/gitlab/-/issues/207950
Cop/UserAdmin:
Enabled: true
Exclude:
- 'app/controllers/admin/sessions_controller.rb'
- 'app/controllers/concerns/enforces_admin_authentication.rb'
- 'app/policies/base_policy.rb'
- 'lib/gitlab/auth/current_user_mode.rb'
- 'spec/**/*.rb'
- 'ee/spec/**/*.rb'
# See https://gitlab.com/gitlab-org/gitlab/-/issues/327495
Style/RegexpLiteral:
Enabled: false
Style/RegexpLiteralMixedPreserve:
Enabled: true
SupportedStyles:
- slashes
- percent_r
- mixed
- mixed_preserve
EnforcedStyle: mixed_preserve
RSpec/TopLevelDescribePath:
Exclude:
- 'spec/fixtures/**/*.rb'
- 'ee/spec/fixtures/**/*.rb'
QA/SelectorUsage:
Enabled: true
Include:
- 'spec/**/*.rb'
- 'ee/spec/**/*.rb'
Exclude:
- 'spec/rubocop/**/*_spec.rb'
Performance/ActiveRecordSubtransactions:
Exclude:
- 'spec/**/*.rb'
- 'ee/spec/**/*.rb'
Performance/ActiveRecordSubtransactionMethods:
Exclude:
- 'spec/**/*.rb'
- 'ee/spec/**/*.rb'