Skip to content

Commit

Permalink
Fix false positive for Rails/LinkToBlank when rel is a symbol value
Browse files Browse the repository at this point in the history
  • Loading branch information
r7kamura authored and bbatsov committed Apr 2, 2019
1 parent a1dd70c commit 7d66f85
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -9,6 +9,7 @@
* [#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][])
* [#6868](https://github.com/rubocop-hq/rubocop/pull/6868): Fix `Rails/LinkToBlank` auto-correct bug when using symbol for target. ([@r7kamura][])
* [#6869](https://github.com/rubocop-hq/rubocop/pull/6869): Fix false positive for `Rails/LinkToBlank` when rel is a symbol value. ([@r7kamura][])

### Changes

Expand Down
8 changes: 4 additions & 4 deletions lib/rubocop/cop/rails/link_to_blank.rb
Expand Up @@ -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 sym} #contains_noopener?))
PATTERN

def_node_matcher :rel_node?, <<-PATTERN
Expand Down Expand Up @@ -80,10 +80,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)
return false unless value

str.split(' ').include?('noopener')
value.to_s.split(' ').include?('noopener')
end
end
end
Expand Down
8 changes: 8 additions & 0 deletions spec/rubocop/cop/rails/link_to_blank_spec.rb
Expand Up @@ -115,6 +115,14 @@
RUBY
end
end

context 'when the rel is symbol noopener' do
it 'register no offence' do
expect_no_offenses(<<-RUBY.strip_indent)
link_to 'Click here', 'https://www.example.com', target: :_blank, rel: :noopener
RUBY
end
end
end
end
end

0 comments on commit 7d66f85

Please sign in to comment.