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 24 additions and 24 deletions
Loading
Loading
@@ -24,7 +24,7 @@ module Gitlab
def commit_title
commit = commits.last
 
return nil unless commit && commit[:message]
return unless commit && commit[:message]
 
index = commit[:message].index("\n")
message = index ? commit[:message][0..index] : commit[:message]
Loading
Loading
Loading
Loading
@@ -127,7 +127,7 @@ module Gitlab
 
full_path = matchd[1]
project = Gitlab::BackgroundMigration::PopulateUntrackedUploadsDependencies::Project.find_by_full_path(full_path)
return nil unless project
return unless project
 
project.id
end
Loading
Loading
Loading
Loading
@@ -108,7 +108,7 @@ module Gitlab
end
 
def find_or_create_groups
return nil unless group_path.present?
return unless group_path.present?
 
log " * Using namespace: #{group_path}"
 
Loading
Loading
Loading
Loading
@@ -47,7 +47,7 @@ module Gitlab
 
# rubocop: disable CodeReuse/ActiveRecord
def find_user_id(username)
return nil unless username
return unless username
 
return users[username] if users.key?(username)
 
Loading
Loading
Loading
Loading
@@ -65,7 +65,7 @@ module Gitlab
end
 
def find_user_id(email)
return nil unless email
return unless email
 
return users[email] if users.key?(email)
 
Loading
Loading
Loading
Loading
@@ -313,7 +313,7 @@ module Gitlab
 
def get_term_color_class(color_index, prefix)
color_name = COLOR[color_index]
return nil if color_name.nil?
return if color_name.nil?
 
get_color_class(["term", prefix, color_name])
end
Loading
Loading
Loading
Loading
@@ -103,7 +103,7 @@ module Gitlab
 
def read_string(gz)
string_size = read_uint32(gz)
return nil unless string_size
return unless string_size
 
gz.read(string_size)
end
Loading
Loading
Loading
Loading
@@ -44,7 +44,7 @@ module Gitlab
end
 
def parent
return nil unless has_parent?
return unless has_parent?
 
self.class.new(@path.to_s.chomp(basename), @entries)
end
Loading
Loading
Loading
Loading
@@ -40,11 +40,11 @@ module Gitlab
end
 
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]
 
return nil if commits.blank?
return if commits.blank?
 
commits.find do |commit|
next unless commit[:committed_date] && event['first_mentioned_in_commit_at']
Loading
Loading
Loading
Loading
@@ -36,7 +36,7 @@ module Gitlab
 
def perform_count(model, estimate)
# 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
# The table is considered small, the assumption here is that
Loading
Loading
Loading
Loading
@@ -75,7 +75,7 @@ module Gitlab
end
 
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
# commented on, and in this context, it's normally the raw diff persisted
Loading
Loading
Loading
Loading
@@ -61,7 +61,7 @@ module Gitlab
 
# Force encoding to UTF-8 on a Mail::Message or Mail::Part
def fix_charset(object)
return nil if object.nil?
return if object.nil?
 
if object.charset
object.body.decoded.force_encoding(object.charset.gsub(/utf8/i, "UTF-8")).encode("UTF-8").to_s
Loading
Loading
Loading
Loading
@@ -239,7 +239,7 @@ module Gitlab
 
res = ::Projects::DownloadService.new(project, link).execute
 
return nil if res.nil?
return if res.nil?
 
res[:markdown]
end
Loading
Loading
Loading
Loading
@@ -58,10 +58,10 @@ module Gitlab
return commit_id if commit_id.is_a?(Gitlab::Git::Commit)
 
# 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.
return nil if commit_id.include?(':')
return if commit_id.include?(':')
 
commit = find_commit(repo, commit_id)
 
Loading
Loading
Loading
Loading
@@ -276,7 +276,7 @@ module Gitlab
# senddata response.
def archive_file_path(storage_path, sha, name, format = "tar.gz")
# Build file path
return nil unless name
return unless name
 
extension =
case format
Loading
Loading
Loading
Loading
@@ -44,7 +44,7 @@ module Gitlab
entry[:name] == path_arr[0] && entry[:type] == :tree
end
 
return nil unless entry
return unless entry
 
if path_arr.size > 1
path_arr.shift
Loading
Loading
Loading
Loading
@@ -384,13 +384,13 @@ module Gitlab
 
# Returns the stacks that calls Gitaly the most times. Used for n+1 detection
def self.max_stacks
return nil unless Gitlab::SafeRequestStore.active?
return unless Gitlab::SafeRequestStore.active?
 
stack_counter = Gitlab::SafeRequestStore[:stack_counter]
return nil unless stack_counter
return unless stack_counter
 
max = max_call_count
return nil if max.zero?
return if max.zero?
 
stack_counter.select { |_, v| v == max }.keys
end
Loading
Loading
Loading
Loading
@@ -27,7 +27,7 @@ module Gitlab
data << msg.data
end
 
return nil if blob.oid.blank?
return if blob.oid.blank?
 
data = data.join
 
Loading
Loading
Loading
Loading
@@ -62,7 +62,7 @@ module Gitlab
end
 
branch = response.branch
return nil unless branch
return unless branch
 
target_commit = Gitlab::Git::Commit.decorate(@repository, branch.target_commit)
Gitlab::Git::Branch.new(@repository, branch.name, target_commit.id, target_commit)
Loading
Loading
Loading
Loading
@@ -39,7 +39,7 @@ module Gitlab
private
 
def custom_language
return nil unless @language
return unless @language
 
Rouge::Lexer.find_fancy(@language)
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