summaryrefslogtreecommitdiff
path: root/rubocop
diff options
context:
space:
mode:
authorYorick Peterse <yorickpeterse@gmail.com>2019-01-16 15:21:50 +0100
committerYorick Peterse <yorickpeterse@gmail.com>2019-01-16 16:48:18 +0100
commit9722158c15300dd4507cbb49b4230ab36b36ae65 (patch)
tree234b63916e51894916d59aea2c13c967c65a9b27 /rubocop
parent454942da67911ed6968b799f23c6b9080da7b856 (diff)
downloadgitlab-ce-9722158c15300dd4507cbb49b4230ab36b36ae65.tar.gz
Fix detecting nested EE constants in RuboCop
The InjectEnterpriseEditionModule cop would not detect certain nested EE constants such as `EE::Foo::Bar::Baz`. This could result in it not enforcing `prepend` being placed on the last line. This commit fixes this by just performing a string match on the line, instead of relying on AST matching.
Diffstat (limited to 'rubocop')
-rw-r--r--rubocop/cop/inject_enterprise_edition_module.rb10
1 files changed, 7 insertions, 3 deletions
diff --git a/rubocop/cop/inject_enterprise_edition_module.rb b/rubocop/cop/inject_enterprise_edition_module.rb
index c8b8aca51ab..1d37b1bd12d 100644
--- a/rubocop/cop/inject_enterprise_edition_module.rb
+++ b/rubocop/cop/inject_enterprise_edition_module.rb
@@ -11,9 +11,13 @@ module RuboCop
METHODS = Set.new(%i[include extend prepend]).freeze
- def_node_matcher :ee_const?, <<~PATTERN
- (const (const _ :EE) _)
- PATTERN
+ def ee_const?(node)
+ line = node.location.expression.source_line
+
+ # We use `match?` here instead of RuboCop's AST matching, as this makes
+ # it far easier to handle nested constants such as `EE::Foo::Bar::Baz`.
+ line.match?(/(\s|\()(::)?EE::/)
+ end
def on_send(node)
return unless METHODS.include?(node.children[1])