Class: RuboCop::Cop::Standard::RailsViewRenderLiteral

Inherits:
RuboCop::Cop
  • Object
show all
Defined in:
lib/rubocop/cop/standard/rails/rails_view_render_literal.rb

Constant Summary collapse

MSG =
'render must be used with a string literal or an instance of a Class'

Instance Method Summary collapse

Instance Method Details

#on_send(node) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/rubocop/cop/standard/rails/rails_view_render_literal.rb', line 50

def on_send(node)
  return unless render?(node)

  if render_literal?(node) || render_inst?(node) || render_const?(node)
  elsif (option_pairs = render_with_options?(node))
    return if option_pairs.any? { |pair| ignore_key?(pair) }

    if (partial_node = option_pairs.map { |pair| partial_key?(pair) }.compact.first)
      add_offense(node, location: :expression) unless literal?(partial_node)
    else
      add_offense(node, location: :expression)
    end
  else
    add_offense(node, location: :expression)
  end
end