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 32 additions and 29 deletions
Loading
Loading
@@ -181,3 +181,6 @@ Cop/InjectEnterpriseEditionModule:
Exclude:
- 'spec/**/*'
- 'ee/spec/**/*'
Style/ReturnNil:
Enabled: true
Loading
Loading
@@ -6,7 +6,7 @@ module ContinueParams
 
def continue_params
continue_params = params[:continue]
return nil unless continue_params
return unless continue_params
 
continue_params = continue_params.permit(:to, :notice, :notice_now)
continue_params[:to] = safe_redirect_path(continue_params[:to])
Loading
Loading
Loading
Loading
@@ -16,7 +16,7 @@ module RendersNotes
private
 
def preload_max_access_for_authors(notes, project)
return nil unless project
return unless project
 
user_ids = notes.map(&:author_id)
project.team.max_member_access_for_user_ids(user_ids)
Loading
Loading
Loading
Loading
@@ -17,7 +17,7 @@ class Projects::ApplicationController < ApplicationController
 
def 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])
auth_proc = ->(project) { !project.pending_delete? }
Loading
Loading
Loading
Loading
@@ -46,8 +46,8 @@ class Projects::MergeRequests::DiffsController < Projects::MergeRequests::Applic
 
# rubocop: disable CodeReuse/ActiveRecord
def commit
return nil unless commit_id = params[:commit_id].presence
return nil unless @merge_request.all_commits.exists?(sha: commit_id)
return unless commit_id = params[:commit_id].presence
return unless @merge_request.all_commits.exists?(sha: commit_id)
 
@commit ||= @project.commit(commit_id)
end
Loading
Loading
Loading
Loading
@@ -28,13 +28,13 @@ class UploadsController < ApplicationController
end
 
def find_model
return nil unless params[:id]
return unless params[:id]
 
upload_model_class.find(params[:id])
end
 
def authorize_access!
return nil unless model
return unless model
 
authorized =
case model
Loading
Loading
@@ -54,7 +54,7 @@ class UploadsController < ApplicationController
end
 
def authorize_create_access!
return nil unless model
return unless model
 
# for now we support only personal snippets comments
authorized = can?(current_user, :comment_personal_snippet, model)
Loading
Loading
Loading
Loading
@@ -74,7 +74,7 @@ module MarkupHelper
# the tag contents are truncated without removing the closing tag.
def first_line_in_markdown(object, attribute, max_chars = nil, 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 << 'img' if options[:allow_images]
Loading
Loading
Loading
Loading
@@ -29,7 +29,7 @@ module MergeRequestsHelper
 
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)
return nil unless build_url
return unless build_url
 
parsed_url = URI.parse(build_url)
 
Loading
Loading
@@ -92,7 +92,7 @@ module MergeRequestsHelper
end
 
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)
end
Loading
Loading
@@ -149,7 +149,7 @@ module MergeRequestsHelper
 
def merge_request_source_project_for_project(project = @project)
unless can?(current_user, :create_merge_request_in, project)
return nil
return
end
 
if can?(current_user, :create_merge_request_from, project)
Loading
Loading
Loading
Loading
@@ -122,7 +122,7 @@ module NotesHelper
end
 
def new_form_url
return nil unless @snippet.is_a?(PersonalSnippet)
return unless @snippet.is_a?(PersonalSnippet)
 
snippet_notes_path(@snippet)
end
Loading
Loading
Loading
Loading
@@ -735,7 +735,7 @@ module Ci
 
# Virtual deployment status depending on the environment status.
def deployment_status
return nil unless starts_environment?
return unless starts_environment?
 
if success?
return successful_deployment_status
Loading
Loading
Loading
Loading
@@ -134,25 +134,25 @@ class CommitRange
end
 
def sha_from
return nil unless @commit_from
return unless @commit_from
 
@commit_from.id
end
 
def sha_to
return nil unless @commit_to
return unless @commit_to
 
@commit_to.id
end
 
def sha_start
return nil unless sha_from
return unless sha_from
 
exclude_start? ? sha_from + '^' : sha_from
end
 
def commit_start
return nil unless sha_start
return unless sha_start
 
if exclude_start?
@commit_start ||= project.commit(sha_start)
Loading
Loading
Loading
Loading
@@ -5,7 +5,7 @@ module BlobLanguageFromGitAttributes
extend ActiveSupport::Concern
 
def language_from_gitattributes
return nil unless project
return unless project
 
repository = project.repository
repository.gitattribute(path, 'gitlab-language')
Loading
Loading
Loading
Loading
@@ -2,7 +2,7 @@
 
module FeatureGate
def flipper_id
return nil if new_record?
return if new_record?
 
"#{self.class.name}:#{id}"
end
Loading
Loading
Loading
Loading
@@ -79,7 +79,7 @@ module MirrorAuthentication
end
 
def ssh_public_key
return nil if ssh_private_key.blank?
return if ssh_private_key.blank?
 
comment = "git@#{::Gitlab.config.gitlab.host}"
::SSHKey.new(ssh_private_key, comment: comment).ssh_public_key
Loading
Loading
Loading
Loading
@@ -69,7 +69,7 @@ module ReactiveCaching
def with_reactive_cache(*args, &blk)
unless within_reactive_cache_lifetime?(*args)
refresh_reactive_cache!(*args)
return nil
return
end
 
keep_alive_reactive_cache!(*args)
Loading
Loading
Loading
Loading
@@ -119,7 +119,7 @@ class Environment < ActiveRecord::Base
def first_deployment_for(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
deployments.find_by(iid: deployment_iid)
Loading
Loading
@@ -130,7 +130,7 @@ class Environment < ActiveRecord::Base
end
 
def formatted_external_url
return nil unless external_url
return unless external_url
 
external_url.gsub(%r{\A.*?://}, '')
end
Loading
Loading
Loading
Loading
@@ -81,7 +81,7 @@ class LabelNote < Note
deleted = label_refs.count - existing_refs.count
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(' + ')
suffix = 'label'.pluralize(deleted > 0 ? deleted : existing_refs.count)
Loading
Loading
Loading
Loading
@@ -73,7 +73,7 @@ class LegacyDiffNote < Note
private
 
def find_diff
return nil unless noteable
return unless noteable
return @diff if defined?(@diff)
 
@diff = noteable.raw_diffs(Commit.max_diff_options).find do |d|
Loading
Loading
Loading
Loading
@@ -149,7 +149,7 @@ class Namespace < ApplicationRecord
end
 
def find_fork_of(project)
return nil unless project.fork_network
return unless project.fork_network
 
if Gitlab::SafeRequestStore.active?
forks_in_namespace = Gitlab::SafeRequestStore.fetch("namespaces:#{id}:forked_projects") do
Loading
Loading
Loading
Loading
@@ -119,7 +119,7 @@ class NotificationRecipient
private
 
def read_ability
return nil if @skip_read_ability
return if @skip_read_ability
return @read_ability if instance_variable_defined?(:@read_ability)
 
@read_ability =
Loading
Loading
@@ -136,7 +136,7 @@ class NotificationRecipient
end
 
def default_project
return nil if @target.nil?
return if @target.nil?
return @target if @target.is_a?(Project)
return @target.project if @target.respond_to?(:project)
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