Class: RuboCop::Cop::Discourse::Plugins::UsePluginInstanceOn

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

Overview

Using ‘DiscourseEvent.on` leaves the handler enabled when the plugin is disabled.

Examples:

# bad
DiscourseEvent.on(:event) { do_something }

# good
on(:event) { do_something }

Constant Summary collapse

MSG =
"Use `on` instead of `DiscourseEvent.on` as the latter will listen to events even if the plugin is disabled."
NOT_OUTSIDE_PLUGIN_RB =
"Don’t call `DiscourseEvent.on` outside `plugin.rb`."
RESTRICT_ON_SEND =
[:on].freeze

Instance Method Summary collapse

Instance Method Details

#on_send(node) ⇒ Object



27
28
29
30
31
# File 'lib/rubocop/cop/discourse/plugins/use_plugin_instance_on.rb', line 27

def on_send(node)
  return unless discourse_event_on?(node)
  return add_offense(node, message: MSG) if in_plugin_rb_file?
  add_offense(node, message: NOT_OUTSIDE_PLUGIN_RB)
end