Class: RuboCop::Cop::GitHub::RailsViewRenderLiteral

Inherits:
RuboCop::Cop
  • Object
show all
Defined in:
lib/rubocop/cop/github/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
66
67
68
69
# File 'lib/rubocop/cop/github/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)
    if option_pairs.any? { |pair| ignore_key?(pair) }
      return
    end

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