Class: RuboCop::Cop::GitHub::RailsControllerRenderLiteral

Inherits:
RuboCop::Cop
  • Object
show all
Defined in:
lib/rubocop/cop/github/rails_controller_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



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/rubocop/cop/github/rails_controller_render_literal.rb', line 71

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)
    option_pairs = option_pairs.reject { |pair| options_key?(pair) }

    if option_pairs.any? { |pair| ignore_key?(pair) }
      return
    end

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

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