Commit 397ab0fb authored by Rémy Coutable's avatar Rémy Coutable

Merge branch 'add-rubocop-return-nil-style' into 'master'

Adds Rubocop ReturnNil cop

Closes #57454

See merge request gitlab-org/gitlab-ce!25034
parents aef1de57 3288e1a8
...@@ -181,3 +181,6 @@ Cop/InjectEnterpriseEditionModule: ...@@ -181,3 +181,6 @@ Cop/InjectEnterpriseEditionModule:
Exclude: Exclude:
- 'spec/**/*' - 'spec/**/*'
- 'ee/spec/**/*' - 'ee/spec/**/*'
Style/ReturnNil:
Enabled: true
...@@ -6,7 +6,7 @@ module ContinueParams ...@@ -6,7 +6,7 @@ module ContinueParams
def continue_params def continue_params
continue_params = params[:continue] continue_params = params[:continue]
return nil unless continue_params return unless continue_params
continue_params = continue_params.permit(:to, :notice, :notice_now) continue_params = continue_params.permit(:to, :notice, :notice_now)
continue_params[:to] = safe_redirect_path(continue_params[:to]) continue_params[:to] = safe_redirect_path(continue_params[:to])
......
...@@ -16,7 +16,7 @@ module RendersNotes ...@@ -16,7 +16,7 @@ module RendersNotes
private private
def preload_max_access_for_authors(notes, project) def preload_max_access_for_authors(notes, project)
return nil unless project return unless project
user_ids = notes.map(&:author_id) user_ids = notes.map(&:author_id)
project.team.max_member_access_for_user_ids(user_ids) project.team.max_member_access_for_user_ids(user_ids)
......
...@@ -17,7 +17,7 @@ class Projects::ApplicationController < ApplicationController ...@@ -17,7 +17,7 @@ class Projects::ApplicationController < ApplicationController
def project def project
return @project if @project return @project if @project
return nil unless params[:project_id] || params[:id] return unless params[:project_id] || params[:id]
path = File.join(params[:namespace_id], params[:project_id] || params[:id]) path = File.join(params[:namespace_id], params[:project_id] || params[:id])
auth_proc = ->(project) { !project.pending_delete? } auth_proc = ->(project) { !project.pending_delete? }
......
...@@ -46,8 +46,8 @@ class Projects::MergeRequests::DiffsController < Projects::MergeRequests::Applic ...@@ -46,8 +46,8 @@ class Projects::MergeRequests::DiffsController < Projects::MergeRequests::Applic
# rubocop: disable CodeReuse/ActiveRecord # rubocop: disable CodeReuse/ActiveRecord
def commit def commit
return nil unless commit_id = params[:commit_id].presence return unless commit_id = params[:commit_id].presence
return nil unless @merge_request.all_commits.exists?(sha: commit_id) return unless @merge_request.all_commits.exists?(sha: commit_id)
@commit ||= @project.commit(commit_id) @commit ||= @project.commit(commit_id)
end end
......
...@@ -28,13 +28,13 @@ class UploadsController < ApplicationController ...@@ -28,13 +28,13 @@ class UploadsController < ApplicationController
end end
def find_model def find_model
return nil unless params[:id] return unless params[:id]
upload_model_class.find(params[:id]) upload_model_class.find(params[:id])
end end
def authorize_access! def authorize_access!
return nil unless model return unless model
authorized = authorized =
case model case model
...@@ -54,7 +54,7 @@ class UploadsController < ApplicationController ...@@ -54,7 +54,7 @@ class UploadsController < ApplicationController
end end
def authorize_create_access! def authorize_create_access!
return nil unless model return unless model
# for now we support only personal snippets comments # for now we support only personal snippets comments
authorized = can?(current_user, :comment_personal_snippet, model) authorized = can?(current_user, :comment_personal_snippet, model)
......
...@@ -74,7 +74,7 @@ module MarkupHelper ...@@ -74,7 +74,7 @@ module MarkupHelper
# the tag contents are truncated without removing the closing tag. # the tag contents are truncated without removing the closing tag.
def first_line_in_markdown(object, attribute, max_chars = nil, options = {}) def first_line_in_markdown(object, attribute, max_chars = nil, options = {})
md = markdown_field(object, attribute, options) md = markdown_field(object, attribute, options)
return nil unless md.present? return unless md.present?
tags = %w(a gl-emoji b pre code p span) tags = %w(a gl-emoji b pre code p span)
tags << 'img' if options[:allow_images] tags << 'img' if options[:allow_images]
......
...@@ -29,7 +29,7 @@ module MergeRequestsHelper ...@@ -29,7 +29,7 @@ module MergeRequestsHelper
def ci_build_details_path(merge_request) def ci_build_details_path(merge_request)
build_url = merge_request.source_project.ci_service.build_page(merge_request.diff_head_sha, merge_request.source_branch) build_url = merge_request.source_project.ci_service.build_page(merge_request.diff_head_sha, merge_request.source_branch)
return nil unless build_url return unless build_url
parsed_url = URI.parse(build_url) parsed_url = URI.parse(build_url)
...@@ -92,7 +92,7 @@ module MergeRequestsHelper ...@@ -92,7 +92,7 @@ module MergeRequestsHelper
end end
def version_index(merge_request_diff) def version_index(merge_request_diff)
return nil if @merge_request_diffs.empty? return if @merge_request_diffs.empty?
@merge_request_diffs.size - @merge_request_diffs.index(merge_request_diff) @merge_request_diffs.size - @merge_request_diffs.index(merge_request_diff)
end end
...@@ -149,7 +149,7 @@ module MergeRequestsHelper ...@@ -149,7 +149,7 @@ module MergeRequestsHelper
def merge_request_source_project_for_project(project = @project) def merge_request_source_project_for_project(project = @project)
unless can?(current_user, :create_merge_request_in, project) unless can?(current_user, :create_merge_request_in, project)
return nil return
end end
if can?(current_user, :create_merge_request_from, project) if can?(current_user, :create_merge_request_from, project)
......
...@@ -122,7 +122,7 @@ module NotesHelper ...@@ -122,7 +122,7 @@ module NotesHelper
end end
def new_form_url def new_form_url
return nil unless @snippet.is_a?(PersonalSnippet) return unless @snippet.is_a?(PersonalSnippet)
snippet_notes_path(@snippet) snippet_notes_path(@snippet)
end end
......
...@@ -735,7 +735,7 @@ module Ci ...@@ -735,7 +735,7 @@ module Ci
# Virtual deployment status depending on the environment status. # Virtual deployment status depending on the environment status.
def deployment_status def deployment_status
return nil unless starts_environment? return unless starts_environment?
if success? if success?
return successful_deployment_status return successful_deployment_status
......
...@@ -134,25 +134,25 @@ class CommitRange ...@@ -134,25 +134,25 @@ class CommitRange
end end
def sha_from def sha_from
return nil unless @commit_from return unless @commit_from
@commit_from.id @commit_from.id
end end
def sha_to def sha_to
return nil unless @commit_to return unless @commit_to
@commit_to.id @commit_to.id
end end
def sha_start def sha_start
return nil unless sha_from return unless sha_from
exclude_start? ? sha_from + '^' : sha_from exclude_start? ? sha_from + '^' : sha_from
end end
def commit_start def commit_start
return nil unless sha_start return unless sha_start
if exclude_start? if exclude_start?
@commit_start ||= project.commit(sha_start) @commit_start ||= project.commit(sha_start)
......
...@@ -5,7 +5,7 @@ module BlobLanguageFromGitAttributes ...@@ -5,7 +5,7 @@ module BlobLanguageFromGitAttributes
extend ActiveSupport::Concern extend ActiveSupport::Concern
def language_from_gitattributes def language_from_gitattributes
return nil unless project return unless project
repository = project.repository repository = project.repository
repository.gitattribute(path, 'gitlab-language') repository.gitattribute(path, 'gitlab-language')
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
module FeatureGate module FeatureGate
def flipper_id def flipper_id
return nil if new_record? return if new_record?
"#{self.class.name}:#{id}" "#{self.class.name}:#{id}"
end end
......
...@@ -79,7 +79,7 @@ module MirrorAuthentication ...@@ -79,7 +79,7 @@ module MirrorAuthentication
end end
def ssh_public_key def ssh_public_key
return nil if ssh_private_key.blank? return if ssh_private_key.blank?
comment = "git@#{::Gitlab.config.gitlab.host}" comment = "git@#{::Gitlab.config.gitlab.host}"
::SSHKey.new(ssh_private_key, comment: comment).ssh_public_key ::SSHKey.new(ssh_private_key, comment: comment).ssh_public_key
......
...@@ -69,7 +69,7 @@ module ReactiveCaching ...@@ -69,7 +69,7 @@ module ReactiveCaching
def with_reactive_cache(*args, &blk) def with_reactive_cache(*args, &blk)
unless within_reactive_cache_lifetime?(*args) unless within_reactive_cache_lifetime?(*args)
refresh_reactive_cache!(*args) refresh_reactive_cache!(*args)
return nil return
end end
keep_alive_reactive_cache!(*args) keep_alive_reactive_cache!(*args)
......
...@@ -119,7 +119,7 @@ class Environment < ActiveRecord::Base ...@@ -119,7 +119,7 @@ class Environment < ActiveRecord::Base
def first_deployment_for(commit_sha) def first_deployment_for(commit_sha)
ref = project.repository.ref_name_for_sha(ref_path, commit_sha) ref = project.repository.ref_name_for_sha(ref_path, commit_sha)
return nil unless ref return unless ref
deployment_iid = ref.split('/').last deployment_iid = ref.split('/').last
deployments.find_by(iid: deployment_iid) deployments.find_by(iid: deployment_iid)
...@@ -130,7 +130,7 @@ class Environment < ActiveRecord::Base ...@@ -130,7 +130,7 @@ class Environment < ActiveRecord::Base
end end
def formatted_external_url def formatted_external_url
return nil unless external_url return unless external_url
external_url.gsub(%r{\A.*?://}, '') external_url.gsub(%r{\A.*?://}, '')
end end
......
...@@ -81,7 +81,7 @@ class LabelNote < Note ...@@ -81,7 +81,7 @@ class LabelNote < Note
deleted = label_refs.count - existing_refs.count deleted = label_refs.count - existing_refs.count
deleted_str = deleted == 0 ? nil : "#{deleted} deleted" deleted_str = deleted == 0 ? nil : "#{deleted} deleted"
return nil unless refs_str || deleted_str return unless refs_str || deleted_str
label_list_str = [refs_str, deleted_str].compact.join(' + ') label_list_str = [refs_str, deleted_str].compact.join(' + ')
suffix = 'label'.pluralize(deleted > 0 ? deleted : existing_refs.count) suffix = 'label'.pluralize(deleted > 0 ? deleted : existing_refs.count)
......
...@@ -73,7 +73,7 @@ class LegacyDiffNote < Note ...@@ -73,7 +73,7 @@ class LegacyDiffNote < Note
private private
def find_diff def find_diff
return nil unless noteable return unless noteable
return @diff if defined?(@diff) return @diff if defined?(@diff)
@diff = noteable.raw_diffs(Commit.max_diff_options).find do |d| @diff = noteable.raw_diffs(Commit.max_diff_options).find do |d|
......
...@@ -149,7 +149,7 @@ class Namespace < ApplicationRecord ...@@ -149,7 +149,7 @@ class Namespace < ApplicationRecord
end end
def find_fork_of(project) def find_fork_of(project)
return nil unless project.fork_network return unless project.fork_network
if Gitlab::SafeRequestStore.active? if Gitlab::SafeRequestStore.active?
forks_in_namespace = Gitlab::SafeRequestStore.fetch("namespaces:#{id}:forked_projects") do forks_in_namespace = Gitlab::SafeRequestStore.fetch("namespaces:#{id}:forked_projects") do
......
...@@ -119,7 +119,7 @@ class NotificationRecipient ...@@ -119,7 +119,7 @@ class NotificationRecipient
private private
def read_ability def read_ability
return nil if @skip_read_ability return if @skip_read_ability
return @read_ability if instance_variable_defined?(:@read_ability) return @read_ability if instance_variable_defined?(:@read_ability)
@read_ability = @read_ability =
...@@ -136,7 +136,7 @@ class NotificationRecipient ...@@ -136,7 +136,7 @@ class NotificationRecipient
end end
def default_project def default_project
return nil if @target.nil? return if @target.nil?
return @target if @target.is_a?(Project) return @target if @target.is_a?(Project)
return @target.project if @target.respond_to?(:project) return @target.project if @target.respond_to?(:project)
end end
......
...@@ -1230,7 +1230,7 @@ class Project < ActiveRecord::Base ...@@ -1230,7 +1230,7 @@ class Project < ActiveRecord::Base
end end
def fork_source def fork_source
return nil unless forked? return unless forked?
forked_from_project || fork_network&.root_project forked_from_project || fork_network&.root_project
end end
...@@ -1679,7 +1679,7 @@ class Project < ActiveRecord::Base ...@@ -1679,7 +1679,7 @@ class Project < ActiveRecord::Base
end end
def export_path def export_path
return nil unless namespace.present? || hashed_storage?(:repository) return unless namespace.present? || hashed_storage?(:repository)
import_export_shared.archive_path import_export_shared.archive_path
end end
......
...@@ -57,7 +57,7 @@ class CampfireService < Service ...@@ -57,7 +57,7 @@ class CampfireService < Service
# https://github.com/basecamp/campfire-api/blob/master/sections/messages.md#create-message # https://github.com/basecamp/campfire-api/blob/master/sections/messages.md#create-message
def speak(room_name, message, auth) def speak(room_name, message, auth)
room = rooms(auth).find { |r| r["name"] == room_name } room = rooms(auth).find { |r| r["name"] == room_name }
return nil unless room return unless room
path = "/room/#{room["id"]}/speak.json" path = "/room/#{room["id"]}/speak.json"
body = { body = {
......
...@@ -112,7 +112,7 @@ class IrkerService < Service ...@@ -112,7 +112,7 @@ class IrkerService < Service
end end
def consider_uri(uri) def consider_uri(uri)
return nil if uri.scheme.nil? return if uri.scheme.nil?
# Authorize both irc://domain.com/#chan and irc://domain.com/chan # Authorize both irc://domain.com/#chan and irc://domain.com/chan
if uri.is_a?(URI) && uri.scheme[/^ircs?\z/] && !uri.path.nil? if uri.is_a?(URI) && uri.scheme[/^ircs?\z/] && !uri.path.nil?
......
...@@ -79,7 +79,7 @@ class Repository ...@@ -79,7 +79,7 @@ class Repository
end end
def raw_repository def raw_repository
return nil unless full_path return unless full_path
@raw_repository ||= initialize_raw_repository @raw_repository ||= initialize_raw_repository
end end
...@@ -103,7 +103,7 @@ class Repository ...@@ -103,7 +103,7 @@ class Repository
end end
def commit(ref = nil) def commit(ref = nil)
return nil unless exists? return unless exists?
return ref if ref.is_a?(::Commit) return ref if ref.is_a?(::Commit)
find_commit(ref || root_ref) find_commit(ref || root_ref)
......
...@@ -27,7 +27,7 @@ class SshHostKey ...@@ -27,7 +27,7 @@ class SshHostKey
def self.find_by(opts = {}) def self.find_by(opts = {})
opts = HashWithIndifferentAccess.new(opts) opts = HashWithIndifferentAccess.new(opts)
return nil unless opts.key?(:id) return unless opts.key?(:id)
project_id, url = opts[:id].split(':', 2) project_id, url = opts[:id].split(':', 2)
project = Project.find_by(id: project_id) project = Project.find_by(id: project_id)
......
...@@ -470,7 +470,7 @@ class User < ApplicationRecord ...@@ -470,7 +470,7 @@ class User < ApplicationRecord
end end
def by_login(login) def by_login(login)
return nil unless login return unless login
if login.include?('@'.freeze) if login.include?('@'.freeze)
unscoped.iwhere(email: login).take unscoped.iwhere(email: login).take
......
...@@ -132,7 +132,7 @@ class WikiPage ...@@ -132,7 +132,7 @@ class WikiPage
# The GitLab Commit instance for this page. # The GitLab Commit instance for this page.
def version def version
return nil unless persisted? return unless persisted?
@version ||= @page.version @version ||= @page.version
end end
......
...@@ -11,7 +11,7 @@ module UserStatusTooltip ...@@ -11,7 +11,7 @@ module UserStatusTooltip
expose :user_status_if_loaded, as: :status_tooltip_html expose :user_status_if_loaded, as: :status_tooltip_html
def user_status_if_loaded def user_status_if_loaded
return nil unless object.association(:status).loaded? return unless object.association(:status).loaded?
user_status(object) user_status(object)
end end
......
...@@ -38,7 +38,7 @@ module ApplicationSettings ...@@ -38,7 +38,7 @@ module ApplicationSettings
def performance_bar_allowed_group_id def performance_bar_allowed_group_id
performance_bar_enabled = !params.key?(:performance_bar_enabled) || params.delete(:performance_bar_enabled) performance_bar_enabled = !params.key?(:performance_bar_enabled) || params.delete(:performance_bar_enabled)
group_full_path = params.delete(:performance_bar_allowed_group_path) group_full_path = params.delete(:performance_bar_allowed_group_path)
return nil unless Gitlab::Utils.to_boolean(performance_bar_enabled) return unless Gitlab::Utils.to_boolean(performance_bar_enabled)
Group.find_by_full_path(group_full_path)&.id if group_full_path.present? Group.find_by_full_path(group_full_path)&.id if group_full_path.present?
end end
......
...@@ -4,7 +4,7 @@ module Boards ...@@ -4,7 +4,7 @@ module Boards
module Visits module Visits
class LatestService < Boards::BaseService class LatestService < Boards::BaseService
def execute def execute
return nil unless current_user return unless current_user
recent_visit_model.latest(current_user, parent, count: params[:count]) recent_visit_model.latest(current_user, parent, count: params[:count])
end end
......
...@@ -12,7 +12,7 @@ module Groups ...@@ -12,7 +12,7 @@ module Groups
end end
def execute def execute
return nil unless group_path return unless group_path
if namespace = namespace_or_group(group_path) if namespace = namespace_or_group(group_path)
return namespace return namespace
......
...@@ -11,7 +11,7 @@ module Projects ...@@ -11,7 +11,7 @@ module Projects
end end
def execute def execute
return nil unless valid_url?(@url) return unless valid_url?(@url)
uploader = FileUploader.new(@project) uploader = FileUploader.new(@project)
uploader.download!(@url) uploader.download!(@url)
......
...@@ -46,7 +46,7 @@ class PushEventPayloadService ...@@ -46,7 +46,7 @@ class PushEventPayloadService
def commit_title def commit_title
commit = @push_data.fetch(:commits).last commit = @push_data.fetch(:commits).last
return nil unless commit && commit[:message] return unless commit && commit[:message]
raw_msg = commit[:message] raw_msg = commit[:message]
......
...@@ -6,7 +6,7 @@ class UploadService ...@@ -6,7 +6,7 @@ class UploadService
end end
def execute def execute
return nil unless @file && @file.size <= max_attachment_size return unless @file && @file.size <= max_attachment_size
uploader = @uploader_class.new(@model, nil, @uploader_context) uploader = @uploader_class.new(@model, nil, @uploader_context)
uploader.store!(@file) uploader.store!(@file)
......
...@@ -149,7 +149,7 @@ module API ...@@ -149,7 +149,7 @@ module API
def conditions(pagination) def conditions(pagination)
fields = pagination.fields fields = pagination.fields
return nil if fields.empty? return if fields.empty?
placeholder = fields.map { '?' } placeholder = fields.map { '?' }
......
...@@ -25,13 +25,13 @@ module BitbucketServer ...@@ -25,13 +25,13 @@ module BitbucketServer
end end
def prev_page def prev_page
return nil unless current_page > 1 return unless current_page > 1
current_page - 1 current_page - 1
end end
def next_page def next_page
return nil unless has_next_page? return unless has_next_page?
current_page + 1 current_page + 1
end end
......
...@@ -84,7 +84,7 @@ module DeclarativePolicy ...@@ -84,7 +84,7 @@ module DeclarativePolicy
# returns nil unless it's already cached # returns nil unless it's already cached
def cached_pass?(context) def cached_pass?(context)
condition = context.condition(@name) condition = context.condition(@name)
return nil unless condition.cached? return unless condition.cached?
condition.pass? condition.pass?
end end
...@@ -124,7 +124,7 @@ module DeclarativePolicy ...@@ -124,7 +124,7 @@ module DeclarativePolicy
def cached_pass?(context) def cached_pass?(context)
condition = delegated_context(context).condition(@name) condition = delegated_context(context).condition(@name)
return nil unless condition.cached? return unless condition.cached?
condition.pass? condition.pass?
rescue MissingDelegate rescue MissingDelegate
...@@ -161,7 +161,7 @@ module DeclarativePolicy ...@@ -161,7 +161,7 @@ module DeclarativePolicy
def cached_pass?(context) def cached_pass?(context)
runner = context.runner(@ability) runner = context.runner(@ability)
return nil unless runner.cached? return unless runner.cached?
runner.pass? runner.pass?
end end
......
...@@ -195,7 +195,7 @@ module Gitlab ...@@ -195,7 +195,7 @@ module Gitlab
def encryption_options def encryption_options
method = translate_method method = translate_method
return nil unless method return unless method
{ {
method: method, method: method,
...@@ -211,7 +211,7 @@ module Gitlab ...@@ -211,7 +211,7 @@ module Gitlab
return @tls_options if defined?(@tls_options) return @tls_options if defined?(@tls_options)
method = translate_method method = translate_method
return nil unless method return unless method
opts = if options['verify_certificates'] && method != 'plain' opts = if options['verify_certificates'] && method != 'plain'
# Dup so we don't accidentally overwrite the constant # Dup so we don't accidentally overwrite the constant
......
...@@ -112,7 +112,7 @@ module Gitlab ...@@ -112,7 +112,7 @@ module Gitlab
attributes = Array(config.attributes[attribute.to_s]) attributes = Array(config.attributes[attribute.to_s])
selected_attr = attributes.find { |attr| entry.respond_to?(attr) } selected_attr = attributes.find { |attr| entry.respond_to?(attr) }
return nil unless selected_attr return unless selected_attr
entry.public_send(selected_attr) # rubocop:disable GitlabSecurity/PublicSend entry.public_send(selected_attr) # rubocop:disable GitlabSecurity/PublicSend
end end
......
...@@ -10,11 +10,11 @@ module Gitlab ...@@ -10,11 +10,11 @@ module Gitlab
def authn_context def authn_context
response_object = auth_hash.extra[:response_object] response_object = auth_hash.extra[:response_object]
return nil if response_object.blank? return if response_object.blank?
document = response_object.decrypted_document document = response_object.decrypted_document
document ||= response_object.document document ||= response_object.document
return nil if document.blank? return if document.blank?
extract_authn_context(document) extract_authn_context(document)
end end
......
...@@ -24,7 +24,7 @@ module Gitlab ...@@ -24,7 +24,7 @@ module Gitlab
def commit_title def commit_title
commit = commits.last commit = commits.last
return nil unless commit && commit[:message] return unless commit && commit[:message]
index = commit[:message].index("\n") index = commit[:message].index("\n")
message = index ? commit[:message][0..index] : commit[:message] message = index ? commit[:message][0..index] : commit[:message]
......
...@@ -127,7 +127,7 @@ module Gitlab ...@@ -127,7 +127,7 @@ module Gitlab
full_path = matchd[1] full_path = matchd[1]
project = Gitlab::BackgroundMigration::PopulateUntrackedUploadsDependencies::Project.find_by_full_path(full_path) project = Gitlab::BackgroundMigration::PopulateUntrackedUploadsDependencies::Project.find_by_full_path(full_path)
return nil unless project return unless project
project.id project.id
end end
......
...@@ -108,7 +108,7 @@ module Gitlab ...@@ -108,7 +108,7 @@ module Gitlab
end end
def find_or_create_groups def find_or_create_groups
return nil unless group_path.present? return unless group_path.present?
log " * Using namespace: #{group_path}" log " * Using namespace: #{group_path}"
......
...@@ -47,7 +47,7 @@ module Gitlab ...@@ -47,7 +47,7 @@ module Gitlab
# rubocop: disable CodeReuse/ActiveRecord # rubocop: disable CodeReuse/ActiveRecord
def find_user_id(username) def find_user_id(username)
return nil unless username return unless username
return users[username] if users.key?(username) return users[username] if users.key?(username)
......
...@@ -65,7 +65,7 @@ module Gitlab ...@@ -65,7 +65,7 @@ module Gitlab
end end
def find_user_id(email) def find_user_id(email)
return nil unless email return unless email
return users[email] if users.key?(email) return users[email] if users.key?(email)
......
...@@ -313,7 +313,7 @@ module Gitlab ...@@ -313,7 +313,7 @@ module Gitlab
def get_term_color_class(color_index, prefix) def get_term_color_class(color_index, prefix)
color_name = COLOR[color_index] color_name = COLOR[color_index]
return nil if color_name.nil? return if color_name.nil?
get_color_class(["term", prefix, color_name]) get_color_class(["term", prefix, color_name])
end end
......
...@@ -103,7 +103,7 @@ module Gitlab ...@@ -103,7 +103,7 @@ module Gitlab
def read_string(gz) def read_string(gz)
string_size = read_uint32(gz) string_size = read_uint32(gz)
return nil unless string_size return unless string_size
gz.read(string_size) gz.read(string_size)
end end
......
...@@ -44,7 +44,7 @@ module Gitlab ...@@ -44,7 +44,7 @@ module Gitlab
end end
def parent def parent
return nil unless has_parent? return unless has_parent?
self.class.new(@path.to_s.chomp(basename), @entries) self.class.new(@path.to_s.chomp(basename), @entries)
end end
......
...@@ -40,11 +40,11 @@ module Gitlab ...@@ -40,11 +40,11 @@ module Gitlab
end end
def first_time_reference_commit(event) def first_time_reference_commit(event)
return nil unless event && merge_request_diff_commits return unless event && merge_request_diff_commits
commits = merge_request_diff_commits[event['id'].to_i] commits = merge_request_diff_commits[event['id'].to_i]
return nil if commits.blank? return if commits.blank?
commits.find do |commit| commits.find do |commit|
next unless commit[:committed_date] && event['first_mentioned_in_commit_at'] next unless commit[:committed_date] && event['first_mentioned_in_commit_at']
......
...@@ -36,7 +36,7 @@ module Gitlab ...@@ -36,7 +36,7 @@ module Gitlab
def perform_count(model, estimate) def perform_count(model, estimate)
# If we estimate 0, we may not have statistics at all. Don't use them. # If we estimate 0, we may not have statistics at all. Don't use them.
return nil unless estimate && estimate > 0 return unless estimate && estimate > 0
if estimate < EXACT_COUNT_THRESHOLD if estimate < EXACT_COUNT_THRESHOLD
# The table is considered small, the assumption here is that # The table is considered small, the assumption here is that
......
...@@ -75,7 +75,7 @@ module Gitlab ...@@ -75,7 +75,7 @@ module Gitlab
end end
def line_for_position(pos) def line_for_position(pos)
return nil unless pos.position_type == 'text' return unless pos.position_type == 'text'
# This method is normally used to find which line the diff was # This method is normally used to find which line the diff was
# commented on, and in this context, it's normally the raw diff persisted # commented on, and in this context, it's normally the raw diff persisted
......
...@@ -61,7 +61,7 @@ module Gitlab ...@@ -61,7 +61,7 @@ module Gitlab
# Force encoding to UTF-8 on a Mail::Message or Mail::Part # Force encoding to UTF-8 on a Mail::Message or Mail::Part
def fix_charset(object) def fix_charset(object)
return nil if object.nil? return if object.nil?
if object.charset if object.charset
object.body.decoded.force_encoding(object.charset.gsub(/utf8/i, "UTF-8")).encode("UTF-8").to_s object.body.decoded.force_encoding(object.charset.gsub(/utf8/i, "UTF-8")).encode("UTF-8").to_s
......
...@@ -239,7 +239,7 @@ module Gitlab ...@@ -239,7 +239,7 @@ module Gitlab
res = ::Projects::DownloadService.new(project, link).execute res = ::Projects::DownloadService.new(project, link).execute
return nil if res.nil? return if res.nil?
res[:markdown] res[:markdown]
end end
......
...@@ -58,10 +58,10 @@ module Gitlab ...@@ -58,10 +58,10 @@ module Gitlab
return commit_id if commit_id.is_a?(Gitlab::Git::Commit) return commit_id if commit_id.is_a?(Gitlab::Git::Commit)
# Some weird thing? # Some weird thing?
return nil unless commit_id.is_a?(String) return unless commit_id.is_a?(String)
# This saves us an RPC round trip. # This saves us an RPC round trip.
return nil if commit_id.include?(':') return if commit_id.include?(':')
commit = find_commit(repo, commit_id) commit = find_commit(repo, commit_id)
......
...@@ -276,7 +276,7 @@ module Gitlab ...@@ -276,7 +276,7 @@ module Gitlab
# senddata response. # senddata response.
def archive_file_path(storage_path, sha, name, format = "tar.gz") def archive_file_path(storage_path, sha, name, format = "tar.gz")
# Build file path # Build file path
return nil unless name return unless name
extension = extension =
case format case format
......
...@@ -44,7 +44,7 @@ module Gitlab ...@@ -44,7 +44,7 @@ module Gitlab
entry[:name] == path_arr[0] && entry[:type] == :tree entry[:name] == path_arr[0] && entry[:type] == :tree
end end
return nil unless entry return unless entry
if path_arr.size > 1 if path_arr.size > 1
path_arr.shift path_arr.shift
......
...@@ -384,13 +384,13 @@ module Gitlab ...@@ -384,13 +384,13 @@ module Gitlab
# Returns the stacks that calls Gitaly the most times. Used for n+1 detection # Returns the stacks that calls Gitaly the most times. Used for n+1 detection
def self.max_stacks def self.max_stacks
return nil unless Gitlab::SafeRequestStore.active? return unless Gitlab::SafeRequestStore.active?
stack_counter = Gitlab::SafeRequestStore[:stack_counter] stack_counter = Gitlab::SafeRequestStore[:stack_counter]
return nil unless stack_counter return unless stack_counter
max = max_call_count max = max_call_count
return nil if max.zero? return if max.zero?
stack_counter.select { |_, v| v == max }.keys stack_counter.select { |_, v| v == max }.keys
end end
......
...@@ -27,7 +27,7 @@ module Gitlab ...@@ -27,7 +27,7 @@ module Gitlab
data << msg.data data << msg.data
end end
return nil if blob.oid.blank? return if blob.oid.blank?
data = data.join data = data.join
......
...@@ -62,7 +62,7 @@ module Gitlab ...@@ -62,7 +62,7 @@ module Gitlab
end end
branch = response.branch branch = response.branch
return nil unless branch return unless branch
target_commit = Gitlab::Git::Commit.decorate(@repository, branch.target_commit) target_commit = Gitlab::Git::Commit.decorate(@repository, branch.target_commit)
Gitlab::Git::Branch.new(@repository, branch.name, target_commit.id, target_commit) Gitlab::Git::Branch.new(@repository, branch.name, target_commit.id, target_commit)
......
...@@ -39,7 +39,7 @@ module Gitlab ...@@ -39,7 +39,7 @@ module Gitlab
private private
def custom_language def custom_language
return nil unless @language return unless @language
Rouge::Lexer.find_fancy(@language) Rouge::Lexer.find_fancy(@language)
end end
......
...@@ -15,7 +15,7 @@ module Gitlab ...@@ -15,7 +15,7 @@ module Gitlab
end end
def expected_forms def expected_forms
return nil unless plural_information return unless plural_information
plural_information['nplurals'].to_i plural_information['nplurals'].to_i
end end
......
...@@ -67,7 +67,7 @@ module Gitlab ...@@ -67,7 +67,7 @@ module Gitlab
# +value+ existing model to be included in the hash # +value+ existing model to be included in the hash
# +parsed_hash+ the original hash # +parsed_hash+ the original hash
def parse_hash(value) def parse_hash(value)
return nil if already_contains_methods?(value) return if already_contains_methods?(value)
@attributes_finder.parse(value) do |hash| @attributes_finder.parse(value) do |hash|
{ include: hash_or_merge(value, hash) } { include: hash_or_merge(value, hash) }
......
...@@ -75,7 +75,7 @@ module Gitlab ...@@ -75,7 +75,7 @@ module Gitlab
# the relation_hash, updating references with new object IDs, mapping users using # the relation_hash, updating references with new object IDs, mapping users using
# the "members_mapper" object, also updating notes if required. # the "members_mapper" object, also updating notes if required.
def create def create
return nil if unknown_service? return if unknown_service?
setup_models setup_models
......
...@@ -57,7 +57,7 @@ module Gitlab ...@@ -57,7 +57,7 @@ module Gitlab
def address_regex def address_regex
wildcard_address = config.address wildcard_address = config.address
return nil unless wildcard_address return unless wildcard_address
regex = Regexp.escape(wildcard_address) regex = Regexp.escape(wildcard_address)
regex = regex.sub(Regexp.escape(WILDCARD_PLACEHOLDER), '(.+)') regex = regex.sub(Regexp.escape(WILDCARD_PLACEHOLDER), '(.+)')
......
...@@ -68,7 +68,7 @@ module Gitlab ...@@ -68,7 +68,7 @@ module Gitlab
end end
def user(login) def user(login)
return nil unless login.present? return unless login.present?
return @users[login] if @users.key?(login) return @users[login] if @users.key?(login)
@users[login] = api.user(login) @users[login] = api.user(login)
......
...@@ -25,7 +25,7 @@ module Gitlab ...@@ -25,7 +25,7 @@ module Gitlab
end end
def find_by_email def find_by_email
return nil unless email return unless email
User.find_by_any_email(email) User.find_by_any_email(email)
.try(:id) .try(:id)
...@@ -33,7 +33,7 @@ module Gitlab ...@@ -33,7 +33,7 @@ module Gitlab
# rubocop: disable CodeReuse/ActiveRecord # rubocop: disable CodeReuse/ActiveRecord
def find_by_external_uid def find_by_external_uid
return nil unless id return unless id
identities = ::Identity.arel_table identities = ::Identity.arel_table
......
...@@ -33,7 +33,7 @@ module Gitlab ...@@ -33,7 +33,7 @@ module Gitlab
# `LOWER(column) = query` instead of using `ILIKE`. # `LOWER(column) = query` instead of using `ILIKE`.
def fuzzy_arel_match(column, query, lower_exact_match: false) def fuzzy_arel_match(column, query, lower_exact_match: false)
query = query.squish query = query.squish
return nil unless query.present? return unless query.present?
words = select_fuzzy_words(query) words = select_fuzzy_words(query)
......
...@@ -60,7 +60,7 @@ module Gitlab ...@@ -60,7 +60,7 @@ module Gitlab
elsif udp_endpoint.present? elsif udp_endpoint.present?
sender = get_udp_sender(encoder, udp_endpoint) sender = get_udp_sender(encoder, udp_endpoint)
else else
return nil return
end end
Jaeger::Reporters::RemoteReporter.new( Jaeger::Reporters::RemoteReporter.new(
......
...@@ -95,7 +95,7 @@ module Gitlab ...@@ -95,7 +95,7 @@ module Gitlab
end end
def cache_commit(commit) def cache_commit(commit)
return nil unless commit.present? return unless commit.present?
resolved_commits[commit.id] ||= commit resolved_commits[commit.id] ||= commit
end end
......
...@@ -53,7 +53,7 @@ module SystemCheck ...@@ -53,7 +53,7 @@ module SystemCheck
end end
def ssh_dir def ssh_dir
return nil unless home_dir return unless home_dir
File.join(home_dir, '.ssh') File.join(home_dir, '.ssh')
end end
......
...@@ -91,7 +91,7 @@ module ExportFileHelper ...@@ -91,7 +91,7 @@ module ExportFileHelper
loop do loop do
object_with_parent = deep_find_with_parent(sensitive_word, project_hash) object_with_parent = deep_find_with_parent(sensitive_word, project_hash)
return nil unless object_with_parent && object_with_parent.object return unless object_with_parent && object_with_parent.object
if is_safe_hash?(object_with_parent.parent, sensitive_word) if is_safe_hash?(object_with_parent.parent, sensitive_word)
# It's in the safe list, remove hash and keep looking # It's in the safe list, remove hash and keep looking
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment