Skip to content
Snippets Groups Projects
Commit c6b1043e authored by 🙈  jacopo beschi 🙉's avatar 🙈 jacopo beschi 🙉 Committed by Rémy Coutable
Browse files

Resolve "Make a Rubocop that forbids returning from a block"

parent 3529ccae
No related branches found
No related tags found
No related merge requests found
Showing
with 43 additions and 38 deletions
Loading
Loading
@@ -217,7 +217,7 @@ module NotesActions
 
def note_project
strong_memoize(:note_project) do
return nil unless project
next nil unless project
 
note_project_id = params[:note_project_id]
 
Loading
Loading
@@ -228,7 +228,7 @@ module NotesActions
project
end
 
return access_denied! unless can?(current_user, :create_note, the_project)
next access_denied! unless can?(current_user, :create_note, the_project)
 
the_project
end
Loading
Loading
Loading
Loading
@@ -15,7 +15,7 @@ module Groups
def update
if @group.update(group_variables_params)
respond_to do |format|
format.json { return render_group_variables }
format.json { render_group_variables }
end
else
respond_to do |format|
Loading
Loading
Loading
Loading
@@ -60,13 +60,13 @@ class Projects::MergeRequestsController < Projects::MergeRequests::ApplicationCo
end
 
format.patch do
return render_404 unless @merge_request.diff_refs
break render_404 unless @merge_request.diff_refs
 
send_git_patch @project.repository, @merge_request.diff_refs
end
 
format.diff do
return render_404 unless @merge_request.diff_refs
break render_404 unless @merge_request.diff_refs
 
send_git_diff @project.repository, @merge_request.diff_refs
end
Loading
Loading
Loading
Loading
@@ -12,7 +12,7 @@ class Projects::VariablesController < Projects::ApplicationController
def update
if @project.update(variables_params)
respond_to do |format|
format.json { return render_variables }
format.json { render_variables }
end
else
respond_to do |format|
Loading
Loading
Loading
Loading
@@ -479,7 +479,7 @@ module Ci
 
def user_variables
Gitlab::Ci::Variables::Collection.new.tap do |variables|
return variables if user.blank?
break variables if user.blank?
 
variables.append(key: 'GITLAB_USER_ID', value: user.id.to_s)
variables.append(key: 'GITLAB_USER_EMAIL', value: user.email)
Loading
Loading
@@ -594,7 +594,7 @@ module Ci
 
def persisted_variables
Gitlab::Ci::Variables::Collection.new.tap do |variables|
return variables unless persisted?
break variables unless persisted?
 
variables
.append(key: 'CI_JOB_ID', value: id.to_s)
Loading
Loading
@@ -643,7 +643,7 @@ module Ci
 
def persisted_environment_variables
Gitlab::Ci::Variables::Collection.new.tap do |variables|
return variables unless persisted? && persisted_environment.present?
break variables unless persisted? && persisted_environment.present?
 
variables.concat(persisted_environment.predefined_variables)
 
Loading
Loading
Loading
Loading
@@ -83,14 +83,14 @@ class NotificationRecipient
 
def has_access?
DeclarativePolicy.subject_scope do
return false unless user.can?(:receive_notifications)
return true if @skip_read_ability
break false unless user.can?(:receive_notifications)
break true if @skip_read_ability
 
return false if @target && !user.can?(:read_cross_project)
return false if @project && !user.can?(:read_project, @project)
break false if @target && !user.can?(:read_cross_project)
break false if @project && !user.can?(:read_project, @project)
 
return true unless read_ability
return true unless DeclarativePolicy.has_policy?(@target)
break true unless read_ability
break true unless DeclarativePolicy.has_policy?(@target)
 
user.can?(read_ability, @target)
end
Loading
Loading
Loading
Loading
@@ -1637,7 +1637,7 @@ class Project < ActiveRecord::Base
 
def container_registry_variables
Gitlab::Ci::Variables::Collection.new.tap do |variables|
return variables unless Gitlab.config.registry.enabled
break variables unless Gitlab.config.registry.enabled
 
variables.append(key: 'CI_REGISTRY', value: Gitlab.config.registry.host_port)
 
Loading
Loading
Loading
Loading
@@ -44,7 +44,7 @@ module Ci
build.run!
register_success(build)
 
return Result.new(build, true)
return Result.new(build, true) # rubocop:disable Cop/AvoidReturnFromBlocks
rescue Ci::Build::MissingDependenciesError
build.drop!(:missing_dependency_failure)
end
Loading
Loading
Loading
Loading
@@ -17,7 +17,7 @@ module Clusters
when 'DONE'
finalize_creation
else
return provider.make_errored!("Unexpected operation status; #{operation.status} #{operation.status_message}")
provider.make_errored!("Unexpected operation status; #{operation.status} #{operation.status_message}")
end
end
end
Loading
Loading
Loading
Loading
@@ -19,8 +19,8 @@ class CreateDeploymentService
 
environment.fire_state_event(action)
 
return unless environment.save
return if environment.stopped?
break unless environment.save
break if environment.stopped?
 
deploy.tap(&:update_merge_request_metrics!)
end
Loading
Loading
Loading
Loading
@@ -10,7 +10,7 @@ class ImportExportCleanUpService
 
def execute
Gitlab::Metrics.measure(:import_export_clean_up) do
return unless File.directory?(path)
next unless File.directory?(path)
 
