Commit 001183da authored by Rémy Coutable's avatar Rémy Coutable
Browse files

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

Adds Rubocop ReturnNil cop

Closes #57454

See merge request gitlab-org/gitlab-ce!25034
......@@ -181,3 +181,6 @@ Cop/InjectEnterpriseEditionModule:
Exclude:
- 'spec/**/*'
- 'ee/spec/**/*'
Style/ReturnNil:
Enabled: true
......@@ -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])
......
......@@ -16,7 +16,7 @@ def prepare_notes_for_rendering(notes, noteable = nil)
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)
......
......@@ -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? }
......
......@@ -46,8 +46,8 @@ def define_diff_vars
# 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
......
......@@ -28,13 +28,13 @@ def uploader_class
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
......@@ -54,7 +54,7 @@ def authorize_access!
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)
......
......@@ -74,7 +74,7 @@ def link_to_html(redacted, url, html_options = {})
# 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]
......
......@@ -29,7 +29,7 @@ def mr_css_classes(mr)
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)
......@@ -92,7 +92,7 @@ def merge_request_version_path(project, merge_request, merge_request_diff, start
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
......@@ -149,7 +149,7 @@ def allow_collaboration_unavailable_reason(merge_request)
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)
......
......@@ -122,7 +122,7 @@ def form_resources
end
def new_form_url
return nil unless @snippet.is_a?(PersonalSnippet)
return unless @snippet.is_a?(PersonalSnippet)
snippet_notes_path(@snippet)
end
......
......@@ -735,7 +735,7 @@ def collect_test_reports!(test_reports)
# 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
......
......@@ -134,25 +134,25 @@ def persisted?
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)
......
......@@ -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')
......
......@@ -2,7 +2,7 @@
module FeatureGate
def flipper_id
return nil if new_record?
return if new_record?
"#{self.class.name}:#{id}"
end
......
......@@ -79,7 +79,7 @@ def auth_method
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
......
......@@ -69,7 +69,7 @@ def reactive_cache_updated(*args)
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)
......
......@@ -119,7 +119,7 @@ def update_merge_request_metrics?
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)
......@@ -130,7 +130,7 @@ def ref_path
end
def formatted_external_url
return nil unless external_url
return unless external_url
external_url.gsub(%r{\A.*?://}, '')
end
......
......@@ -81,7 +81,7 @@ def labels_str(prefix, label_refs)
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)
......
......@@ -73,7 +73,7 @@ def active?(diff_refs = nil)
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|
......
......@@ -149,7 +149,7 @@ def kind
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
......
......@@ -119,7 +119,7 @@ def excluded_participating_action?
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 =
......@@ -136,7 +136,7 @@ def read_ability
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
......
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