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
Fix false positive for Rails/LinkToBlank
when rel is a symbol value
#6869
Fix false positive for Rails/LinkToBlank
when rel is a symbol value
#6869
Conversation
1a997e7
to
77282a0
Compare
CHANGELOG.md
Outdated
@@ -8,6 +8,7 @@ | |||
* [#6856](https://github.com/rubocop-hq/rubocop/pull/6856): Fix auto-correction for `Style/BlockComments` when the file is missing a trailing blank line. ([@ericsullivan][]) | |||
* [#6858](https://github.com/rubocop-hq/rubocop/issues/6858): Fix an incorrect auto-correct for `Lint/ToJSON` when there are no `to_json` arguments. ([@koic][]) | |||
* [#6865](https://github.com/rubocop-hq/rubocop/pull/6865): Fix deactivated `StyleGuideBaseURL` for `Layout/ClassStructure`. ([@aeroastro][]) | |||
* [#6869](https://github.com/rubocop-hq/rubocop/pull/6869): Fix false positive for `Rails/LinkToBlank`. ([@r7kamura][]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you write a little more about the reason for false positive? It will be user friendly 😃
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right. Slightly modified like this:
- Fix false positive for `Rails/LinkToBlank`.
+ Fix false positive for `Rails/LinkToBlank` when rel is a symbol value.
77282a0
to
a8aebed
Compare
Rails/LinkToBlank
on symbol relRails/LinkToBlank
when rel is a symbol value
a8aebed
to
3138f0a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good! Can you resolve branch conflicts?
@@ -22,7 +22,7 @@ class LinkToBlank < Cop | |||
PATTERN | |||
|
|||
def_node_matcher :includes_noopener?, <<-PATTERN | |||
(pair {(sym :rel) (str "rel")} (str #contains_noopener?)) | |||
(pair {(sym :rel) (str "rel")} {(str #contains_noopener?) (sym #contains_noopener?)}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I could be wrong, but I think you could do:
({str sym} #contains_noopener?)
Don't take my word for it though. I haven't tested the pattern. 🙂
@@ -79,10 +79,10 @@ def add_rel(send_node, offence_node, corrector) | |||
corrector.insert_after(range, new_rel_exp) | |||
end | |||
|
|||
def contains_noopener?(str) | |||
return false unless str | |||
def contains_noopener?(value) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
3138f0a
to
2350e8c
Compare
2350e8c
to
8f6b191
Compare
This code should be valid on
Rails/LinkToBlank
cop, but it's not on rubocop v0.66.0 because rel value is a Symbol.This PR is related to #6868.
Before submitting the PR make sure the following are checked:
[Fix #issue-number]
(if the related issue exists).master
(if not - rebase it).and description in grammatically correct, complete sentences.
bundle exec rake default
. It executes all tests and RuboCop for itself, and generates the documentation.