Skip to content

Commit

Permalink
Fix errors that occur when unrelated tag is investigated by `Rails/…
Browse files Browse the repository at this point in the history
…ContentTag`
  • Loading branch information
r7kamura committed Oct 12, 2022
1 parent f361219 commit d2f63de
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
1 change: 1 addition & 0 deletions changelog/fix_errors_that_occur_when_unrelated_tag.md
Original file line number Diff line number Diff line change
@@ -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][])
3 changes: 2 additions & 1 deletion lib/rubocop/cop/rails/content_tag.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 8 additions & 0 deletions spec/rubocop/cop/rails/content_tag_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit d2f63de

Please sign in to comment.