diff options
71 files changed, 95 insertions, 92 deletions
diff --git a/.rubocop.yml b/.rubocop.yml index bcff67ded8c..2985c1446e4 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -181,3 +181,6 @@ Cop/InjectEnterpriseEditionModule: Exclude: - 'spec/**/*' - 'ee/spec/**/*' + +Style/ReturnNil: + Enabled: true diff --git a/app/controllers/concerns/continue_params.rb b/app/controllers/concerns/continue_params.rb index f0e6adf4dec..54c0510497f 100644 --- a/app/controllers/concerns/continue_params.rb +++ b/app/controllers/concerns/continue_params.rb @@ -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]) diff --git a/app/controllers/concerns/renders_notes.rb b/app/controllers/concerns/renders_notes.rb index ce36da6b715..18015b1de88 100644 --- a/app/controllers/concerns/renders_notes.rb +++ b/app/controllers/concerns/renders_notes.rb @@ -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) diff --git a/app/controllers/projects/application_controller.rb b/app/controllers/projects/application_controller.rb index e0677ce3fbc..6504fd6c08a 100644 --- a/app/controllers/projects/application_controller.rb +++ b/app/controllers/projects/application_controller.rb @@ -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? } diff --git a/app/controllers/projects/merge_requests/diffs_controller.rb b/app/controllers/projects/merge_requests/diffs_controller.rb index 518d41bd3fb..456d2c34768 100644 --- a/app/controllers/projects/merge_requests/diffs_controller.rb +++ b/app/controllers/projects/merge_requests/diffs_controller.rb @@ -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 diff --git a/app/controllers/uploads_controller.rb b/app/controllers/uploads_controller.rb index 519e7439205..568c6e2a852 100644 --- a/app/controllers/uploads_controller.rb +++ b/app/controllers/uploads_controller.rb @@ -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 @@ -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) diff --git a/app/helpers/markup_helper.rb b/app/helpers/markup_helper.rb index 66f4b7b3f30..d83c69603a9 100644 --- a/app/helpers/markup_helper.rb +++ b/app/helpers/markup_helper.rb @@ -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] diff --git a/app/helpers/merge_requests_helper.rb b/app/helpers/merge_requests_helper.rb index 23d7aa427bb..991ca42c445 100644 --- a/app/helpers/merge_requests_helper.rb +++ b/app/helpers/merge_requests_helper.rb @@ -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) @@ -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 @@ -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) diff --git a/app/helpers/notes_helper.rb b/app/helpers/notes_helper.rb index aaf38cbfe70..a50137bea3d 100644 --- a/app/helpers/notes_helper.rb +++ b/app/helpers/notes_helper.rb @@ -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 diff --git a/app/models/ci/build.rb b/app/models/ci/build.rb index f39441a1e5b..a64c6051f95 100644 --- a/app/models/ci/build.rb +++ b/app/models/ci/build.rb @@ -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 diff --git a/app/models/commit_range.rb b/app/models/commit_range.rb index 094747ee48d..920b1d092dd 100644 --- a/app/models/commit_range.rb +++ b/app/models/commit_range.rb @@ -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) diff --git a/app/models/concerns/blob_language_from_git_attributes.rb b/app/models/concerns/blob_language_from_git_attributes.rb index 70213d22147..56e1276a220 100644 --- a/app/models/concerns/blob_language_from_git_attributes.rb +++ b/app/models/concerns/blob_language_from_git_attributes.rb @@ -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') diff --git a/app/models/concerns/feature_gate.rb b/app/models/concerns/feature_gate.rb index 3f84de54ad5..bb095f113e2 100644 --- a/app/models/concerns/feature_gate.rb +++ b/app/models/concerns/feature_gate.rb @@ -2,7 +2,7 @@ module FeatureGate def flipper_id - return nil if new_record? + return if new_record? "#{self.class.name}:#{id}" end diff --git a/app/models/concerns/mirror_authentication.rb b/app/models/concerns/mirror_authentication.rb index e3e1a0441f8..948094221e5 100644 --- a/app/models/concerns/mirror_authentication.rb +++ b/app/models/concerns/mirror_authentication.rb @@ -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 diff --git a/app/models/concerns/reactive_caching.rb b/app/models/concerns/reactive_caching.rb index de77ca3e963..d2ead7130e5 100644 --- a/app/models/concerns/reactive_caching.rb +++ b/app/models/concerns/reactive_caching.rb @@ -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) diff --git a/app/models/environment.rb b/app/models/environment.rb index 87bdb52b58b..3d909cc8e5c 100644 --- a/app/models/environment.rb +++ b/app/models/environment.rb @@ -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) @@ -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 diff --git a/app/models/label_note.rb b/app/models/label_note.rb index 680952cf421..d6814f4a948 100644 --- a/app/models/label_note.rb +++ b/app/models/label_note.rb @@ -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) diff --git a/app/models/legacy_diff_note.rb b/app/models/legacy_diff_note.rb index 00dec6bb92b..e2c75bc7ee9 100644 --- a/app/models/legacy_diff_note.rb +++ b/app/models/legacy_diff_note.rb @@ -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| diff --git a/app/models/namespace.rb b/app/models/namespace.rb index f7592532c5b..a5c479bdc0c 100644 --- a/app/models/namespace.rb +++ b/app/models/namespace.rb @@ -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 diff --git a/app/models/notification_recipient.rb b/app/models/notification_recipient.rb index 481c1d963c6..793cce191fa 100644 --- a/app/models/notification_recipient.rb +++ b/app/models/notification_recipient.rb @@ -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 = @@ -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 diff --git a/app/models/project.rb b/app/models/project.rb index 6db88c146b4..4cc13f372c1 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -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 @@ -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 diff --git a/app/models/project_services/campfire_service.rb b/app/models/project_services/campfire_service.rb index 1d7877a1fb5..ad26e42a21b 100644 --- a/app/models/project_services/campfire_service.rb +++ b/app/models/project_services/campfire_service.rb @@ -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 = { diff --git a/app/models/project_services/irker_service.rb b/app/models/project_services/irker_service.rb index 83fd9a34438..fb76bc89c98 100644 --- a/app/models/project_services/irker_service.rb +++ b/app/models/project_services/irker_service.rb @@ -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? diff --git a/app/models/repository.rb b/app/models/repository.rb index cd761a29618..851175a61b7 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -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 @@ -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) diff --git a/app/models/ssh_host_key.rb b/app/models/ssh_host_key.rb index fd23cc9ac87..b6fb39ee81f 100644 --- a/app/models/ssh_host_key.rb +++ b/app/models/ssh_host_key.rb @@ -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) diff --git a/app/models/user.rb b/app/models/user.rb index ee51c35d576..778c9e631bd 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -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 diff --git a/app/models/wiki_page.rb b/app/models/wiki_page.rb index b1d6d461928..64daba81dcf 100644 --- a/app/models/wiki_page.rb +++ b/app/models/wiki_page.rb @@ -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 diff --git a/app/serializers/concerns/user_status_tooltip.rb b/app/serializers/concerns/user_status_tooltip.rb index aa6e67e3351..633b117d392 100644 --- a/app/serializers/concerns/user_status_tooltip.rb +++ b/app/serializers/concerns/user_status_tooltip.rb @@ -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 diff --git a/app/services/application_settings/update_service.rb b/app/services/application_settings/update_service.rb index 2e4643ed668..9146eb96533 100644 --- a/app/services/application_settings/update_service.rb +++ b/app/services/application_settings/update_service.rb @@ -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 diff --git a/app/services/boards/visits/latest_service.rb b/app/services/boards/visits/latest_service.rb index d8de08c5844..d13e25b4f12 100644 --- a/app/services/boards/visits/latest_service.rb +++ b/app/services/boards/visits/latest_service.rb @@ -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 diff --git a/app/services/groups/nested_create_service.rb b/app/services/groups/nested_create_service.rb index f01f5656296..01bd685712b 100644 --- a/app/services/groups/nested_create_service.rb +++ b/app/services/groups/nested_create_service.rb @@ -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 diff --git a/app/services/projects/download_service.rb b/app/services/projects/download_service.rb index dd297c9ba43..aba175eb79b 100644 --- a/app/services/projects/download_service.rb +++ b/app/services/projects/download_service.rb @@ -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) diff --git a/app/services/push_event_payload_service.rb b/app/services/push_event_payload_service.rb index bb1259787af..fe366ac225b 100644 --- a/app/services/push_event_payload_service.rb +++ b/app/services/push_event_payload_service.rb @@ -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] diff --git a/app/services/upload_service.rb b/app/services/upload_service.rb index 41ca95b3b6f..403944557a2 100644 --- a/app/services/upload_service.rb +++ b/app/services/upload_service.rb @@ -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) diff --git a/lib/api/helpers/pagination.rb b/lib/api/helpers/pagination.rb index d00e61678b5..94b58a64d26 100644 --- a/lib/api/helpers/pagination.rb +++ b/lib/api/helpers/pagination.rb @@ -149,7 +149,7 @@ module API def conditions(pagination) fields = pagination.fields - return nil if fields.empty? + return if fields.empty? placeholder = fields.map { '?' } diff --git a/lib/bitbucket_server/collection.rb b/lib/bitbucket_server/collection.rb index 7e4b2277bbe..f549acbd87f 100644 --- a/lib/bitbucket_server/collection.rb +++ b/lib/bitbucket_server/collection.rb @@ -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 diff --git a/lib/declarative_policy/rule.rb b/lib/declarative_policy/rule.rb index f38f4f0a50f..964d35cde9e 100644 --- a/lib/declarative_policy/rule.rb +++ b/lib/declarative_policy/rule.rb @@ -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 @@ -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 @@ -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 diff --git a/lib/gitlab/auth/ldap/config.rb b/lib/gitlab/auth/ldap/config.rb index dddba85e629..47d63eb53cf 100644 --- a/lib/gitlab/auth/ldap/config.rb +++ b/lib/gitlab/auth/ldap/config.rb @@ -195,7 +195,7 @@ module Gitlab def encryption_options method = translate_method - return nil unless method + return unless method { method: method, @@ -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 diff --git a/lib/gitlab/auth/ldap/person.rb b/lib/gitlab/auth/ldap/person.rb index 48d134f91b0..13d67e0f871 100644 --- a/lib/gitlab/auth/ldap/person.rb +++ b/lib/gitlab/auth/ldap/person.rb @@ -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 diff --git a/lib/gitlab/auth/saml/auth_hash.rb b/lib/gitlab/auth/saml/auth_hash.rb index 1af9fa40c3a..b0df9757bbd 100644 --- a/lib/gitlab/auth/saml/auth_hash.rb +++ b/lib/gitlab/auth/saml/auth_hash.rb @@ -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 diff --git a/lib/gitlab/background_migration/migrate_events_to_push_event_payloads.rb b/lib/gitlab/background_migration/migrate_events_to_push_event_payloads.rb index 38fecac1bfe..42fcaa87e66 100644 --- a/lib/gitlab/background_migration/migrate_events_to_push_event_payloads.rb +++ b/lib/gitlab/background_migration/migrate_events_to_push_event_payloads.rb @@ -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] diff --git a/lib/gitlab/background_migration/populate_untracked_uploads_dependencies.rb b/lib/gitlab/background_migration/populate_untracked_uploads_dependencies.rb index 4a9a62aaeb5..a84f794bfae 100644 --- a/lib/gitlab/background_migration/populate_untracked_uploads_dependencies.rb +++ b/lib/gitlab/background_migration/populate_untracked_uploads_dependencies.rb @@ -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 diff --git a/lib/gitlab/bare_repository_import/importer.rb b/lib/gitlab/bare_repository_import/importer.rb index 3cd327f5109..144ba2ec031 100644 --- a/lib/gitlab/bare_repository_import/importer.rb +++ b/lib/gitlab/bare_repository_import/importer.rb @@ -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}" diff --git a/lib/gitlab/bitbucket_import/importer.rb b/lib/gitlab/bitbucket_import/importer.rb index 75a3f17f549..441fdec8a1e 100644 --- a/lib/gitlab/bitbucket_import/importer.rb +++ b/lib/gitlab/bitbucket_import/importer.rb @@ -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) diff --git a/lib/gitlab/bitbucket_server_import/importer.rb b/lib/gitlab/bitbucket_server_import/importer.rb index dbbedd5dcbe..4a789ae457f 100644 --- a/lib/gitlab/bitbucket_server_import/importer.rb +++ b/lib/gitlab/bitbucket_server_import/importer.rb @@ -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) diff --git a/lib/gitlab/ci/ansi2html.rb b/lib/gitlab/ci/ansi2html.rb index 4dcb3869d4f..fba0de20ced 100644 --- a/lib/gitlab/ci/ansi2html.rb +++ b/lib/gitlab/ci/ansi2html.rb @@ -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 diff --git a/lib/gitlab/ci/build/artifacts/metadata.rb b/lib/gitlab/ci/build/artifacts/metadata.rb index 08dac756cc1..d45a044686e 100644 --- a/lib/gitlab/ci/build/artifacts/metadata.rb +++ b/lib/gitlab/ci/build/artifacts/metadata.rb @@ -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 diff --git a/lib/gitlab/ci/build/artifacts/metadata/entry.rb b/lib/gitlab/ci/build/artifacts/metadata/entry.rb index d0a80518ae8..80e69cdcc95 100644 --- a/lib/gitlab/ci/build/artifacts/metadata/entry.rb +++ b/lib/gitlab/ci/build/artifacts/metadata/entry.rb @@ -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 diff --git a/lib/gitlab/cycle_analytics/plan_event_fetcher.rb b/lib/gitlab/cycle_analytics/plan_event_fetcher.rb index db8ac3becea..aeca9d00156 100644 --- a/lib/gitlab/cycle_analytics/plan_event_fetcher.rb +++ b/lib/gitlab/cycle_analytics/plan_event_fetcher.rb @@ -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'] diff --git a/lib/gitlab/database/count/tablesample_count_strategy.rb b/lib/gitlab/database/count/tablesample_count_strategy.rb index cf1cf054dbf..fedf6ca4fe1 100644 --- a/lib/gitlab/database/count/tablesample_count_strategy.rb +++ b/lib/gitlab/database/count/tablesample_count_strategy.rb @@ -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 diff --git a/lib/gitlab/diff/file.rb b/lib/gitlab/diff/file.rb index c9d89d56884..eac9bb88eb6 100644 --- a/lib/gitlab/diff/file.rb +++ b/lib/gitlab/diff/file.rb @@ -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 diff --git a/lib/gitlab/email/reply_parser.rb b/lib/gitlab/email/reply_parser.rb index 2743f011ca6..dc44e9d7481 100644 --- a/lib/gitlab/email/reply_parser.rb +++ b/lib/gitlab/email/reply_parser.rb @@ -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 diff --git a/lib/gitlab/fogbugz_import/importer.rb b/lib/gitlab/fogbugz_import/importer.rb index 431911d1eee..2c53f9b026d 100644 --- a/lib/gitlab/fogbugz_import/importer.rb +++ b/lib/gitlab/fogbugz_import/importer.rb @@ -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 diff --git a/lib/gitlab/git/commit.rb b/lib/gitlab/git/commit.rb index c5688cda565..491e4b47196 100644 --- a/lib/gitlab/git/commit.rb +++ b/lib/gitlab/git/commit.rb @@ -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) diff --git a/lib/gitlab/git/repository.rb b/lib/gitlab/git/repository.rb index 2f8e4e9e93d..7750978fb95 100644 --- a/lib/gitlab/git/repository.rb +++ b/lib/gitlab/git/repository.rb @@ -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 diff --git a/lib/gitlab/git/tree.rb b/lib/gitlab/git/tree.rb index 51542bcaaa2..6fcea4e12b4 100644 --- a/lib/gitlab/git/tree.rb +++ b/lib/gitlab/git/tree.rb @@ -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 diff --git a/lib/gitlab/gitaly_client.rb b/lib/gitlab/gitaly_client.rb index 869b835b61e..3e7e4f096ee 100644 --- a/lib/gitlab/gitaly_client.rb +++ b/lib/gitlab/gitaly_client.rb @@ -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 diff --git a/lib/gitlab/gitaly_client/blob_service.rb b/lib/gitlab/gitaly_client/blob_service.rb index 39547328210..6b8e58e6199 100644 --- a/lib/gitlab/gitaly_client/blob_service.rb +++ b/lib/gitlab/gitaly_client/blob_service.rb @@ -27,7 +27,7 @@ module Gitlab data << msg.data end - return nil if blob.oid.blank? + return if blob.oid.blank? data = data.join diff --git a/lib/gitlab/gitaly_client/operation_service.rb b/lib/gitlab/gitaly_client/operation_service.rb index bc45ee38fb5..2528208440e 100644 --- a/lib/gitlab/gitaly_client/operation_service.rb +++ b/lib/gitlab/gitaly_client/operation_service.rb @@ -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) diff --git a/lib/gitlab/highlight.rb b/lib/gitlab/highlight.rb index a4e60bbd828..381f1dd4e55 100644 --- a/lib/gitlab/highlight.rb +++ b/lib/gitlab/highlight.rb @@ -39,7 +39,7 @@ module Gitlab private def custom_language - return nil unless @language + return unless @language Rouge::Lexer.find_fancy(@language) end diff --git a/lib/gitlab/i18n/metadata_entry.rb b/lib/gitlab/i18n/metadata_entry.rb index 3764e379681..4facd10bfc8 100644 --- a/lib/gitlab/i18n/metadata_entry.rb +++ b/lib/gitlab/i18n/metadata_entry.rb @@ -15,7 +15,7 @@ module Gitlab end def expected_forms - return nil unless plural_information + return unless plural_information plural_information['nplurals'].to_i end diff --git a/lib/gitlab/import_export/json_hash_builder.rb b/lib/gitlab/import_export/json_hash_builder.rb index 477499e1688..b145f37c052 100644 --- a/lib/gitlab/import_export/json_hash_builder.rb +++ b/lib/gitlab/import_export/json_hash_builder.rb @@ -67,7 +67,7 @@ module Gitlab # +value+ existing model to be included in the hash # +parsed_hash+ the original hash def parse_hash(value) - return nil if already_contains_methods?(value) + return if already_contains_methods?(value) @attributes_finder.parse(value) do |hash| { include: hash_or_merge(value, hash) } diff --git a/lib/gitlab/import_export/relation_factory.rb b/lib/gitlab/import_export/relation_factory.rb index 099b488f68e..61a1aa6da5a 100644 --- a/lib/gitlab/import_export/relation_factory.rb +++ b/lib/gitlab/import_export/relation_factory.rb @@ -75,7 +75,7 @@ module Gitlab # the relation_hash, updating references with new object IDs, mapping users using # the "members_mapper" object, also updating notes if required. def create - return nil if unknown_service? + return if unknown_service? setup_models diff --git a/lib/gitlab/incoming_email.rb b/lib/gitlab/incoming_email.rb index cc0c633b943..8b346f6d7d2 100644 --- a/lib/gitlab/incoming_email.rb +++ b/lib/gitlab/incoming_email.rb @@ -57,7 +57,7 @@ module Gitlab def address_regex wildcard_address = config.address - return nil unless wildcard_address + return unless wildcard_address regex = Regexp.escape(wildcard_address) regex = regex.sub(Regexp.escape(WILDCARD_PLACEHOLDER), '(.+)') diff --git a/lib/gitlab/legacy_github_import/client.rb b/lib/gitlab/legacy_github_import/client.rb index bc952147667..bbdd094e33b 100644 --- a/lib/gitlab/legacy_github_import/client.rb +++ b/lib/gitlab/legacy_github_import/client.rb @@ -68,7 +68,7 @@ module Gitlab end def user(login) - return nil unless login.present? + return unless login.present? return @users[login] if @users.key?(login) @users[login] = api.user(login) diff --git a/lib/gitlab/legacy_github_import/user_formatter.rb b/lib/gitlab/legacy_github_import/user_formatter.rb index ec0e221b1ff..889e6aaa968 100644 --- a/lib/gitlab/legacy_github_import/user_formatter.rb +++ b/lib/gitlab/legacy_github_import/user_formatter.rb @@ -25,7 +25,7 @@ module Gitlab end def find_by_email - return nil unless email + return unless email User.find_by_any_email(email) .try(:id) @@ -33,7 +33,7 @@ module Gitlab # rubocop: disable CodeReuse/ActiveRecord def find_by_external_uid - return nil unless id + return unless id identities = ::Identity.arel_table diff --git a/lib/gitlab/sql/pattern.rb b/lib/gitlab/sql/pattern.rb index 92388262035..07d0acdbae9 100644 --- a/lib/gitlab/sql/pattern.rb +++ b/lib/gitlab/sql/pattern.rb @@ -33,7 +33,7 @@ module Gitlab # `LOWER(column) = query` instead of using `ILIKE`. def fuzzy_arel_match(column, query, lower_exact_match: false) query = query.squish - return nil unless query.present? + return unless query.present? words = select_fuzzy_words(query) diff --git a/lib/gitlab/tracing/jaeger_factory.rb b/lib/gitlab/tracing/jaeger_factory.rb index 2682007302a..93520d5667b 100644 --- a/lib/gitlab/tracing/jaeger_factory.rb +++ b/lib/gitlab/tracing/jaeger_factory.rb @@ -60,7 +60,7 @@ module Gitlab elsif udp_endpoint.present? sender = get_udp_sender(encoder, udp_endpoint) else - return nil + return end Jaeger::Reporters::RemoteReporter.new( diff --git a/lib/gitlab/tree_summary.rb b/lib/gitlab/tree_summary.rb index 453d78e2f7b..8518a13cd1c 100644 --- a/lib/gitlab/tree_summary.rb +++ b/lib/gitlab/tree_summary.rb @@ -95,7 +95,7 @@ module Gitlab end def cache_commit(commit) - return nil unless commit.present? + return unless commit.present? resolved_commits[commit.id] ||= commit end diff --git a/lib/system_check/app/git_user_default_ssh_config_check.rb b/lib/system_check/app/git_user_default_ssh_config_check.rb index 6cd53779bfd..a331f88873b 100644 --- a/lib/system_check/app/git_user_default_ssh_config_check.rb +++ b/lib/system_check/app/git_user_default_ssh_config_check.rb @@ -53,7 +53,7 @@ module SystemCheck end def ssh_dir - return nil unless home_dir + return unless home_dir File.join(home_dir, '.ssh') end diff --git a/spec/support/import_export/export_file_helper.rb b/spec/support/import_export/export_file_helper.rb index ac320934f5a..388b88f0331 100644 --- a/spec/support/import_export/export_file_helper.rb +++ b/spec/support/import_export/export_file_helper.rb @@ -91,7 +91,7 @@ module ExportFileHelper loop do 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) # It's in the safe list, remove hash and keep looking |