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"

Instance Method Summary collapse

Instance Method Details

#on_send(node) ⇒ Object



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/rubocop/cop/github/rails_controller_render_literal.rb', line 63

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

  if render_literal?(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, :expression)
      end
    else
      add_offense(node, :expression)
    end

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