[Go to site: main page, start]

Gitlab RuboCop docs

Gitlab/AvoidConstDefaultOrganizationId

Enabled by defaultSafeSupports autocorrectionVersion AddedVersion Changed
EnabledYesNo--

Flags usages of DEFAULT_ORGANIZATION_ID constant

Examples

# bad
Organizations::Organization::DEFAULT_ORGANIZATION_ID
::Organizations::Organization::DEFAULT_ORGANIZATION_ID
DEFAULT_ORGANIZATION_ID = 1

Good - using specific lookup methods

# good
Organizations::Organization.find(id)
project.organization
namespace.organization

Gitlab/AvoidCurrentOrganization

Enabled by defaultSafeSupports autocorrectionVersion AddedVersion Changed
EnabledYesNo--

This cop checks for use Current.organization at banned layers of the application

Examples

# bad
class SomeService
  def execute
    do_something_with(Current.organization)
  end
end

# good
class SomeController < ApplicationController
  def create
    response = SomeService.new(organization: Current.organization).execute
  end
end

class SomeService
  def initialize(organization:)
    @organization = organization
  end

  def execute
    do_something_with(@organization)
  end
end

Gitlab/AvoidDefaultOrganization

Enabled by defaultSafeSupports autocorrectionVersion AddedVersion Changed
EnabledYesNo--

Flags usages of Organizations::Organization.default_organization and Organization.default_organization

Examples

Bad - Using .default_organization

# bad
Organizations::Organization.default_organization
::Organizations::Organization.default_organization
Organization.default_organization

Good - Using lookup methods or inferring from another model

# good
Organizations::Organization.find(id)
project.organization
namespace.organization

Gitlab/AvoidDirectWorkItemTypeUsage

Enabled by defaultSafeSupports autocorrectionVersion AddedVersion Changed
EnabledYesNo--

Flags direct usage of WorkItems::Type and WorkItems::TypesFramework::SystemDefined::Type.

These models should not be used directly. Instead, use WorkItems::TypesFramework::Provider which is the single source of truth for fetching work item types.

Examples

Bad - Using WorkItems::Type directly

# bad
WorkItems::Type.default_by_type(:issue)
::WorkItems::Type.base_types
WorkItems::TypesFramework::SystemDefined::Type.all

Good - Using the Provider

# good
WorkItems::TypesFramework::Provider.new(namespace).find_by_base_type(:issue)
WorkItems::TypesFramework::Provider.unfiltered_base_types
WorkItems::TypesFramework::Provider.new(namespace).all

Gitlab/AvoidFeatureCategoryNotOwned

Enabled by defaultSafeSupports autocorrectionVersion AddedVersion Changed
EnabledYesNo--

No documentation

Gitlab/AvoidFeatureGet

Enabled by defaultSafeSupports autocorrectionVersion AddedVersion Changed
EnabledYesNo--

Bans the use of Feature.get.

Examples

# bad

Feature.get(:x).enable
Feature.get(:x).enable_percentage_of_time(100)
Feature.get(:x).remove

# good

stub_feature_flags(x: true)
Feature.enable(:x)
Feature.enable_percentage_of_time(:x, 100)
Feature.remove(:x)

Gitlab/AvoidGitlabDedicatedInstanceChecks

Enabled by defaultSafeSupports autocorrectionVersion AddedVersion Changed
EnabledYesNo--

Checks for use of raw GitLab Dedicated instance checks.

Examples

# bad
if Gitlab::CurrentSettings.gitlab_dedicated_instance?
  do_dedicated_specific_thing
end

# bad
return unless Gitlab::Dedicated.dedicated_instance?

# good
if Gitlab::Dedicated.feature_available?(:my_dedicated_feature)
  do_dedicated_specific_thing
end

Gitlab/AvoidGitlabInstanceChecks

Enabled by defaultSafeSupports autocorrectionVersion AddedVersion Changed
EnabledYesNo--

This cop checks for use of gitlab instance specific checks.

Examples

# bad
if Gitlab.com?
  Ci::Runner::FORM_EDITABLE + Ci::Runner::MINUTES_COST_FACTOR_FIELDS
else
  Ci::Runner::FORM_EDITABLE
end

# good
if Gitlab::Saas.feature_available?(:purchases_additional_minutes)
  Ci::Runner::FORM_EDITABLE + Ci::Runner::MINUTES_COST_FACTOR_FIELDS
else
  Ci::Runner::FORM_EDITABLE
end

Gitlab/AvoidOrganizationUrlRoutes

Enabled by defaultSafeSupports autocorrectionVersion AddedVersion Changed
EnabledYesNo--

Checks for direct use of organization-scoped URL route helpers.

All routes are cloned under the /o/:organization_path scope, generating helpers prefixed with organization_ (e.g. organization_projects_path). Developers should use the standard (global) helpers instead (e.g. projects_path), which automatically become organization-aware via Routing::OrganizationsHelper::MappedHelpers.

Examples

# bad
organization_root_path(org)
organization_projects_url(namespace, organization_path: org.path)
organization_project_issues_path(project, organization_path: org.path)

# good - standard helpers auto-redirect based on Current.organization
root_path
projects_url(namespace)
project_issues_path(project)

# good - organization resource routes (not org-scoped clones)
organization_path(org)
organizations_path
new_organization_path

Gitlab/AvoidProjectIssuableUrlHelpers

Enabled by defaultSafeSupports autocorrectionVersion AddedVersion Changed
EnabledYesNo--

Flags usages of project_issue_url, project_issue_path, project_work_item_url, and project_work_item_path helpers, which raise errors for group-level issues.

Examples

# bad
project_issue_url(project, issue)
project_issue_path(project, issue)
project_work_item_url(project, work_item)
project_work_item_path(project, work_item)

# good
Gitlab::UrlBuilder.build(issue)
Gitlab::UrlBuilder.build(issue, only_path: true)

Gitlab/AvoidRailsCacheDeleteMatched

Enabled by defaultSafeSupports autocorrectionVersion AddedVersion Changed
EnabledYesNo--

Checks for Rails.cache.delete_matched usage.

Rails.cache.delete_matched scans the entire Redis cluster to find keys matching the pattern, which can cause severe performance issues, timeouts, and production incidents in large-scale applications.

Examples

# bad
Rails.cache.delete_matched("users/*/feature_enabled/*")

# bad
Rails.cache.delete_matched(
  "some/key/*"
)

# good - delete specific cache keys
Rails.cache.delete("some/key")

# good - redesign caching strategy to avoid wildcard deletions
# Use a versioned cache key approach:
def cache_key
  "some/key/id/v#{cache_version}"
end

def cache_version
  # Increment version when cache needs invalidation
  user.cache_version
end

Gitlab/AvoidUploadedFileFromParams

Enabled by defaultSafeSupports autocorrectionVersion AddedVersion Changed
EnabledYesNo--

This cop checks for UploadedFile.from_params usage. See https://docs.gitlab.com/ee/development/uploads/working_with_uploads.html

Examples

# bad
class MyAwfulApi < Grape::API::Instance
  params do
    optional 'file.path', type: String
    optional 'file.name', type: String
    optional 'file.type', type: String
    optional 'file.size', type: Integer
    optional 'file.md5', type: String
    optional 'file.sha1', type: String
    optional 'file.sha256', type: String
  end
  put '/files' do
    uploaded_file = UploadedFile.from_params(params, :file, FileUploader.workhorse_local_upload_path)
  end
end

# good
class MyMuchBetterApi < Grape::API::Instance
  params do
    requires :file, type: ::API::Validations::Types::WorkhorseFile
  end
  put '/files' do
    uploaded_file = declared_params[:file]
  end
end

Gitlab/AvoidUserOrganization

Enabled by defaultSafeSupports autocorrectionVersion AddedVersion Changed
EnabledYesNo--

Checks for use of User#organization method

Examples

# bad
class SomeService
  def execute
    do_something_with(user.organization)
  end
end

# bad
class SomeService
  def execute
    do_something_with(current_user.organization)
  end
end

# good
class SomeController < ApplicationController
  def create
    response = SomeService.new(organization: Current.organization).execute
  end
end

class SomeService
  def initialize(organization:)
    @organization = organization
  end

  def execute
    do_something_with(@organization)
  end
end

# good (these are not User objects)
project.organization
group.organization
namespace.organization

Gitlab/BoundedContexts

Enabled by defaultSafeSupports autocorrectionVersion AddedVersion Changed
EnabledYesNo--

No documentation

Gitlab/BulkInsert

Enabled by defaultSafeSupports autocorrectionVersion AddedVersion Changed
EnabledYesNo--

Cop that disallows the use of legacy_bulk_insert, in favour of using the BulkInsertSafe module.

Gitlab/ChangeTimezone

Enabled by defaultSafeSupports autocorrectionVersion AddedVersion Changed
EnabledYesNo--

No documentation

Gitlab/ConstGetInheritFalse

Enabled by defaultSafeSupports autocorrectionVersion AddedVersion Changed
EnabledYesAlways--

Cop that encourages usage of inherit=false for 2nd argument when using const_get.

See https://gitlab.com/gitlab-org/gitlab/issues/27678

Gitlab/DelegatePredicateMethods

Enabled by defaultSafeSupports autocorrectionVersion AddedVersion Changed
EnabledYesNo--

This cop looks for delegations to predicate methods with allow_nil: true option. This construct results in three possible results: true, false and nil. In other words, it does not preserve the strict Boolean nature of predicate method return value. This cop suggests creating a method to handle nil delegator and ensure only Boolean type is returned.

Examples

# bad
delegate :is_foo?, to: :bar, allow_nil: true

# good
def is_foo?
  return false unless bar
  bar.is_foo?
end

def is_foo?
  !!bar&.is_foo?
end

Gitlab/DeprecatedAuditEventService

Enabled by defaultSafeSupports autocorrectionVersion AddedVersion Changed
EnabledYesNo--

Checks for usage of the deprecated AuditEventService and prevents new implementations from being added.

Examples

# bad
AuditEventService.new(...)

# good
Gitlab::Audit::Auditor.audit { ... }

Gitlab/DirectStdio

Enabled by defaultSafeSupports autocorrectionVersion AddedVersion Changed
EnabledYesNo--

Flags direct writes to $stdout, $stderr, STDOUT, or STDERR.

Examples

# bad
$stdout.puts("Checking LDAP ...")
$stderr.puts("Error: #{message}")
STDOUT.print("done")
STDERR.print("done")

# good
Gitlab::AppLogger.info("Checking LDAP ...")
say("Checking LDAP ...") # via Gitlab::TaskHelpers or SystemCheck::Helpers

Gitlab/DisallowCurrentOrganizationIdSafeNavigation

Enabled by defaultSafeSupports autocorrectionVersion AddedVersion Changed
EnabledYesAlways--

Discourages the use of Current.organization&.id.

Current.organization is expected to be assigned in contexts where its ID is accessed. If Current.organization is not assigned, attempting to access id directly (i.e., Current.organization.id) will correctly raise a Current::OrganizationNotAssignedError. Using the safe navigation operator (&.id) prevents this error from being raised, potentially hiding issues where Current.organization was not properly set up.

This cop enforces the direct use of Current.organization.id to ensure that Current::OrganizationNotAssignedError is raised if Current.organization is nil.

Examples

# bad
id = Current.organization&.id
id = ::Current.organization&.id

# good
# If Current.organization is expected to be present (which it is),
# this will raise Current::OrganizationNotAssignedError if it's unexpectedly nil,
# making the underlying issue visible.
id = Current.organization.id

Gitlab/EeFeatureFlagInFoss

Enabled by defaultSafeSupports autocorrectionVersion AddedVersion Changed
EnabledYesNo--

Checks for usage of EE-only feature flags in FOSS code.

Feature flags defined in ee/config/feature_flags/ should only be used within the ee/ directory to prevent FOSS-only test failures.

Examples

# bad (in lib/gitlab/gon_helper.rb with ee/config/feature_flags/beta/ee_only_flag.yml)
push_frontend_feature_flag(:ee_only_flag, current_user)

# good (in ee/lib/ee/gitlab/gon_helper.rb)
push_frontend_feature_flag(:ee_only_flag, current_user)

# good (in lib/gitlab/gon_helper.rb with config/feature_flags/beta/some_flag.yml)
push_frontend_feature_flag(:some_flag, current_user)

Gitlab/EeOnlyClass

Enabled by defaultSafeSupports autocorrectionVersion AddedVersion Changed
EnabledYesNo--

No documentation

Gitlab/EventStoreCloudEventInheritance

Enabled by defaultSafeSupports autocorrectionVersion AddedVersion Changed
EnabledYesNo--

Forbids direct inheritance from Gitlab::EventStore::Event. New event classes should inherit from Gitlab::EventStore::CloudEvent (or a descendant) instead.

Examples

# bad
class MyEvent < Gitlab::EventStore::Event
  def schema
    { 'type' => 'object' }
  end
end

# bad
class MyEvent < ::Gitlab::EventStore::Event
end

# good
class MyEvent < Gitlab::EventStore::CloudEvent
  event_category :my_domain
  event_type :my_event

  def data_schema
    { 'type' => 'object' }
  end
end

# good
class MyEvent < ::Gitlab::EventStore::CloudEvent
end

Gitlab/EventStoreDocRequired

Enabled by defaultSafeSupports autocorrectionVersion AddedVersion Changed
EnabledYesNo--

Ensures every EventStore event class has a documentation file, and that the documentation correctly reflects whether the event lives under ee/app/events/ (via ee_only: true) or app/events/ (no ee_only).

Examples

# bad - data/events/ci/pipeline_created_event.yml is missing
module Ci
  class PipelineCreatedEvent < Gitlab::EventStore::Event; end
end

# good - data/events/ci/pipeline_created_event.yml exists:
# event: Ci::PipelineCreatedEvent
# description: Published when a CI pipeline is created.
# feature_category: continuous_integration

Gitlab/EventStoreSubscriber

Enabled by defaultSafeSupports autocorrectionVersion AddedVersion Changed
EnabledYesNo--

Cop that checks the implementation of Gitlab::EventStore::Subscriber

A worker that implements Gitlab::EventStore::Subscriber must implement the method #handle_event(event) and must not override the method #perform(*args)

Examples

# bad
class MySubscriber
  include Gitlab::EventStore::Subscriber

  def perform(*args)
  end
end

# bad
class MySubscriber
  include Gitlab::EventStore::Subscriber
end

# good
class MySubscriber
  include Gitlab::EventStore::Subscriber

  def handle_event(event)
  end
end

Gitlab/Except

Enabled by defaultSafeSupports autocorrectionVersion AddedVersion Changed
EnabledYesNo--

Cop that disallows the use of Gitlab::SQL::Except, in favour of using the FromExcept module.

Gitlab/FeatureAvailableUsage

Enabled by defaultSafeSupports autocorrectionVersion AddedVersion Changed
EnabledYesNo--

Cop that checks for correct calling of #feature_available?

Gitlab/FeatureFlagKeyDynamic

Enabled by defaultSafeSupports autocorrectionVersion AddedVersion Changed
EnabledYesAlways--

The first argument to Feature.enabled? and Feature.disabled? should be a literal symbol. Dynamic keys are discouraged because they are harder to explicitly search for in the codebase by name. Strings are similarly discouraged to simplify exact matching when searching for flag usage.

Feature flags are technical debt (should be short lived), so it is important to ensure we can find all usages in order to remove the flag safely. More information at https://docs.gitlab.com/development/feature_flags/#feature-flag-definition-and-validation

Examples

# bad
Feature.enabled?('some_flag')
Feature.enabled?(flag_name)
Feature.disabled?(flag)
Gitlab::AiGateway.push_feature_flag(flag)

# good
Feature.enabled?(:some_flag)
Feature.disabled?(:other_flag)
Gitlab::AiGateway.push_feature_flag(:another_flag)

Gitlab/FeatureFlagWithoutActor

Enabled by defaultSafeSupports autocorrectionVersion AddedVersion Changed
EnabledYesNo--

No documentation

Gitlab/FinderWithFindBy

Enabled by defaultSafeSupports autocorrectionVersion AddedVersion Changed
EnabledYesAlways--

No documentation

Gitlab/HTTParty

Enabled by defaultSafeSupports autocorrectionVersion AddedVersion Changed
EnabledYesAlways--

No documentation

Gitlab/HardDeleteCalls

Enabled by defaultSafeSupports autocorrectionVersion AddedVersion Changed
EnabledYesNo--

This cop identifies direct calls to hard delete classes that could lead to data loss.

Gitlab/HttpV2

Enabled by defaultSafeSupports autocorrectionVersion AddedVersion Changed
EnabledYesAlways--

No documentation

Gitlab/Intersect

Enabled by defaultSafeSupports autocorrectionVersion AddedVersion Changed
EnabledYesNo--

Cop that disallows the use of Gitlab::SQL::Intersect, in favour of using the FromIntersect module.

Gitlab/Json

Enabled by defaultSafeSupports autocorrectionVersion AddedVersion Changed
EnabledYesAlways--

No documentation

Gitlab/JsonSafeParse

Enabled by defaultSafeSupports autocorrectionVersion AddedVersion Changed
EnabledYesAlways--

Encourages the use of Gitlab::Json::SafeParser.parse over Gitlab::Json.parse for parsing untrusted JSON input with built-in size and depth limits.

SafeParser provides protection against:

  • Deeply nested structures (DoS via stack exhaustion)
  • Extremely large arrays or hashes (memory exhaustion)
  • Oversized JSON payloads (memory exhaustion)

Examples

# bad - no arguments beyond payload -> corrected to SafeParser.parse

Gitlab::Json.parse(user_input)
Gitlab::Json.parse(request.body.read)
::Gitlab::Json.parse(params[:data])

# good (autocorrected)

Gitlab::Json::SafeParser.parse(user_input)
Gitlab::Json::SafeParser.parse(request.body.read)
::Gitlab::Json::SafeParser.parse(params[:data])

# bad - extra arguments present -> corrected to Gitlab::Json.safe_parse
# (SafeParser.parse only accepts parse-limit keys and would raise
# UnknownConfigurationError for JSON options like `symbolize_names:`.)

Gitlab::Json.parse(data, symbolize_names: true)
Gitlab::Json.parse(data, legacy_mode: true)

# good (autocorrected)

Gitlab::Json.safe_parse(data, symbolize_names: true)
Gitlab::Json.safe_parse(data, legacy_mode: true)

# also good - already using `Gitlab::Json.safe_parse`

Gitlab::Json.safe_parse(data)
Gitlab::Json.safe_parse(data, parse_limits: { max_depth: 10 })

Gitlab/KeysFirstAndValuesFirst

Enabled by defaultSafeSupports autocorrectionVersion AddedVersion Changed
EnabledYesAlways--

Detects the use of .keys.first or .values.first and suggests a change to .each_key.first or .each_value.first. This reduces memory usage and execution time.

Examples

# bad

hash.keys.first
hash.values.first

# good

hash.each_key.first
hash.each_value.first

Gitlab/LicenseAvailableUsage

Enabled by defaultSafeSupports autocorrectionVersion AddedVersion Changed
EnabledYesNo--

Cop to ban use of License.feature_available? in ApplicationSetting model to avoid cyclical dependency issues. Issue example: https://gitlab.com/gitlab-org/gitlab/-/issues/423237

Gitlab/MarkUsedFeatureFlags

Enabled by defaultSafeSupports autocorrectionVersion AddedVersion Changed
EnabledYesNo--

This cop tracks the usage of feature flags among the codebase.

The files set in tmp/feature_flags/*.used can then be used for verification purpose.

Gitlab/ModuleWithInstanceVariables

Enabled by defaultSafeSupports autocorrectionVersion AddedVersion Changed
EnabledYesNo--

No documentation

Gitlab/NamespacedClass

Enabled by defaultSafeSupports autocorrectionVersion AddedVersion Changed
EnabledYesNo--

Cop that enforces use of namespaced classes in order to better identify high level domains within the codebase.

Examples

# bad
class MyClass
end

module Gitlab
  class MyClass
  end
end

class Gitlab::MyClass
end

# good
module MyDomain
  class MyClass
  end
end

module Gitlab
  module MyDomain
    class MyClass
    end
  end
end

class Gitlab::MyDomain::MyClass
end

Gitlab/NoCodeCoverageComment

Enabled by defaultSafeSupports autocorrectionVersion AddedVersion Changed
EnabledYesNo--

Discourages the use of # :nocov: to exclude code from coverage report.

The nocov token can be configured via CommentToken option and defaults to 'nocov'.

Examples

CommentToken: ’nocov’ (default)

# bad
# :nocov:
def method
end
# :nocov:

# good
def method
end

Gitlab/NoFindInWorkers

Enabled by defaultSafeSupports autocorrectionVersion AddedVersion Changed
EnabledYesNo--

Checks for use of ActiveRecord find in Sidekiq workers.

Examples

# bad
class ExampleWorker
  def perform
    record = Klass.find(id)
  end
end

# good
class ExampleWorker
  def perform
    record = Klass.find_by_id(id)
    return unless record
  end
end

Gitlab/NoHelpersInPresenters

Enabled by defaultSafeSupports autocorrectionVersion AddedVersion Changed
EnabledYesNo--

Enforces that presenters don’t include helpers.

Presenters should be view-agnostic and not depend on view context. Including helper modules in presenters couples them to the view layer and makes them harder to test and reason about.

Examples

# bad
class BasePresenter
  include DiffHelper

  def diffs_slice
    @diffs_slice ||= resource.first_diffs_slice(offset, diff_options)
  end
end
# good
class BasePresenter
  attr_reader :diff_options

  def initialize(diff_options)
    @diff_options = diff_options
  end

  def diffs_slice
    @diffs_slice ||= resource.first_diffs_slice(offset, diff_options)
  end
end

Gitlab/PolicyRuleBoolean

Enabled by defaultSafeSupports autocorrectionVersion AddedVersion Changed
EnabledYesNo--

This cop checks for usage of boolean operators in rule blocks, which does not work because conditions are objects, not booleans.

Examples

# bad, `conducts_electricity` returns a Rule object, not a boolean!
rule { conducts_electricity && batteries }.enable :light_bulb

# good
rule { conducts_electricity & batteries }.enable :light_bulb
# bad, `conducts_electricity` returns a Rule object, so the ternary is always going to be true
rule { conducts_electricity ? can?(:magnetize) : batteries }.enable :motor

# good
rule { conducts_electricity & can?(:magnetize) }.enable :motor
rule { ~conducts_electricity & batteries }.enable :motor

Gitlab/PredicateMemoization

Enabled by defaultSafeSupports autocorrectionVersion AddedVersion Changed
EnabledYesNo--

No documentation

Gitlab/PreventOrganizationFirst

Enabled by defaultSafeSupports autocorrectionVersion AddedVersion Changed
EnabledYesNo--

Prevents use of Organizations::Organization.first which can lead to unpredictable behavior for our migration to cells.

Examples

Bad - using first or first!

# bad
Organizations::Organization.first
Organizations::Organization.first!

Good - using specific lookup methods

# good
Organizations::Organization.find(id)
project.organization
namespace.organization

Gitlab/RailsLogger

Enabled by defaultSafeSupports autocorrectionVersion AddedVersion Changed
EnabledYesNo--

No documentation

Gitlab/SaasFeatureAvailableOutsideEe

Enabled by defaultSafeSupports autocorrectionVersion AddedVersion Changed
EnabledYesNo--

Checks for use of Gitlab::Saas.feature_available? outside of the /ee directory.

Examples

# bad (outside /ee directory)
if Gitlab::Saas.feature_available?(:some_feature)
  # do something
end

# bad (outside /ee directory with safe navigation)
if Gitlab::Saas&.feature_available?(:some_feature)
  # do something
end

# good (inside /ee directory)
if Gitlab::Saas.feature_available?(:some_feature)
  # do something
end

Gitlab/ServiceResponse

Enabled by defaultSafeSupports autocorrectionVersion AddedVersion Changed
EnabledYesNo--

No documentation

Gitlab/StrongMemoizeAttr

Enabled by defaultSafeSupports autocorrectionVersion AddedVersion Changed
EnabledYesAlways--

Prefer using .strong_memoize_attr() over #strong_memoize(). See https://docs.gitlab.com/ee/development/utilities.html/#strongmemoize.

Good:

def memoized_method
  'This is a memoized method'
end
strong_memoize_attr :memoized_method

Bad, can be autocorrected:

def memoized_method
  strong_memoize(:memoized_method) do
    'This is a memoized method'
  end
end

Very bad, can’t be autocorrected:

def memoized_method
  return unless enabled?

  strong_memoize(:memoized_method) do
    'This is a memoized method'
  end
end

Gitlab/TokenWithoutPrefix

Enabled by defaultSafeSupports autocorrectionVersion AddedVersion Changed
EnabledYesNo--

Checks for the use of add_authentication_token_field without also defining a prefix. Using a prefix for each token type allows easier secret detection if it leaks.

Examples

# bad
add_authentication_token_field :foo

# good
add_authentication_token_field :foo, format_with_prefix: method_name_here

Gitlab/TokenWithoutRoutable

Enabled by defaultSafeSupports autocorrectionVersion AddedVersion Changed
EnabledYesNo--

Checks for the use of add_authentication_token_field without also defining a routable_token. Encoding routing information in the token allows the HTTP Router to route requests to the correct cell without an extra lookup.

Examples

# bad
add_authentication_token_field :foo

# good
add_authentication_token_field :foo, routable_token: { payload: { c: ->(record) { record.cell_id } } }

Gitlab/Union

Enabled by defaultSafeSupports autocorrectionVersion AddedVersion Changed
EnabledYesNo--

Cop that disallows the use of Gitlab::SQL::Union, in favour of using the FromUnion module.

Gitlab/UseParamKeyForConvertingClassName

Enabled by defaultSafeSupports autocorrectionVersion AddedVersion Changed
EnabledYesAlways--

Checks for redundant use of *.name.underscore.tr('/', '_')

Examples

# bad
class Example
  def class_name
    self.name.underscore.tr('/', '_')
  end
end

# good
class Example
  def class_name
    Gitlab::Utils.param_key(self)
  end
end

Gitlab/UsersInternalOrganization

Enabled by defaultSafeSupports autocorrectionVersion AddedVersion Changed
EnabledYesNo--

Prevents direct calls to Users::Internal methods without organization context.

Examples

# bad
Users::Internal.alert_bot
Internal.support_bot

# good
Users::Internal.in_organization(organization).alert_bot
Users::Internal.in_organization(organization).support_bot

Gitlab/WithoutReactiveCache

Enabled by defaultSafeSupports autocorrectionVersion AddedVersion Changed
EnabledYesNo--

Cop that prevents the use of without_reactive_cache