Skip to content
Snippets Groups Projects
Commit 3288e1a8 authored by Andrew Newdigate's avatar Andrew Newdigate
Browse files

Adds the Rubocop ReturnNil cop

This style change enforces `return if ...` instead of
`return nil if ...` to save maintainers a few minor review points
parent 7bbdb2a2
No related branches found
No related tags found
No related merge requests found
Showing
with 27 additions and 27 deletions
Loading
Loading
@@ -1230,7 +1230,7 @@ class Project < ActiveRecord::Base
end
 
def fork_source
return nil unless forked?
return unless forked?
 
forked_from_project || fork_network&.root_project
end
Loading
Loading
@@ -1679,7 +1679,7 @@ class Project < ActiveRecord::Base
end
 
def export_path
return nil unless namespace.present? || hashed_storage?(:repository)
return unless namespace.present? || hashed_storage?(:repository)
 
import_export_shared.archive_path
end
Loading
Loading
Loading
Loading
@@ -57,7 +57,7 @@ class CampfireService < Service
# https://github.com/basecamp/campfire-api/blob/master/sections/messages.md#create-message
def speak(room_name, message, auth)
room = rooms(auth).find { |r| r["name"] == room_name }
return nil unless room
return unless room
 
path = "/room/#{room["id"]}/speak.json"
body = {
Loading
Loading
Loading
Loading
@@ -112,7 +112,7 @@ class IrkerService < Service
end
 
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
if uri.is_a?(URI) && uri.scheme[/^ircs?\z/] && !uri.path.nil?
Loading
Loading
Loading
Loading
@@ -79,7 +79,7 @@ class Repository
end
 
def raw_repository
return nil unless full_path
return unless full_path
 
@raw_repository ||= initialize_raw_repository
end
Loading
Loading
@@ -103,7 +103,7 @@ class Repository
end
 
def commit(ref = nil)
return nil unless exists?
return unless exists?
return ref if ref.is_a?(::Commit)
 
find_commit(ref || root_ref)
Loading
Loading
Loading
Loading
@@ -27,7 +27,7 @@ class SshHostKey
 
def self.find_by(opts = {})
opts = HashWithIndifferentAccess.new(opts)
return nil unless opts.key?(:id)
return unless opts.key?(:id)
 
project_id, url = opts[:id].split(':', 2)
project = Project.find_by(id: project_id)
Loading
Loading
Loading
Loading
@@ -470,7 +470,7 @@ class User < ApplicationRecord
end
 
def by_login(login)
return nil unless login
return unless login
 
if login.include?('@'.freeze)
unscoped.iwhere(email: login).take
Loading
Loading
Loading
Loading
@@ -132,7 +132,7 @@ class WikiPage
 
# The GitLab Commit instance for this page.
def version
return nil unless persisted?
return unless persisted?
 
@version ||= @page.version
end
Loading
Loading
Loading
Loading
@@ -11,7 +11,7 @@ module UserStatusTooltip
expose :user_status_if_loaded, as: :status_tooltip_html
 
def user_status_if_loaded
return nil unless object.association(:status).loaded?
return unless object.association(:status).loaded?
 
user_status(object)
end
Loading
Loading
Loading
Loading
@@ -38,7 +38,7 @@ module ApplicationSettings
def performance_bar_allowed_group_id
performance_bar_enabled = !params.key?(:performance_bar_enabled) || params.delete(:performance_bar_enabled)
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?
end
Loading
Loading
Loading
Loading
@@ -4,7 +4,7 @@ module Boards
module Visits
class LatestService < Boards::BaseService
def execute
return nil unless current_user
return unless current_user
 
recent_visit_model.latest(current_user, parent, count: params[:count])
end
Loading
Loading
Loading
Loading
@@ -12,7 +12,7 @@ module Groups
end
 
def execute
return nil unless group_path
return unless group_path
 
if namespace = namespace_or_group(group_path)
return namespace
Loading
Loading
Loading
Loading
@@ -11,7 +11,7 @@ module Projects
end
 
def execute
return nil unless valid_url?(@url)
return unless valid_url?(@url)
 
uploader = FileUploader.new(@project)
uploader.download!(@url)
Loading
Loading
Loading
Loading
@@ -46,7 +46,7 @@ class PushEventPayloadService
def commit_title
commit = @push_data.fetch(:commits).last
 
return nil unless commit && commit[:message]
return unless commit && commit[:message]
 
raw_msg = commit[:message]
 
Loading
Loading
Loading
Loading
@@ -6,7 +6,7 @@ class UploadService
end
 
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.store!(@file)
Loading
Loading
Loading
Loading
@@ -149,7 +149,7 @@ module API
def conditions(pagination)
fields = pagination.fields
 
return nil if fields.empty?
return if fields.empty?
 
placeholder = fields.map { '?' }
 
Loading
Loading
Loading
Loading
@@ -25,13 +25,13 @@ module BitbucketServer
end
 
def prev_page
return nil unless current_page > 1
return unless current_page > 1
 
current_page - 1
end
 
def next_page
return nil unless has_next_page?
return unless has_next_page?
 
current_page + 1
end
Loading
Loading
Loading
Loading
@@ -84,7 +84,7 @@ module DeclarativePolicy
# returns nil unless it's already cached
def cached_pass?(context)
condition = context.condition(@name)
return nil unless condition.cached?
return unless condition.cached?
 
condition.pass?
end
Loading
Loading
@@ -124,7 +124,7 @@ module DeclarativePolicy
 
def cached_pass?(context)
condition = delegated_context(context).condition(@name)
return nil unless condition.cached?
return unless condition.cached?
 
condition.pass?
rescue MissingDelegate
Loading
Loading
@@ -161,7 +161,7 @@ module DeclarativePolicy
 
def cached_pass?(context)
runner = context.runner(@ability)
return nil unless runner.cached?
return unless runner.cached?
 
runner.pass?
end
Loading
Loading
Loading
Loading
@@ -195,7 +195,7 @@ module Gitlab
 
def encryption_options
method = translate_method
return nil unless method
return unless method
 
{
method: method,
Loading
Loading
@@ -211,7 +211,7 @@ module Gitlab
return @tls_options if defined?(@tls_options)
 
method = translate_method
return nil unless method
return unless method
 
opts = if options['verify_certificates'] && method != 'plain'
# Dup so we don't accidentally overwrite the constant
Loading
Loading
Loading
Loading
@@ -112,7 +112,7 @@ module Gitlab
attributes = Array(config.attributes[attribute.to_s])
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
end
Loading
Loading
Loading
Loading
@@ -10,11 +10,11 @@ module Gitlab
 
def authn_context
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.document
return nil if document.blank?
return if document.blank?
 
extract_authn_context(document)
end
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment