Skip to content

Commit d76e038

Browse files
authored
Merge pull request #564 from koic/fix_a_false_positive_for_rails_content_tag
[Fix #556] Fix a false positive for `Rails/ContentTag`
2 parents dfd8112 + 162deaa commit d76e038

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* [#556](https://github.com/rubocop/rubocop-rails/issues/556): Fix a false positive for `Rails/ContentTag` when using using the `tag` method with 3 or more arguments. ([@koic][])

lib/rubocop/cop/rails/content_tag.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ def on_new_investigation
3434

3535
def on_send(node)
3636
return unless node.receiver.nil?
37+
return if node.arguments.count >= 3
3738

3839
first_argument = node.first_argument
3940
return if !first_argument ||

spec/rubocop/cop/rails/content_tag_spec.rb

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,14 +75,19 @@
7575
RUBY
7676
end
7777

78-
it 'corrects an offense with all arguments' do
79-
expect_offense(<<~RUBY)
78+
# Prevents `ArgumentError` reported by https://github.com/rubocop/rubocop-rails/issues/556.
79+
# See: https://api.rubyonrails.org/v6.1.4/classes/ActionView/Helpers/TagHelper.html#method-i-tag-label-Legacy+syntax
80+
it 'does not register an offense with all arguments' do
81+
expect_no_offenses(<<~RUBY)
8082
tag(:br, {class: ["strong", "highlight"]}, true, false)
81-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Use `tag.br` instead of `tag(:br)`.
8283
RUBY
84+
end
8385

84-
expect_correction(<<~RUBY)
85-
tag.br({class: ["strong", "highlight"]}, true, false)
86+
# Prevents `ArgumentError` reported by https://github.com/rubocop/rubocop-rails/issues/556.
87+
# See: https://api.rubyonrails.org/v6.1.4/classes/ActionView/Helpers/TagHelper.html#method-i-tag-label-Legacy+syntax
88+
it 'does not register an offense with three arguments' do
89+
expect_no_offenses(<<~RUBY)
90+
tag(:br, {class: ["strong", "highlight"]}, true)
8691
RUBY
8792
end
8893

0 commit comments

Comments
 (0)