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

Autocorrect for Rails/LinkToBlank is wrong for link_to with parentheses #6737

Closed
kentarohonda opened this issue Feb 6, 2019 · 1 comment · Fixed by #6743
Closed

Autocorrect for Rails/LinkToBlank is wrong for link_to with parentheses #6737

kentarohonda opened this issue Feb 6, 2019 · 1 comment · Fixed by #6743
Labels

Comments

@kentarohonda
Copy link

Auto-correction of Rails/LinkToBlank produces syntactically incorrect code when link_to is used with parentheses.


Expected behavior

, rel: 'noopener' is expected to be inserted before the closing parenthesis.

link_to('name', 'http://example.com', target: '_blank', rel: 'noopener')

Actual behavior

, rel: 'noopener' is inserted after the closing parenthesis.

link_to('name', 'http://example.com', target: '_blank'), rel: 'noopener'

Steps to reproduce the problem

Example file(test.rb)

link_to('name', 'http://example.com', target: '_blank')
$ rubocop -R -a test.rb 
Inspecting 1 file
E

Offenses:

test.rb:1:39: C: [Corrected] Rails/LinkToBlank: Specify a :rel option containing noopener.
link_to('name', 'http://example.com', target: '_blank')
                                      ^^^^^^^^^^^^^^^^
test.rb:1:56: E: Lint/Syntax: unexpected token tCOMMA
(Using Ruby 2.2 parser; configure using TargetRubyVersion parameter, under AllCops)
link_to('name', 'http://example.com', target: '_blank'), rel: 'noopener'
                                                       ^

1 file inspected, 2 offenses detected, 1 offense corrected

RuboCop version

$ rubocop -V
0.63.1 (using Parser 2.6.0.0, running on ruby 2.4.5 x86_64-linux)
@koic
Copy link
Member

koic commented Feb 7, 2019

Thanks for the feedback. I opened a PR #6743.

koic added a commit to koic/rubocop that referenced this issue Feb 7, 2019
Fixes rubocop#6737.

This PR fixes an incorrect auto-correct for `Rails/LinkToBlank` when
`link_to` method arguments are enclosed in parentheses.
@koic koic closed this as completed in #6743 Feb 7, 2019
koic added a commit that referenced this issue Feb 7, 2019
…s_link_to_blank

[Fix #6737] Fix an incorrect auto-correct for `Rails/LinkToBlank`
@Drenmi Drenmi mentioned this issue Feb 10, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants