Skip to content

Commit d2f63de

Browse files
committed
Fix errors that occur when unrelated tag is investigated by Rails/ContentTag
1 parent f361219 commit d2f63de

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* [#813](https://github.com/rubocop/rubocop-rails/pull/813): Fix errors that occur when unrelated `tag` is investigated by `Rails/ContentTag`. ([@r7kamura][])

lib/rubocop/cop/rails/content_tag.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ def allowed_argument?(argument)
5656
argument.send_type? ||
5757
argument.const_type? ||
5858
argument.splat_type? ||
59-
allowed_name?(argument)
59+
allowed_name?(argument) ||
60+
!argument.respond_to?(:value)
6061
end
6162

6263
def register_offense(node, message, preferred_method)

spec/rubocop/cop/rails/content_tag_spec.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,14 @@
174174
end
175175
end
176176

177+
context 'when the first argument is keyword arguments' do
178+
it 'does not register an offense' do
179+
expect_no_offenses(<<~RUBY)
180+
tag(factory: :tag)
181+
RUBY
182+
end
183+
end
184+
177185
context 'when `tag` is not a top-level method (e.g. using intercom-ruby)' do
178186
it 'does not register an offense' do
179187
expect_no_offenses(<<~RUBY)

0 commit comments

Comments
 (0)