Sha256: d70c2df9cfdbc7aab5c37918ae002cd90da6191a7bcf735395a116b8d54ce5aa
Contents?: true
Size: 1.57 KB
Versions: 25
Compression:
Stored size: 1.57 KB
Contents
# frozen_string_literal: true require "rubocop" module RuboCop module Cop module GitHub class RailsViewRenderLiteral < Cop MSG = "render must be used with a string literal" def_node_matcher :literal?, <<-PATTERN ({str sym true false nil?} ...) PATTERN def_node_matcher :render?, <<-PATTERN (send nil? :render $...) PATTERN def_node_matcher :render_literal?, <<-PATTERN (send nil? :render ({str sym} $_) $...) PATTERN def_node_matcher :render_with_options?, <<-PATTERN (send nil? :render (hash $...) ...) PATTERN def_node_matcher :ignore_key?, <<-PATTERN (pair (sym { :inline }) $_) PATTERN def_node_matcher :partial_key?, <<-PATTERN (pair (sym { :file :layout :partial }) $_) PATTERN def on_send(node) return unless render?(node) if render_literal?(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 end end end end
Version data entries
25 entries across 25 versions & 2 rubygems