Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rails/ContentTag creates an invalid method call trying to fix the legacy syntax with parameters #556

Closed
yheuhtozr opened this issue Sep 22, 2021 · 0 comments · Fixed by #564
Labels
bug Something isn't working

Comments

@yheuhtozr
Copy link

The following behavior seems not right, as the transformed expression ends up in error.

it 'corrects an offense with all arguments' do
expect_offense(<<~RUBY)
tag(:br, {class: ["strong", "highlight"]}, true, false)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Use `tag.br` instead of `tag(:br)`.
RUBY
expect_correction(<<~RUBY)
tag.br({class: ["strong", "highlight"]}, true, false)
RUBY
end

Expected behavior

Leave a call with legacy arguments such as tag(:br, {class: ["strong", "highlight"]}, true, false) as it as, or convert into something legal and non-deprecated (does it have any outside a raw HTML string?).

Actual behavior

It outputs tag.br({class: ["strong", "highlight"]}, true, false), which results in error.

Confirmed on my env:

$ rails c
Running via Spring preloader in process 29296
Loading development environment (Rails 6.1.4.1)
[1] pry(main)> helper.tag.br({class: ["strong", "highlight"]}, true, false)
ArgumentError: wrong number of arguments (given 4, expected 1..2)
from /home/user/.rbenv/versions/3.0.2/lib/ruby/gems/3.0.0/gems/actionview-6.1.4.1/lib/action_view/helpers/tag_helper.rb:56:in `tag_string'
[2] pry(main)> helper.tag(:br, {class: ["strong", "highlight"]}, true, false)
=> "<br class=\"strong highlight\">"

Steps to reproduce the problem

Run Rubocop.

RuboCop version

$ rubocop -V
1.21.0 (using Parser 3.0.2.0, rubocop-ast 1.11.0, running on ruby 3.0.2 x86_64-linux)
  - rubocop-performance 1.11.5
  - rubocop-rails 2.12.2
  - rubocop-rspec 2.5.0
@yheuhtozr yheuhtozr changed the title Rails/ContentTag creates an invalid method trying to fix the legacy syntax with parameters Rails/ContentTag creates an invalid method call trying to fix the legacy syntax with parameters Sep 22, 2021
@koic koic added the bug Something isn't working label Sep 22, 2021
koic added a commit to koic/rubocop-rails that referenced this issue Sep 27, 2021
Fixes rubocop#556.

This PR fixes a false positive for `Rails/ContentTag`
when using using the `tag` method with 3 or more arguments.
koic added a commit to koic/rubocop-rails that referenced this issue Sep 28, 2021
Fixes rubocop#556.

This PR fixes a false positive for `Rails/ContentTag`
when using using the `tag` method with 3 or more arguments.
@koic koic closed this as completed in #564 Sep 30, 2021
koic added a commit that referenced this issue Sep 30, 2021
…ent_tag

[Fix #556] Fix a false positive for `Rails/ContentTag`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants