Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
291232eb
Commit
291232eb
authored
Sep 02, 2020
by
Peter Leitzen
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'dz-improve-route-cop' into 'master'
Improve routing cop See merge request gitlab-org/gitlab!40976
parents
e3881459
cf09b573
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
42 additions
and
9 deletions
+42
-9
config/routes/group.rb
config/routes/group.rb
+5
-9
rubocop/routes_under_scope.rb
rubocop/routes_under_scope.rb
+9
-0
spec/rubocop/cop/put_group_routes_under_scope_spec.rb
spec/rubocop/cop/put_group_routes_under_scope_spec.rb
+14
-0
spec/rubocop/cop/put_project_routes_under_scope_spec.rb
spec/rubocop/cop/put_project_routes_under_scope_spec.rb
+14
-0
No files found.
config/routes/group.rb
View file @
291232eb
...
@@ -23,9 +23,7 @@ constraints(::Constraints::GroupUrlConstrainer.new) do
...
@@ -23,9 +23,7 @@ constraints(::Constraints::GroupUrlConstrainer.new) do
get
'archived'
,
action: :show
,
as: :group_archived
# rubocop:disable Cop/PutGroupRoutesUnderScope
get
'archived'
,
action: :show
,
as: :group_archived
# rubocop:disable Cop/PutGroupRoutesUnderScope
end
end
# These routes are legit and the cop rule will be improved in
get
'/'
,
action: :show
,
as: :group_canonical
# https://gitlab.com/gitlab-org/gitlab/-/issues/230703
get
'/'
,
action: :show
,
as: :group_canonical
# rubocop:disable Cop/PutGroupRoutesUnderScope
end
end
scope
(
path:
'groups/*group_id/-'
,
scope
(
path:
'groups/*group_id/-'
,
...
@@ -112,11 +110,9 @@ constraints(::Constraints::GroupUrlConstrainer.new) do
...
@@ -112,11 +110,9 @@ constraints(::Constraints::GroupUrlConstrainer.new) do
as: :group
,
as: :group
,
constraints:
{
id:
Gitlab
::
PathRegex
.
full_namespace_route_regex
,
format:
/(html|json|atom)/
},
constraints:
{
id:
Gitlab
::
PathRegex
.
full_namespace_route_regex
,
format:
/(html|json|atom)/
},
controller: :groups
)
do
controller: :groups
)
do
# These routes are legit and the cop rule will be improved in
get
'/'
,
action: :show
# https://gitlab.com/gitlab-org/gitlab/-/issues/230703
patch
'/'
,
action: :update
get
'/'
,
action: :show
# rubocop:disable Cop/PutGroupRoutesUnderScope
put
'/'
,
action: :update
patch
'/'
,
action: :update
# rubocop:disable Cop/PutGroupRoutesUnderScope
delete
'/'
,
action: :destroy
put
'/'
,
action: :update
# rubocop:disable Cop/PutGroupRoutesUnderScope
delete
'/'
,
action: :destroy
# rubocop:disable Cop/PutGroupRoutesUnderScope
end
end
end
end
rubocop/routes_under_scope.rb
View file @
291232eb
...
@@ -12,6 +12,7 @@ module RuboCop
...
@@ -12,6 +12,7 @@ module RuboCop
def
on_send
(
node
)
def
on_send
(
node
)
return
unless
route_method?
(
node
)
return
unless
route_method?
(
node
)
return
unless
outside_scope?
(
node
)
return
unless
outside_scope?
(
node
)
return
if
root_route?
(
node
)
add_offense
(
node
)
add_offense
(
node
)
end
end
...
@@ -25,5 +26,13 @@ module RuboCop
...
@@ -25,5 +26,13 @@ module RuboCop
def
route_method?
(
node
)
def
route_method?
(
node
)
ROUTE_METHODS
.
include?
(
node
.
method_name
)
ROUTE_METHODS
.
include?
(
node
.
method_name
)
end
end
def
root_route?
(
node
)
first_argument
=
node
.
arguments
.
first
if
first_argument
.
respond_to?
(
:value
)
first_argument
.
value
==
'/'
end
end
end
end
end
end
spec/rubocop/cop/put_group_routes_under_scope_spec.rb
View file @
291232eb
...
@@ -46,4 +46,18 @@ RSpec.describe RuboCop::Cop::PutGroupRoutesUnderScope, type: :rubocop do
...
@@ -46,4 +46,18 @@ RSpec.describe RuboCop::Cop::PutGroupRoutesUnderScope, type: :rubocop do
end
end
PATTERN
PATTERN
end
end
it
'does not register an offense for the root route'
do
expect_no_offenses
(
<<~
PATTERN
)
get '/'
PATTERN
end
it
'does not register an offense for the root route within scope'
do
expect_no_offenses
(
<<~
PATTERN
)
scope(path: 'groups/*group_id/-', module: :groups) do
get '/'
end
PATTERN
end
end
end
spec/rubocop/cop/put_project_routes_under_scope_spec.rb
View file @
291232eb
...
@@ -46,4 +46,18 @@ RSpec.describe RuboCop::Cop::PutProjectRoutesUnderScope, type: :rubocop do
...
@@ -46,4 +46,18 @@ RSpec.describe RuboCop::Cop::PutProjectRoutesUnderScope, type: :rubocop do
end
end
PATTERN
PATTERN
end
end
it
'does not register an offense for the root route'
do
expect_no_offenses
(
<<~
PATTERN
)
get '/'
PATTERN
end
it
'does not register an offense for the root route within scope'
do
expect_no_offenses
(
<<~
PATTERN
)
scope '-' do
get '/'
end
PATTERN
end
end
end
Write
Preview
Markdown
is supported
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