Commit 1066f853 authored by Rajendra Kadam's avatar Rajendra Kadam Committed by Yorick Peterse

Allow multiple use `X_if_ee` on last lines

parent 7da7c18c
......@@ -367,7 +367,7 @@ module ApplicationSettingsHelper
end
end
ApplicationSettingsHelper.prepend_if_ee('EE::ApplicationSettingsHelper') # rubocop: disable Cop/InjectEnterpriseEditionModule
ApplicationSettingsHelper.prepend_if_ee('EE::ApplicationSettingsHelper')
# The methods in `EE::ApplicationSettingsHelper` should be available as both
# instance and class methods.
......
......@@ -152,7 +152,7 @@ module AuthHelper
extend self
end
AuthHelper.prepend_if_ee('EE::AuthHelper') # rubocop: disable Cop/InjectEnterpriseEditionModule
AuthHelper.prepend_if_ee('EE::AuthHelper')
# The methods added in EE should be available as both class and instance
# methods, just like the methods provided by `AuthHelper` itself.
......
# frozen_string_literal: true
module ProjectsHelper
prepend_if_ee('::EE::ProjectsHelper') # rubocop: disable Cop/InjectEnterpriseEditionModule
def project_incident_management_setting
@project_incident_management_setting ||= @project.incident_management_setting ||
@project.build_incident_management_setting
......
......@@ -101,7 +101,7 @@ module ServicesHelper
extend self
end
ServicesHelper.prepend_if_ee('EE::ServicesHelper') # rubocop: disable Cop/InjectEnterpriseEditionModule
ServicesHelper.prepend_if_ee('EE::ServicesHelper')
# The methods in `EE::ServicesHelper` should be available as both instance and
# class methods.
......
......@@ -42,7 +42,7 @@ module SystemNoteHelper
extend self
end
SystemNoteHelper.prepend_if_ee('EE::SystemNoteHelper') # rubocop: disable Cop/InjectEnterpriseEditionModule
SystemNoteHelper.prepend_if_ee('EE::SystemNoteHelper')
# The methods in `EE::SystemNoteHelper` should be available as both instance and
# class methods.
......
......@@ -150,5 +150,5 @@ end
Noteable.extend(Noteable::ClassMethods)
Noteable::ClassMethods.prepend_if_ee('EE::Noteable::ClassMethods') # rubocop: disable Cop/InjectEnterpriseEditionModule
Noteable::ClassMethods.prepend_if_ee('EE::Noteable::ClassMethods')
Noteable.prepend_if_ee('EE::Noteable')
......@@ -50,8 +50,8 @@ module ProtectedRefAccess
end
end
ProtectedRefAccess.include_if_ee('EE::ProtectedRefAccess::Scopes') # rubocop: disable Cop/InjectEnterpriseEditionModule
ProtectedRefAccess.prepend_if_ee('EE::ProtectedRefAccess') # rubocop: disable Cop/InjectEnterpriseEditionModule
ProtectedRefAccess.include_if_ee('EE::ProtectedRefAccess::Scopes')
ProtectedRefAccess.prepend_if_ee('EE::ProtectedRefAccess')
# When using `prepend` (or `include` for that matter), the `ClassMethods`
# constants are not merged. This means that `class_methods` in
......
---
title: Allow multiple usage of EE extension/inclusion on last lines
merge_request: 31183
author: Rajendra Kadam
type: fixed
......@@ -160,5 +160,5 @@ class Rack::Attack
end
end
::Rack::Attack.extend_if_ee('::EE::Gitlab::Rack::Attack') # rubocop: disable Cop/InjectEnterpriseEditionModule
::Rack::Attack.extend_if_ee('::EE::Gitlab::Rack::Attack')
::Rack::Attack::Request.prepend_if_ee('::EE::Gitlab::Rack::Attack::Request')
......@@ -17,6 +17,8 @@ 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
def ee_const?(node)
......@@ -48,7 +50,13 @@ module RuboCop
# the expression is the last line _of code_.
last_line -= 1 if buffer.source.end_with?("\n")
add_offense(node, message: INVALID_LINE) if line < last_line
last_line_content = buffer.source.split("\n")[-1]
if CHECK_LINE_METHODS_REGEXP.match?(last_line_content)
ignore_node(node)
elsif line < last_line
add_offense(node, message: INVALID_LINE)
end
end
def verify_argument_type(node)
......
......@@ -159,6 +159,17 @@ describe RuboCop::Cop::InjectEnterpriseEditionModule do
SOURCE
end
it 'does not flag the double use of `X_if_ee` on the last line' do
expect_no_offenses(<<~SOURCE)
class Foo
end
Foo.extend_if_ee('EE::Foo')
Foo.include_if_ee('EE::Foo')
Foo.prepend_if_ee('EE::Foo')
SOURCE
end
it 'autocorrects offenses by just disabling the Cop' do
source = <<~SOURCE
class Foo
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment