diff --git a/changelog/fix_errors_that_occur_when_unrelated_tag.md b/changelog/fix_errors_that_occur_when_unrelated_tag.md new file mode 100644 index 0000000000..98615c5320 --- /dev/null +++ b/changelog/fix_errors_that_occur_when_unrelated_tag.md @@ -0,0 +1 @@ +* [#813](https://github.com/rubocop/rubocop-rails/pull/813): Fix errors that occur when unrelated `tag` is investigated by `Rails/ContentTag`. ([@r7kamura][]) diff --git a/lib/rubocop/cop/rails/content_tag.rb b/lib/rubocop/cop/rails/content_tag.rb index 9cc8dc9d45..7376b09d8b 100644 --- a/lib/rubocop/cop/rails/content_tag.rb +++ b/lib/rubocop/cop/rails/content_tag.rb @@ -56,7 +56,8 @@ def allowed_argument?(argument) argument.send_type? || argument.const_type? || argument.splat_type? || - allowed_name?(argument) + allowed_name?(argument) || + !argument.respond_to?(:value) end def register_offense(node, message, preferred_method) diff --git a/spec/rubocop/cop/rails/content_tag_spec.rb b/spec/rubocop/cop/rails/content_tag_spec.rb index 01bf7a2db4..01554c43a8 100644 --- a/spec/rubocop/cop/rails/content_tag_spec.rb +++ b/spec/rubocop/cop/rails/content_tag_spec.rb @@ -174,6 +174,14 @@ end end + context 'when the first argument is keyword arguments' do + it 'does not register an offense' do + expect_no_offenses(<<~RUBY) + tag(factory: :tag) + RUBY + end + end + context 'when `tag` is not a top-level method (e.g. using intercom-ruby)' do it 'does not register an offense' do expect_no_offenses(<<~RUBY)