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
48fe9b20
Commit
48fe9b20
authored
May 22, 2020
by
nmilojevic1
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update specs for cop
- Add missing specs - Update descriptions
parent
62cd8ed2
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
14 deletions
+22
-14
rubocop/cop/inject_enterprise_edition_module.rb
rubocop/cop/inject_enterprise_edition_module.rb
+8
-14
spec/rubocop/cop/inject_enterprise_edition_module_spec.rb
spec/rubocop/cop/inject_enterprise_edition_module_spec.rb
+14
-0
No files found.
rubocop/cop/inject_enterprise_edition_module.rb
View file @
48fe9b20
...
@@ -2,8 +2,8 @@
...
@@ -2,8 +2,8 @@
module
RuboCop
module
RuboCop
module
Cop
module
Cop
# Cop that blacklists the injecting of EE specific modules
anywhere but on
# Cop that blacklists the injecting of EE specific modules
before any lines which are not already injecting another module.
#
the last line of a file. It allows multiple EE
injections as long as they're all at the end.
#
It allows multiple module
injections as long as they're all at the end.
class
InjectEnterpriseEditionModule
<
RuboCop
::
Cop
::
Cop
class
InjectEnterpriseEditionModule
<
RuboCop
::
Cop
::
Cop
INVALID_LINE
=
'Injecting EE modules must be done on the last line of this file'
\
INVALID_LINE
=
'Injecting EE modules must be done on the last line of this file'
\
', outside of any class or module definitions'
', outside of any class or module definitions'
...
@@ -18,7 +18,9 @@ module RuboCop
...
@@ -18,7 +18,9 @@ module RuboCop
DISALLOW_METHODS
=
Set
.
new
(
%i[include extend prepend]
).
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
COMMENT_OR_EMPTY_LINE
=
/^\s*(#.*|$)/
.
freeze
CHECK_LINE_METHODS_REGEXP
=
Regexp
.
union
((
CHECK_LINE_METHODS
+
DISALLOW_METHODS
).
map
(
&
:to_s
)
+
[
COMMENT_OR_EMPTY_LINE
]).
freeze
def
ee_const?
(
node
)
def
ee_const?
(
node
)
line
=
node
.
location
.
expression
.
source_line
line
=
node
.
location
.
expression
.
source_line
...
@@ -43,17 +45,9 @@ module RuboCop
...
@@ -43,17 +45,9 @@ module RuboCop
line
=
node
.
location
.
line
line
=
node
.
location
.
line
buffer
=
node
.
location
.
expression
.
source_buffer
buffer
=
node
.
location
.
expression
.
source_buffer
last_line
=
buffer
.
last_line
last_line
=
buffer
.
last_line
lines
=
buffer
.
source
.
split
(
"
\n
"
)
# We allow multiple includes, extends and prepends as long as they're all ath the end.
# We allow multiple includes, extends and prepends as long as they're all at the end.
allowed_line
=
true
allowed_line
=
(
line
...
last_line
).
all?
{
|
i
|
CHECK_LINE_METHODS_REGEXP
.
match?
(
lines
[
i
-
1
])
}
index_line
=
last_line
-
line
+
1
content
=
buffer
.
source
.
split
(
"
\n
"
)
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
allowed_line
if
allowed_line
ignore_node
(
node
)
ignore_node
(
node
)
...
...
spec/rubocop/cop/inject_enterprise_edition_module_spec.rb
View file @
48fe9b20
...
@@ -170,6 +170,20 @@ describe RuboCop::Cop::InjectEnterpriseEditionModule do
...
@@ -170,6 +170,20 @@ describe RuboCop::Cop::InjectEnterpriseEditionModule do
SOURCE
SOURCE
end
end
it
'does not flag the use of `prepend_if_ee EE` as long as all injections are at the end of the file'
do
expect_no_offenses
(
<<~
SOURCE
)
class Foo
end
Foo.include_if_ee('EE::Foo')
Foo.prepend_if_ee('EE::Foo')
Foo.include(Bar)
# comment on prepending Bar
Foo.prepend(Bar)
SOURCE
end
it
'autocorrects offenses by just disabling the Cop'
do
it
'autocorrects offenses by just disabling the Cop'
do
source
=
<<~
SOURCE
source
=
<<~
SOURCE
class Foo
class Foo
...
...
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