Sha256: f69ad2f4e323344290b5245666e79d8a712a831aa96aa6bdcd2a97d4a7386bbc

Contents?: true

Size: 1.06 KB

Versions: 3

Compression:

Stored size: 1.06 KB

Contents

# frozen_string_literal: true

module RuboCop
  module Cop
    module Rails
      # This cop looks for inline rendering within controller actions.
      #
      # @example
      #   # bad
      #   class ProductsController < ApplicationController
      #     def index
      #       render inline: "<% products.each do |p| %><p><%= p.name %></p><% end %>", type: :erb
      #     end
      #   end
      #
      #   # good
      #   # app/views/products/index.html.erb
      #   # <% products.each do |p| %>
      #   #   <p><%= p.name %></p>
      #   # <% end %>
      #
      #   class ProductsController < ApplicationController
      #     def index
      #     end
      #   end
      #
      class RenderInline < Cop
        MSG = 'Prefer using a template over inline rendering.'

        def_node_matcher :render_with_inline_option?, <<~PATTERN
          (send nil? :render (hash <(pair {(sym :inline) (str "inline")} _) ...>))
        PATTERN

        def on_send(node)
          add_offense(node) if render_with_inline_option?(node)
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
rubocop-rails-2.8.1 lib/rubocop/cop/rails/render_inline.rb
rubocop-rails-2.8.0 lib/rubocop/cop/rails/render_inline.rb
rubocop-rails-2.7.1 lib/rubocop/cop/rails/render_inline.rb