Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
heptapod
heptapod
Commits
c7b65ec451d8
Commit
c7b65ec4
authored
Apr 18, 2018
by
🙈 jacopo beschi 🙉
Browse files
Resolve "Make a Rubocop that forbids returning from a block"
parent
1754ff297b1a
Changes
59
Hide whitespace changes
Inline
Side-by-side
app/controllers/concerns/notes_actions.rb
View file @
c7b65ec4
...
...
@@ -217,7 +217,7 @@
def
note_project
strong_memoize
(
:note_project
)
do
return
nil
unless
project
next
nil
unless
project
note_project_id
=
params
[
:note_project_id
]
...
...
@@ -228,7 +228,7 @@
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
...
...
app/controllers/groups/variables_controller.rb
View file @
c7b65ec4
...
...
@@ -15,7 +15,7 @@
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
|
...
...
app/controllers/projects/merge_requests_controller.rb
View file @
c7b65ec4
...
...
@@ -60,9 +60,9 @@
end
format
.
patch
do
re
turn
render_404
unless
@merge_request
.
diff_refs
b
re
ak
render_404
unless
@merge_request
.
diff_refs
send_git_patch
@project
.
repository
,
@merge_request
.
diff_refs
end
format
.
diff
do
...
...
@@ -64,9 +64,9 @@
send_git_patch
@project
.
repository
,
@merge_request
.
diff_refs
end
format
.
diff
do
re
turn
render_404
unless
@merge_request
.
diff_refs
b
re
ak
render_404
unless
@merge_request
.
diff_refs
send_git_diff
@project
.
repository
,
@merge_request
.
diff_refs
end
...
...
app/controllers/projects/variables_controller.rb
View file @
c7b65ec4
...
...
@@ -12,7 +12,7 @@
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
|
...
...
app/models/ci/build.rb
View file @
c7b65ec4
...
...
@@ -479,7 +479,7 @@
def
user_variables
Gitlab
::
Ci
::
Variables
::
Collection
.
new
.
tap
do
|
variables
|
re
turn
variables
if
user
.
blank?
b
re
ak
variables
if
user
.
blank?
variables
.
append
(
key:
'GITLAB_USER_ID'
,
value:
user
.
id
.
to_s
)
variables
.
append
(
key:
'GITLAB_USER_EMAIL'
,
value:
user
.
email
)
...
...
@@ -594,7 +594,7 @@
def
persisted_variables
Gitlab
::
Ci
::
Variables
::
Collection
.
new
.
tap
do
|
variables
|
re
turn
variables
unless
persisted?
b
re
ak
variables
unless
persisted?
variables
.
append
(
key:
'CI_JOB_ID'
,
value:
id
.
to_s
)
...
...
@@ -643,7 +643,7 @@
def
persisted_environment_variables
Gitlab
::
Ci
::
Variables
::
Collection
.
new
.
tap
do
|
variables
|
re
turn
variables
unless
persisted?
&&
persisted_environment
.
present?
b
re
ak
variables
unless
persisted?
&&
persisted_environment
.
present?
variables
.
concat
(
persisted_environment
.
predefined_variables
)
...
...
app/models/notification_recipient.rb
View file @
c7b65ec4
...
...
@@ -83,6 +83,6 @@
def
has_access?
DeclarativePolicy
.
subject_scope
do
re
turn
false
unless
user
.
can?
(
:receive_notifications
)
re
turn
true
if
@skip_read_ability
b
re
ak
false
unless
user
.
can?
(
:receive_notifications
)
b
re
ak
true
if
@skip_read_ability
...
...
@@ -88,4 +88,4 @@
re
turn
false
if
@target
&&
!
user
.
can?
(
:read_cross_project
)
re
turn
false
if
@project
&&
!
user
.
can?
(
:read_project
,
@project
)
b
re
ak
false
if
@target
&&
!
user
.
can?
(
:read_cross_project
)
b
re
ak
false
if
@project
&&
!
user
.
can?
(
:read_project
,
@project
)
...
...
@@ -91,6 +91,6 @@
re
turn
true
unless
read_ability
re
turn
true
unless
DeclarativePolicy
.
has_policy?
(
@target
)
b
re
ak
true
unless
read_ability
b
re
ak
true
unless
DeclarativePolicy
.
has_policy?
(
@target
)
user
.
can?
(
read_ability
,
@target
)
end
...
...
app/models/project.rb
View file @
c7b65ec4
...
...
@@ -1637,7 +1637,7 @@
def
container_registry_variables
Gitlab
::
Ci
::
Variables
::
Collection
.
new
.
tap
do
|
variables
|
re
turn
variables
unless
Gitlab
.
config
.
registry
.
enabled
b
re
ak
variables
unless
Gitlab
.
config
.
registry
.
enabled
variables
.
append
(
key:
'CI_REGISTRY'
,
value:
Gitlab
.
config
.
registry
.
host_port
)
...
...
app/services/ci/register_job_service.rb
View file @
c7b65ec4
...
...
@@ -44,7 +44,7 @@
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
...
...
app/services/clusters/gcp/verify_provision_status_service.rb
View file @
c7b65ec4
...
...
@@ -17,7 +17,7 @@
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
...
...
app/services/create_deployment_service.rb
View file @
c7b65ec4
...
...
@@ -19,8 +19,8 @@
environment
.
fire_state_event
(
action
)
re
turn
unless
environment
.
save
re
turn
if
environment
.
stopped?
b
re
ak
unless
environment
.
save
b
re
ak
if
environment
.
stopped?
deploy
.
tap
(
&
:update_merge_request_metrics!
)
end
...
...
app/services/import_export_clean_up_service.rb
View file @
c7b65ec4
...
...
@@ -10,7 +10,7 @@
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
...
...
app/services/projects/destroy_service.rb
View file @
c7b65ec4
...
...
@@ -137,7 +137,7 @@
return
true
unless
Gitlab
.
config
.
registry
.
enabled
ContainerRepository
.
build_root_repository
(
project
).
tap
do
|
repository
|
re
turn
repository
.
has_tags?
?
repository
.
delete_tags!
:
true
b
re
ak
repository
.
has_tags?
?
repository
.
delete_tags!
:
true
end
end
...
...
app/services/repository_archive_clean_up_service.rb
View file @
c7b65ec4
...
...
@@ -10,7 +10,7 @@
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
...
...
app/services/test_hooks/base_service.rb
View file @
c7b65ec4
...
...
@@ -19,7 +19,7 @@
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
)
...
...
app/workers/post_receive.rb
View file @
c7b65ec4
...
...
@@ -33,7 +33,7 @@
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
)
...
...
app/workers/stuck_ci_jobs_worker.rb
View file @
c7b65ec4
...
...
@@ -38,7 +38,7 @@
def
drop_stuck
(
status
,
timeout
)
search
(
status
,
timeout
)
do
|
build
|
re
turn
unless
build
.
stuck?
b
re
ak
unless
build
.
stuck?
drop_build
:stuck
,
build
,
status
,
timeout
end
...
...
changelogs/unreleased/42889-avoid-return-inside-block.yml
0 → 100644
View file @
c7b65ec4
---
title
:
Rubocop rule to avoid returning from a block
merge_request
:
18000
author
:
Jacopo Beschi @jacopo-beschi
type
:
added
lib/api/discussions.rb
View file @
c7b65ec4
...
...
@@ -25,7 +25,7 @@
get
":id/
#{
noteables_str
}
/:noteable_id/discussions"
do
noteable
=
find_noteable
(
parent_type
,
noteables_str
,
params
[
:noteable_id
])
re
turn
not_found!
(
"Discussions"
)
unless
can?
(
current_user
,
noteable_read_ability_name
(
noteable
),
noteable
)
b
re
ak
not_found!
(
"Discussions"
)
unless
can?
(
current_user
,
noteable_read_ability_name
(
noteable
),
noteable
)
notes
=
noteable
.
notes
.
inc_relations_for_view
...
...
@@ -50,7 +50,7 @@
notes
=
readable_discussion_notes
(
noteable
,
params
[
:discussion_id
])
if
notes
.
empty?
||
!
can?
(
current_user
,
noteable_read_ability_name
(
noteable
),
noteable
)
re
turn
not_found!
(
"Discussion"
)
b
re
ak
not_found!
(
"Discussion"
)
end
discussion
=
Discussion
.
build
(
notes
,
noteable
)
...
...
@@ -98,7 +98,7 @@
notes
=
readable_discussion_notes
(
noteable
,
params
[
:discussion_id
])
if
notes
.
empty?
||
!
can?
(
current_user
,
noteable_read_ability_name
(
noteable
),
noteable
)
re
turn
not_found!
(
"Notes"
)
b
re
ak
not_found!
(
"Notes"
)
end
present
notes
,
with:
Entities
::
Note
...
...
@@ -117,8 +117,8 @@
noteable
=
find_noteable
(
parent_type
,
noteables_str
,
params
[
:noteable_id
])
notes
=
readable_discussion_notes
(
noteable
,
params
[
:discussion_id
])
re
turn
not_found!
(
"Discussion"
)
if
notes
.
empty?
re
turn
bad_request!
(
"Discussion is an individual note."
)
unless
notes
.
first
.
part_of_discussion?
b
re
ak
not_found!
(
"Discussion"
)
if
notes
.
empty?
b
re
ak
bad_request!
(
"Discussion is an individual note."
)
unless
notes
.
first
.
part_of_discussion?
opts
=
{
note:
params
[
:body
],
...
...
lib/api/group_variables.rb
View file @
c7b65ec4
...
...
@@ -31,7 +31,7 @@
key
=
params
[
:key
]
variable
=
user_group
.
variables
.
find_by
(
key:
key
)
re
turn
not_found!
(
'GroupVariable'
)
unless
variable
b
re
ak
not_found!
(
'GroupVariable'
)
unless
variable
present
variable
,
with:
Entities
::
Variable
end
...
...
@@ -67,7 +67,7 @@
put
':id/variables/:key'
do
variable
=
user_group
.
variables
.
find_by
(
key:
params
[
:key
])
re
turn
not_found!
(
'GroupVariable'
)
unless
variable
b
re
ak
not_found!
(
'GroupVariable'
)
unless
variable
variable_params
=
declared_params
(
include_missing:
false
).
except
(
:key
)
...
...
lib/api/internal.rb
View file @
c7b65ec4
...
...
@@ -50,7 +50,7 @@
access_checker
.
check
(
params
[
:action
],
params
[
:changes
])
@project
||=
access_checker
.
project
rescue
Gitlab
::
GitAccess
::
UnauthorizedError
,
Gitlab
::
GitAccess
::
NotFoundError
=>
e
re
turn
{
status:
false
,
message:
e
.
message
}
b
re
ak
{
status:
false
,
message:
e
.
message
}
end
log_user_activity
(
actor
)
...
...
@@ -142,7 +142,7 @@
if
key
key
.
update_last_used_at
else
re
turn
{
'success'
=>
false
,
'message'
=>
'Could not find the given key'
}
b
re
ak
{
'success'
=>
false
,
'message'
=>
'Could not find the given key'
}
end
if
key
.
is_a?
(
DeployKey
)
...
...
@@ -146,9 +146,9 @@
end
if
key
.
is_a?
(
DeployKey
)
re
turn
{
success:
false
,
message:
'Deploy keys cannot be used to retrieve recovery codes'
}
b
re
ak
{
success:
false
,
message:
'Deploy keys cannot be used to retrieve recovery codes'
}
end
user
=
key
.
user
unless
user
...
...
@@ -150,9 +150,9 @@
end
user
=
key
.
user
unless
user
re
turn
{
success:
false
,
message:
'Could not find a user for the given key'
}
b
re
ak
{
success:
false
,
message:
'Could not find a user for the given key'
}
end
unless
user
.
two_factor_enabled?
...
...
@@ -156,7 +156,7 @@
end
unless
user
.
two_factor_enabled?
re
turn
{
success:
false
,
message:
'Two-factor authentication is not enabled for this user'
}
b
re
ak
{
success:
false
,
message:
'Two-factor authentication is not enabled for this user'
}
end
codes
=
nil
...
...
Prev
1
2
3
Next
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment