Class: RuboCop::Cop::Discourse::Plugins::CallRequiresPlugin

Inherits:
Base
  • Object
show all
Defined in:
lib/rubocop/cop/discourse/plugins/call_requires_plugin.rb

Overview

Plugin controllers must call ‘requires_plugin` to prevent routes from being accessible when the plugin is disabled.

Examples:

# bad
class MyController
  def my_action
  end
end

# good
class MyController
  requires_plugin PLUGIN_NAME
  def my_action
  end
end

Constant Summary collapse

MSG =
"Use `requires_plugin` in controllers to prevent routes from being accessible when plugin is disabled."

Instance Method Summary collapse

Instance Method Details

#on_class(node) ⇒ Object



37
38
39
40
41
# File 'lib/rubocop/cop/discourse/plugins/call_requires_plugin.rb', line 37

def on_class(node)
  return if requires_plugin_present?(node)
  return if requires_plugin_present_in_parent_classes(node)
  add_offense(node, message: MSG)
end