Class: RuboCop::Cop::GitHub::RailsViewRenderShorthand

Inherits:
RuboCop::Cop
  • Object
show all
Defined in:
lib/rubocop/cop/github/rails_view_render_shorthand.rb

Constant Summary collapse

MSG =
"Prefer `render` partial shorthand"

Instance Method Summary collapse

Instance Method Details

#on_send(node) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/rubocop/cop/github/rails_view_render_shorthand.rb', line 23

def on_send(node)
  if option_pairs = render_with_options?(node)
    partial_key = option_pairs.map { |pair| partial_key?(pair) }.compact.first
    locals_key = option_pairs.map { |pair| locals_key?(pair) }.compact.first

    if option_pairs.length == 1 && partial_key
      add_offense(node, :expression, "Use `render #{partial_key.source}` instead")
    elsif option_pairs.length == 2 && partial_key && locals_key
      add_offense(node, :expression, "Use `render #{partial_key.source}, #{locals_key.source}` instead")
    end
  end
end