Class: GLRubocop::GLCops::CallbackMethodNames
- Inherits:
-
RuboCop::Cop::Cop
- Object
- RuboCop::Cop::Cop
- GLRubocop::GLCops::CallbackMethodNames
- Defined in:
- lib/gl_rubocop/gl_cops/callback_method_names.rb
Overview
This cop ensures that controller callbacks are named methods, not inline blocks.
Good:
before_action :set_user
Bad:
before_action { do_something }
before_action -> { do_something }
Constant Summary collapse
- CALLBACKS =
%i[before_action after_action around_action].freeze
Instance Method Summary collapse
Instance Method Details
#on_send(node) ⇒ Object
14 15 16 17 18 19 20 |
# File 'lib/gl_rubocop/gl_cops/callback_method_names.rb', line 14 def on_send(node) return unless CALLBACKS.include?(node.method_name) = 'Use a named method for controller callbacks instead of an inline block.' add_offense(node, message: ) if node.parent&.block_type? end |