From 797200d936f4e8dcd906f7c91241d6c9d561031c Mon Sep 17 00:00:00 2001 From: John Reed Date: Wed, 16 Jun 2021 15:30:07 -0700 Subject: [PATCH 1/3] Adding test for RailsViewRenderLiteral check on components using with_content --- test/test_rails_view_render_literal.rb | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/test/test_rails_view_render_literal.rb b/test/test_rails_view_render_literal.rb index b5f85866..051b8274 100644 --- a/test/test_rails_view_render_literal.rb +++ b/test/test_rails_view_render_literal.rb @@ -62,6 +62,14 @@ def test_render_component_instance_no_offense assert_equal 0, cop.offenses.count end + def test_render_component_instance_with_content_no_offense + erb_investigate cop, <<-ERB, "app/views/foo/index.html.erb" + <%= render MyClass.new(title: "foo", bar: "baz").with_content("foo") %> + ERB + + assert_equal 0, cop.offenses.count + end + def test_render_component_instance_block_no_offense erb_investigate cop, <<-ERB, "app/views/foo/index.html.erb" <%= render Module::MyClass.new(title: "foo", bar: "baz") do %>Content<% end %> From 74d41d205528c89304e468c87a7800effdd717cd Mon Sep 17 00:00:00 2001 From: Joel Hawksley Date: Fri, 18 Jun 2021 16:28:04 -0600 Subject: [PATCH 2/3] remove unused matcher --- lib/rubocop/cop/github/render_literal_helpers.rb | 4 ---- 1 file changed, 4 deletions(-) diff --git a/lib/rubocop/cop/github/render_literal_helpers.rb b/lib/rubocop/cop/github/render_literal_helpers.rb index b7d90abe..658d0af8 100644 --- a/lib/rubocop/cop/github/render_literal_helpers.rb +++ b/lib/rubocop/cop/github/render_literal_helpers.rb @@ -20,10 +20,6 @@ module RenderLiteralHelpers (send nil? {:render :render_to_string} ({str sym} $_) $...) PATTERN - def_node_matcher :render_inst?, <<-PATTERN - (send nil? {:render :render_to_string} (send _ :new ...) ...) - PATTERN - def_node_matcher :render_with_options?, <<-PATTERN (send nil? {:render :render_to_string} (hash $...) ...) PATTERN From ac8cb0bd65e4ba1b220ac091b4e732ba7cc41a46 Mon Sep 17 00:00:00 2001 From: Joel Hawksley Date: Fri, 18 Jun 2021 16:49:53 -0600 Subject: [PATCH 3/3] add support for `with_content` https://github.com/rubocop/rubocop-ast/blob/master/docs/modules/ROOT/pages/node_pattern.adoc ^ Was JUST enough context for me to figure this out! --- lib/rubocop/cop/github/render_literal_helpers.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/rubocop/cop/github/render_literal_helpers.rb b/lib/rubocop/cop/github/render_literal_helpers.rb index 658d0af8..67417a54 100644 --- a/lib/rubocop/cop/github/render_literal_helpers.rb +++ b/lib/rubocop/cop/github/render_literal_helpers.rb @@ -28,6 +28,10 @@ module RenderLiteralHelpers (send nil? {:render :render_to_string} (send _ :new ...) ...) PATTERN + def_node_matcher :render_view_component_instance_with_content?, <<-PATTERN + (send nil? {:render :render_to_string} (send (send _ :new ...) `:with_content ...)) + PATTERN + def_node_matcher :render_view_component_collection?, <<-PATTERN (send nil? {:render :render_to_string} (send _ :with_collection ...) ...) PATTERN @@ -41,7 +45,8 @@ def hash_with_literal_keys?(hash) end def render_view_component?(node) - render_view_component_instance?(node) || + render_view_component_instance_with_content?(node) || + render_view_component_instance?(node) || render_view_component_collection?(node) end end