clean_up_export_files
end
Loading
Loading
Loading
Loading
@@ -137,7 +137,7 @@ module Projects
return true unless Gitlab.config.registry.enabled
 
ContainerRepository.build_root_repository(project).tap do |repository|
return repository.has_tags? ? repository.delete_tags! : true
break repository.has_tags? ? repository.delete_tags! : true
end
end
 
Loading
Loading
Loading
Loading
@@ -10,7 +10,7 @@ class RepositoryArchiveCleanUpService
 
def execute
Gitlab::Metrics.measure(:repository_archive_clean_up) do
return unless File.directory?(path)
next unless File.directory?(path)
 
clean_up_old_archives
clean_up_empty_directories
Loading
Loading
Loading
Loading
@@ -19,7 +19,7 @@ module TestHooks
error_message = catch(:validation_error) do
sample_data = self.__send__(trigger_data_method) # rubocop:disable GitlabSecurity/PublicSend
 
return hook.execute(sample_data, trigger_key)
return hook.execute(sample_data, trigger_key) # rubocop:disable Cop/AvoidReturnFromBlocks
end
 
error(error_message)
Loading
Loading
Loading
Loading
@@ -33,7 +33,7 @@ class PostReceive
 
unless @user
log("Triggered hook for non-existing user \"#{post_received.identifier}\"")
return false
return false # rubocop:disable Cop/AvoidReturnFromBlocks
end
 
if Gitlab::Git.tag_ref?(ref)
Loading
Loading
Loading
Loading
@@ -38,7 +38,7 @@ class StuckCiJobsWorker
 
def drop_stuck(status, timeout)
search(status, timeout) do |build|
return unless build.stuck?
break unless build.stuck?
 
drop_build :stuck, build, status, timeout
end
Loading
Loading
---
title: Rubocop rule to avoid returning from a block
merge_request: 18000
author: Jacopo Beschi @jacopo-beschi
type: added
Loading
Loading
@@ -25,7 +25,7 @@ module API
get ":id/#{noteables_str}/:noteable_id/discussions" do
noteable = find_noteable(parent_type, noteables_str, params[:noteable_id])
 
return not_found!("Discussions") unless can?(current_user, noteable_read_ability_name(noteable), noteable)
break not_found!("Discussions") unless can?(current_user, noteable_read_ability_name(noteable), noteable)
 
notes = noteable.notes
.inc_relations_for_view
Loading
Loading
@@ -50,7 +50,7 @@ module API
notes = readable_discussion_notes(noteable, params[:discussion_id])
 
if notes.empty? || !can?(current_user, noteable_read_ability_name(noteable), noteable)
return not_found!("Discussion")
break not_found!("Discussion")
end
 
discussion = Discussion.build(notes, noteable)
Loading
Loading
@@ -98,7 +98,7 @@ module API
notes = readable_discussion_notes(noteable, params[:discussion_id])
 
if notes.empty? || !can?(current_user, noteable_read_ability_name(noteable), noteable)
return not_found!("Notes")
break not_found!("Notes")
end
 
present notes, with: Entities::Note
Loading
Loading
@@ -117,8 +117,8 @@ module API
noteable = find_noteable(parent_type, noteables_str, params[:noteable_id])
notes = readable_discussion_notes(noteable, params[:discussion_id])
 
return not_found!("Discussion") if notes.empty?
return bad_request!("Discussion is an individual note.") unless notes.first.part_of_discussion?
break not_found!("Discussion") if notes.empty?
break bad_request!("Discussion is an individual note.") unless notes.first.part_of_discussion?
 
opts = {
note: params[:body],
Loading
Loading
Loading
Loading
@@ -31,7 +31,7 @@ module API
key = params[:key]
variable = user_group.variables.find_by(key: key)
 
return not_found!('GroupVariable') unless variable
break not_found!('GroupVariable') unless variable
 
present variable, with: Entities::Variable
end
Loading
Loading
@@ -67,7 +67,7 @@ module API
put ':id/variables/:key' do
variable = user_group.variables.find_by(key: params[:key])
 
return not_found!('GroupVariable') unless variable
break not_found!('GroupVariable') unless variable
 
variable_params = declared_params(include_missing: false).except(:key)
 
Loading
Loading
Loading
Loading
@@ -50,7 +50,7 @@ module API
access_checker.check(params[:action], params[:changes])
@project ||= access_checker.project
rescue Gitlab::GitAccess::UnauthorizedError, Gitlab::GitAccess::NotFoundError => e
return { status: false, message: e.message }
break { status: false, message: e.message }
end
 
log_user_activity(actor)
Loading
Loading
@@ -142,21 +142,21 @@ module API
if key
key.update_last_used_at
else
return { 'success' => false, 'message' => 'Could not find the given key' }
break { 'success' => false, 'message' => 'Could not find the given key' }
end
 
if key.is_a?(DeployKey)
return { success: false, message: 'Deploy keys cannot be used to retrieve recovery codes' }
break { success: false, message: 'Deploy keys cannot be used to retrieve recovery codes' }
end
 
user = key.user
 
unless user
return { success: false, message: 'Could not find a user for the given key' }
break { success: false, message: 'Could not find a user for the given key' }
end
 
unless user.two_factor_enabled?
return { success: false, message: 'Two-factor authentication is not enabled for this user' }
break { success: false, message: 'Two-factor authentication is not enabled for this user' }
end
 
codes = nil
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