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
62cd8ed2
Commit
62cd8ed2
authored
May 20, 2020
by
nmilojevic1
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow multiple prepends if they're all at the end
parent
b7524f8f
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
13 additions
and
14 deletions
+13
-14
app/services/projects/create_service.rb
app/services/projects/create_service.rb
+0
-2
app/services/projects/import_service.rb
app/services/projects/import_service.rb
+0
-2
rubocop/cop/inject_enterprise_edition_module.rb
rubocop/cop/inject_enterprise_edition_module.rb
+13
-10
No files found.
app/services/projects/create_service.rb
View file @
62cd8ed2
...
...
@@ -249,9 +249,7 @@ module Projects
end
end
# rubocop: disable Cop/InjectEnterpriseEditionModule
Projects
::
CreateService
.
prepend_if_ee
(
'EE::Projects::CreateService'
)
# rubocop: enable Cop/InjectEnterpriseEditionModule
# Measurable should be at the bottom of the ancestor chain, so it will measure execution of EE::Projects::CreateService as well
Projects
::
CreateService
.
prepend
(
Measurable
)
app/services/projects/import_service.rb
View file @
62cd8ed2
...
...
@@ -149,9 +149,7 @@ module Projects
end
end
# rubocop: disable Cop/InjectEnterpriseEditionModule
Projects
::
ImportService
.
prepend_if_ee
(
'EE::Projects::ImportService'
)
# rubocop: enable Cop/InjectEnterpriseEditionModule
# Measurable should be at the bottom of the ancestor chain, so it will measure execution of EE::Projects::ImportService as well
Projects
::
ImportService
.
prepend
(
Measurable
)
rubocop/cop/inject_enterprise_edition_module.rb
View file @
62cd8ed2
...
...
@@ -3,8 +3,7 @@
module
RuboCop
module
Cop
# Cop that blacklists the injecting of EE specific modules anywhere but on
# the last line of a file. Injecting a module in the middle of a file will
# cause merge conflicts, while placing it on the last line will not.
# the last line of a file. It allows multiple EE injections as long as they're all at the end.
class
InjectEnterpriseEditionModule
<
RuboCop
::
Cop
::
Cop
INVALID_LINE
=
'Injecting EE modules must be done on the last line of this file'
\
', outside of any class or module definitions'
...
...
@@ -17,10 +16,10 @@ module RuboCop
CHECK_LINE_METHODS
=
Set
.
new
(
%i[include_if_ee extend_if_ee prepend_if_ee]
).
freeze
CHECK_LINE_METHODS_REGEXP
=
Regexp
.
union
(
CHECK_LINE_METHODS
.
map
(
&
:to_s
)).
freeze
DISALLOW_METHODS
=
Set
.
new
(
%i[include extend prepend]
).
freeze
CHECK_LINE_METHODS_REGEXP
=
Regexp
.
union
((
CHECK_LINE_METHODS
+
DISALLOW_METHODS
).
map
(
&
:to_s
)
+
[
/^\s*(#.*|$)/
]).
freeze
def
ee_const?
(
node
)
line
=
node
.
location
.
expression
.
source_line
...
...
@@ -45,14 +44,18 @@ module RuboCop
buffer
=
node
.
location
.
expression
.
source_buffer
last_line
=
buffer
.
last_line
#
Parser treats the final newline (if present) as a separate line,
# meaning that a simple `line < last_line` would yield true even though
# the expression is the last line _of code_.
last_line
-=
1
if
buffer
.
source
.
end_with?
(
"
\n
"
)
#
We allow multiple includes, extends and prepends as long as they're all ath the end.
allowed_line
=
true
index_line
=
last_line
-
line
+
1
content
=
buffer
.
source
.
split
(
"
\n
"
)
last_line_content
=
buffer
.
source
.
split
(
"
\n
"
)[
-
1
]
while
index_line
>
0
&&
allowed_line
line_content
=
content
[
-
index_line
]
allowed_line
=
CHECK_LINE_METHODS_REGEXP
.
match?
(
line_content
)
index_line
-=
1
end
if
CHECK_LINE_METHODS_REGEXP
.
match?
(
last_line_content
)
if
allowed_line
ignore_node
(
node
)
elsif
line
<
last_line
add_offense
(
node
,
message:
INVALID_LINE
)
...
...
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