Commit b7d8df50 authored by Douwe Maan's avatar Douwe Maan

Enable Style/MutableConstant

parent 3dadf306
......@@ -308,6 +308,9 @@ Style/MultilineOperationIndentation:
Style/MultilineTernaryOperator:
Enabled: true
Style/MutableConstant:
Enabled: true
# Favor unless over if for negative conditions (or control flow or).
Style/NegatedIf:
Enabled: true
......
......@@ -471,11 +471,6 @@ Style/MultilineIfModifier:
- 'app/models/project_wiki.rb'
- 'lib/gitlab/workhorse.rb'
# Offense count: 187
# Cop supports --auto-correct.
Style/MutableConstant:
Enabled: false
# Offense count: 8
# Cop supports --auto-correct.
Style/NestedParenthesizedCalls:
......
......@@ -3,7 +3,7 @@ class Admin::SystemInfoController < Admin::ApplicationController
'nobrowse',
'read-only',
'ro'
]
].freeze
EXCLUDED_MOUNT_TYPES = [
'autofs',
......@@ -27,7 +27,7 @@ class Admin::SystemInfoController < Admin::ApplicationController
'tmpfs',
'tracefs',
'vfat'
]
].freeze
def show
@cpus = Vmstat.cpu rescue nil
......
......@@ -59,10 +59,10 @@ module ServiceParams
:user_key,
:username,
:webhook
]
].freeze
# Parameters to ignore if no value is specified
FILTER_BLANK_PARAMS = [:password]
FILTER_BLANK_PARAMS = [:password].freeze
def service_params
dynamic_params = @service.event_channel_names + @service.event_names
......
......@@ -5,7 +5,7 @@ class JwtController < ApplicationController
SERVICES = {
Auth::ContainerRegistryAuthenticationService::AUDIENCE => Auth::ContainerRegistryAuthenticationService,
}
}.freeze
def auth
service = SERVICES[params[:service]]
......
......@@ -19,7 +19,7 @@
# iids: integer[]
#
class IssuableFinder
NONE = '0'
NONE = '0'.freeze
attr_accessor :current_user, :params
......
......@@ -13,7 +13,7 @@
#
class TodosFinder
NONE = '0'
NONE = '0'.freeze
attr_accessor :current_user, :params
......
......@@ -198,7 +198,7 @@ module IssuablesHelper
@counts[issuable_type][state]
end
IRRELEVANT_PARAMS_FOR_CACHE_KEY = %i[utf8 sort page]
IRRELEVANT_PARAMS_FOR_CACHE_KEY = %i[utf8 sort page].freeze
private_constant :IRRELEVANT_PARAMS_FOR_CACHE_KEY
def issuables_state_counter_cache_key(issuable_type, state)
......
......@@ -5,7 +5,7 @@ class ApplicationSetting < ActiveRecord::Base
add_authentication_token_field :runners_registration_token
add_authentication_token_field :health_check_access_token
CACHE_KEY = 'application_setting.last'
CACHE_KEY = 'application_setting.last'.freeze
DOMAIN_LIST_SEPARATOR = %r{\s*[,;]\s* # comma or semicolon, optionally surrounded by whitespace
| # or
\s # any whitespace character
......
......@@ -4,8 +4,8 @@ module Ci
RUNNER_QUEUE_EXPIRY_TIME = 60.minutes
LAST_CONTACT_TIME = 1.hour.ago
AVAILABLE_SCOPES = %w[specific shared active paused online]
FORM_EDITABLE = %i[description tag_list active run_untagged locked]
AVAILABLE_SCOPES = %w[specific shared active paused online].freeze
FORM_EDITABLE = %i[description tag_list active run_untagged locked].freeze
has_many :builds
has_many :runner_projects, dependent: :destroy
......
......@@ -22,7 +22,7 @@ class Commit
DIFF_HARD_LIMIT_LINES = 50000
# The SHA can be between 7 and 40 hex characters.
COMMIT_SHA_PATTERN = '\h{7,40}'
COMMIT_SHA_PATTERN = '\h{7,40}'.freeze
class << self
def decorate(commits, project)
......
......@@ -45,7 +45,7 @@ module CacheMarkdownField
Project
Release
Snippet
]
].freeze
def self.caching_classes
CACHING_CLASSES.map(&:constantize)
......
module HasStatus
extend ActiveSupport::Concern
DEFAULT_STATUS = 'created'
AVAILABLE_STATUSES = %w[created pending running success failed canceled skipped]
STARTED_STATUSES = %w[running success failed skipped]
ACTIVE_STATUSES = %w[pending running]
COMPLETED_STATUSES = %w[success failed canceled skipped]
ORDERED_STATUSES = %w[failed pending running canceled success skipped]
DEFAULT_STATUS = 'created'.freeze
AVAILABLE_STATUSES = %w[created pending running success failed canceled skipped].freeze
STARTED_STATUSES = %w[running success failed skipped].freeze
ACTIVE_STATUSES = %w[pending running].freeze
COMPLETED_STATUSES = %w[success failed canceled skipped].freeze
ORDERED_STATUSES = %w[failed pending running canceled success skipped].freeze
class_methods do
def status_sql
......
......@@ -11,7 +11,7 @@ class Label < ActiveRecord::Base
cache_markdown_field :description, pipeline: :single_line
DEFAULT_COLOR = '#428BCA'
DEFAULT_COLOR = '#428BCA'.freeze
default_value_for :color, DEFAULT_COLOR
......
class GroupMember < Member
SOURCE_TYPE = 'Namespace'
SOURCE_TYPE = 'Namespace'.freeze
belongs_to :group, foreign_key: 'source_id'
......
class ProjectMember < Member
SOURCE_TYPE = 'Project'
SOURCE_TYPE = 'Project'.freeze
include Gitlab::ShellAdapter
......
......@@ -7,7 +7,7 @@ class MergeRequestDiff < ActiveRecord::Base
COMMITS_SAFE_SIZE = 100
# Valid types of serialized diffs allowed by Gitlab::Git::Diff
VALID_CLASSES = [Hash, Rugged::Patch, Rugged::Diff::Delta]
VALID_CLASSES = [Hash, Rugged::Patch, Rugged::Diff::Delta].freeze
belongs_to :merge_request
......
......@@ -35,11 +35,11 @@ class NotificationSetting < ActiveRecord::Base
:merge_merge_request,
:failed_pipeline,
:success_pipeline
]
].freeze
EXCLUDED_WATCHER_EVENTS = [
:success_pipeline
]
].freeze
store :events, accessors: EMAIL_EVENTS, coder: JSON
......
......@@ -22,7 +22,7 @@ class Project < ActiveRecord::Base
class BoardLimitExceeded < StandardError; end
NUMBER_OF_PERMITTED_BOARDS = 1
UNKNOWN_IMPORT_URL = 'http://unknown.git'
UNKNOWN_IMPORT_URL = 'http://unknown.git'.freeze
cache_markdown_field :description, pipeline: :description
......
......@@ -18,7 +18,7 @@ class ProjectFeature < ActiveRecord::Base
PRIVATE = 10
ENABLED = 20
FEATURES = %i(issues merge_requests wiki snippets builds repository)
FEATURES = %i(issues merge_requests wiki snippets builds repository).freeze
class << self
def access_level_attribute(feature)
......
......@@ -3,7 +3,7 @@ require "addressable/uri"
class BuildkiteService < CiService
include ReactiveService
ENDPOINT = "https://buildkite.com"
ENDPOINT = "https://buildkite.com".freeze
prop_accessor :project_url, :token
boolean_accessor :enable_ssl_verification
......
......@@ -6,7 +6,7 @@ class HipchatService < Service
a b i strong em br img pre code
table th tr td caption colgroup col thead tbody tfoot
ul ol li dl dt dd
]
].freeze
prop_accessor :token, :room, :server, :color, :api_version
boolean_accessor :notify_only_broken_builds, :notify
......
class PivotaltrackerService < Service
include HTTParty
API_ENDPOINT = 'https://www.pivotaltracker.com/services/v5/source_commits'
API_ENDPOINT = 'https://www.pivotaltracker.com/services/v5/source_commits'.freeze
prop_accessor :token, :restrict_to_branch
validates :token, presence: true, if: :activated?
......
......@@ -4,7 +4,7 @@ class ProjectStatistics < ActiveRecord::Base
before_save :update_storage_size
STORAGE_COLUMNS = [:repository_size, :lfs_objects_size, :build_artifacts_size]
STORAGE_COLUMNS = [:repository_size, :lfs_objects_size, :build_artifacts_size].freeze
STATISTICS_COLUMNS = [:commit_count] + STORAGE_COLUMNS
def total_repository_size
......
......@@ -5,7 +5,7 @@ class ProjectWiki
'Markdown' => :markdown,
'RDoc' => :rdoc,
'AsciiDoc' => :asciidoc
} unless defined?(MARKUPS)
}.freeze unless defined?(MARKUPS)
class CouldNotCreateWikiError < StandardError; end
......
......@@ -18,7 +18,7 @@ class Repository
CACHED_METHODS = %i(size commit_count readme version contribution_guide
changelog license_blob license_key gitignore koding_yml
gitlab_ci_yml branch_names tag_names branch_count
tag_count avatar exists? empty? root_ref)
tag_count avatar exists? empty? root_ref).freeze
# Certain method caches should be refreshed when certain types of files are
# changed. This Hash maps file types (as returned by Gitlab::FileDetector) to
......@@ -33,7 +33,7 @@ class Repository
koding: :koding_yml,
gitlab_ci: :gitlab_ci_yml,
avatar: :avatar
}
}.freeze
# Wraps around the given method and caches its output in Redis and an instance
# variable.
......
......@@ -17,7 +17,7 @@ class Todo < ActiveRecord::Base
APPROVAL_REQUIRED => :approval_required,
UNMERGEABLE => :unmergeable,
DIRECTLY_ADDRESSED => :directly_addressed
}
}.freeze
belongs_to :author, class_name: "User"
belongs_to :note
......
......@@ -2,7 +2,7 @@ module Auth
class ContainerRegistryAuthenticationService < BaseService
include Gitlab::CurrentSettings
AUDIENCE = 'container_registry'
AUDIENCE = 'container_registry'.freeze
def execute(authentication_abilities:)
@authentication_abilities = authentication_abilities
......
......@@ -4,7 +4,7 @@ module Members
attr_accessor :source
ALLOWED_SCOPES = %i[members requesters all]
ALLOWED_SCOPES = %i[members requesters all].freeze
def initialize(source, current_user, params = {})
@source = source
......
......@@ -3,7 +3,7 @@ module Notes
UPDATE_SERVICES = {
'Issue' => Issues::UpdateService,
'MergeRequest' => MergeRequests::UpdateService
}
}.freeze
def self.noteable_update_service(note)
UPDATE_SERVICES[note.noteable_type]
......
......@@ -4,7 +4,7 @@ module Projects
class DestroyError < StandardError; end
DELETED_FLAG = '+deleted'
DELETED_FLAG = '+deleted'.freeze
def async_execute
project.transaction do
......
......@@ -2,7 +2,7 @@ module Projects
class DownloadService < BaseService
WHITELIST = [
/^[^.]+\.fogbugz.com$/
]
].freeze
def initialize(project, url)
@project, @url = project, url
......
......@@ -2,7 +2,7 @@ module Projects
class UpdatePagesService < BaseService
BLOCK_SIZE = 32.kilobytes
MAX_SIZE = 1.terabyte
SITE_PATH = 'public/'
SITE_PATH = 'public/'.freeze
attr_reader :build
......
# Extra methods for uploader
module UploaderHelper
IMAGE_EXT = %w[png jpg jpeg gif bmp tiff]
IMAGE_EXT = %w[png jpg jpeg gif bmp tiff].freeze
# We recommend using the .mp4 format over .mov. Videos in .mov format can
# still be used but you really need to make sure they are served with the
# proper MIME type video/mp4 and not video/quicktime or your videos won't play
# on IE >= 9.
# http://archive.sublimevideo.info/20150912/docs.sublimevideo.net/troubleshooting.html
VIDEO_EXT = %w[mp4 m4v mov webm ogv]
VIDEO_EXT = %w[mp4 m4v mov webm ogv].freeze
# These extension types can contain dangerous code and should only be embedded inline with
# proper filtering. They should always be tagged as "Content-Disposition: attachment", not "inline".
DANGEROUS_EXT = %w[svg]
DANGEROUS_EXT = %w[svg].freeze
def image?
extension_match?(IMAGE_EXT)
......
......@@ -18,7 +18,7 @@
# end
#
class AddressableUrlValidator < ActiveModel::EachValidator
DEFAULT_OPTIONS = { protocols: %w(http https ssh git) }
DEFAULT_OPTIONS = { protocols: %w(http https ssh git) }.freeze
def validate_each(record, attribute, value)
unless valid_url?(value)
......
module Gollum
GIT_ADAPTER = "rugged"
GIT_ADAPTER = "rugged".freeze
end
require "gollum-lib"
......
......@@ -10,7 +10,7 @@ end
#
module Gitlab
module StrongParameterScalars
GITLAB_PERMITTED_SCALAR_TYPES = [::UploadedFile]
GITLAB_PERMITTED_SCALAR_TYPES = [::UploadedFile].freeze
def permitted_scalar?(value)
super || GITLAB_PERMITTED_SCALAR_TYPES.any? { |type| value.is_a?(type) }
......
WIKI_SLUG_ID = { id: /\S+/ } unless defined? WIKI_SLUG_ID
WIKI_SLUG_ID = { id: /\S+/ }.freeze unless defined? WIKI_SLUG_ID
scope(controller: :wikis) do
scope(path: 'wikis', as: :wikis) do
......
......@@ -3,7 +3,7 @@
class MoveFromDevelopersCanMergeToProtectedBranchesMergeAccess < ActiveRecord::Migration
DOWNTIME = true
DOWNTIME_REASON = <<-HEREDOC
DOWNTIME_REASON = <<-HEREDOC.freeze
We're creating a `merge_access_level` for each `protected_branch`. If a user creates a `protected_branch` while this
is running, we might be left with a `protected_branch` _without_ an associated `merge_access_level`. The `protected_branches`
table must not change while this is running, so downtime is required.
......
......@@ -3,7 +3,7 @@
class MoveFromDevelopersCanPushToProtectedBranchesPushAccess < ActiveRecord::Migration
DOWNTIME = true
DOWNTIME_REASON = <<-HEREDOC
DOWNTIME_REASON = <<-HEREDOC.freeze
We're creating a `push_access_level` for each `protected_branch`. If a user creates a `protected_branch` while this
is running, we might be left with a `protected_branch` _without_ an associated `push_access_level`. The `protected_branches`
table must not change while this is running, so downtime is required.
......
......@@ -10,7 +10,7 @@ class RemoveProjectIdFromSpamLogs < ActiveRecord::Migration
# When a migration requires downtime you **must** uncomment the following
# constant and define a short and easy to understand explanation as to why the
# migration requires downtime.
DOWNTIME_REASON = 'Removing a column that contains data that is not used anywhere.'
DOWNTIME_REASON = 'Removing a column that contains data that is not used anywhere.'.freeze
# When using the methods "add_concurrent_index" or "add_column_with_default"
# you must disable the use of transactions as these methods can not run in an
......
......@@ -2,7 +2,7 @@ class ChangeMergeErrorToText < ActiveRecord::Migration
include Gitlab::Database::MigrationHelpers
DOWNTIME = true
DOWNTIME_REASON = 'This migration requires downtime because it alters a column from varchar(255) to text.'
DOWNTIME_REASON = 'This migration requires downtime because it alters a column from varchar(255) to text.'.freeze
def change
change_column :merge_requests, :merge_error, :text, limit: 65535
......
......@@ -10,7 +10,7 @@ class AddTableIssueMetrics < ActiveRecord::Migration
# When a migration requires downtime you **must** uncomment the following
# constant and define a short and easy to understand explanation as to why the
# migration requires downtime.
DOWNTIME_REASON = 'Adding foreign key'
DOWNTIME_REASON = 'Adding foreign key'.freeze
# When using the methods "add_concurrent_index" or "add_column_with_default"
# you must disable the use of transactions as these methods can not run in an
......
......@@ -10,7 +10,7 @@ class AddTableMergeRequestMetrics < ActiveRecord::Migration
# When a migration requires downtime you **must** uncomment the following
# constant and define a short and easy to understand explanation as to why the
# migration requires downtime.
DOWNTIME_REASON = 'Adding foreign key'
DOWNTIME_REASON = 'Adding foreign key'.freeze
# When using the methods "add_concurrent_index" or "add_column_with_default"
# you must disable the use of transactions as these methods can not run in an
......
......@@ -26,7 +26,7 @@ class AddMarkdownCacheColumns < ActiveRecord::Migration
projects: [:description],
releases: [:description],
snippets: [:title, :content],
}
}.freeze
def change
COLUMNS.each do |table, columns|
......
......@@ -3,7 +3,7 @@ class MigrateProjectFeatures < ActiveRecord::Migration
DOWNTIME = true
DOWNTIME_REASON =
<<-EOT
<<-EOT.freeze
Migrating issues_enabled, merge_requests_enabled, wiki_enabled, builds_enabled, snippets_enabled fields from projects to
a new table called project_features.
EOT
......
......@@ -7,7 +7,7 @@ class RemoveFeaturesEnabledFromProjects < ActiveRecord::Migration
# Set this constant to true if this migration requires downtime.
DOWNTIME = true
DOWNTIME_REASON = "Removing fields from database requires downtine."
DOWNTIME_REASON = "Removing fields from database requires downtine.".freeze
def up
remove_column :projects, :issues_enabled
......
......@@ -5,7 +5,7 @@ class RemoveProjectsPushesSinceGc < ActiveRecord::Migration
include Gitlab::Database::MigrationHelpers
DOWNTIME = true
DOWNTIME_REASON = 'This migration removes an existing column'
DOWNTIME_REASON = 'This migration removes an existing column'.freeze
disable_ddl_transaction!
......
......@@ -3,7 +3,7 @@ class ChangeArtifactsSizeColumn < ActiveRecord::Migration
DOWNTIME = true
DOWNTIME_REASON = 'Changing an integer column size requires a full table rewrite.'
DOWNTIME_REASON = 'Changing an integer column size requires a full table rewrite.'.freeze
def up
change_column :ci_builds, :artifacts_size, :integer, limit: 8
......
......@@ -10,7 +10,7 @@ class CreateMergeRequestsClosingIssues < ActiveRecord::Migration
# When a migration requires downtime you **must** uncomment the following
# constant and define a short and easy to understand explanation as to why the
# migration requires downtime.
DOWNTIME_REASON = 'Adding foreign keys'
DOWNTIME_REASON = 'Adding foreign keys'.freeze
# When using the methods "add_concurrent_index" or "add_column_with_default"
# you must disable the use of transactions as these methods can not run in an
......
......@@ -2,7 +2,7 @@ class AddTypeToLabels < ActiveRecord::Migration
include Gitlab::Database::MigrationHelpers
DOWNTIME = true
DOWNTIME_REASON = 'Labels will not work as expected until this migration is complete.'
DOWNTIME_REASON = 'Labels will not work as expected until this migration is complete.'.freeze
def change
add_column :labels, :type, :string
......
......@@ -2,7 +2,7 @@ class CreateLabelPriorities < ActiveRecord::Migration
include Gitlab::Database::MigrationHelpers
DOWNTIME = true
DOWNTIME_REASON = 'This migration adds foreign keys'
DOWNTIME_REASON = 'This migration adds foreign keys'.freeze
disable_ddl_transaction!
......
......@@ -2,7 +2,7 @@ class AddUniqueIndexToLabels < ActiveRecord::Migration
include Gitlab::Database::MigrationHelpers
DOWNTIME = true
DOWNTIME_REASON = 'This migration removes duplicated labels.'
DOWNTIME_REASON = 'This migration removes duplicated labels.'.freeze
disable_ddl_transaction!
......
......@@ -2,7 +2,7 @@ class MigrateLabelsPriority < ActiveRecord::Migration
include Gitlab::Database::MigrationHelpers
DOWNTIME = true
DOWNTIME_REASON = 'Prioritized labels will not work as expected until this migration is complete.'
DOWNTIME_REASON = 'Prioritized labels will not work as expected until this migration is complete.'.freeze
disable_ddl_transaction!
......
......@@ -2,7 +2,7 @@ class RemovePriorityFromLabels < ActiveRecord::Migration
include Gitlab::Database::MigrationHelpers
DOWNTIME = true
DOWNTIME_REASON = 'This migration removes an existing column'
DOWNTIME_REASON = 'This migration removes an existing column'.freeze
disable_ddl_transaction!
......
......@@ -8,7 +8,7 @@ class MigrateSidekiqQueuesFromDefault < ActiveRecord::Migration
DOWNTIME = true
DOWNTIME_REASON = <<-EOF
DOWNTIME_REASON = <<-EOF.freeze
Moving Sidekiq jobs from queues requires Sidekiq to be stopped. Not stopping
Sidekiq will result in the loss of jobs that are scheduled after this
migration completes.
......@@ -71,7 +71,7 @@ class MigrateSidekiqQueuesFromDefault < ActiveRecord::Migration
'StuckCiBuildsWorker' => :cronjob,
'UpdateMergeRequestsWorker' => :update_merge_requests
}
}
}.freeze
def up
Sidekiq.redis do |redis|
......
class GenerateProjectFeatureForProjects < ActiveRecord::Migration
DOWNTIME = true
DOWNTIME_REASON = <<-HEREDOC
DOWNTIME_REASON = <<-HEREDOC.freeze
Application was eager loading project_feature for all projects generating an extra query
everytime a project was fetched. We removed that behavior to avoid the extra query, this migration
makes sure all projects have a project_feature record associated.
......