Skip to content

Commit e8d60f3

Browse files
fwolfstkoic
andcommitted
add link_to_if and link_to_unless to matched calls
of the LinkToBlank cop. Add changelog entry and add specs within three contexts for the three different methods Co-authored-by: Koichi ITO <koic.ito@gmail.com>
1 parent 7c4ad0c commit e8d60f3

File tree

3 files changed

+396
-93
lines changed

3 files changed

+396
-93
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* [#1288](https://github.com/rubocop/rubocop-rails/issues/1288): Let `Rails/LinkToBlank` look into `link_to_if` and `link_to_unless`, too. ([@fwolfst][])

lib/rubocop/cop/rails/link_to_blank.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
module RuboCop
44
module Cop
55
module Rails
6-
# Checks for calls to `link_to` that contain a
6+
# Checks for calls to `link_to`, `link_to_if`, and `link_to_unless` methods that contain a
77
# `target: '_blank'` but no `rel: 'noopener'`. This can be a security
88
# risk as the loaded page will have control over the previous page
99
# and could change its location for phishing purposes.
@@ -24,7 +24,7 @@ class LinkToBlank < Base
2424
extend AutoCorrector
2525

2626
MSG = 'Specify a `:rel` option containing noopener.'
27-
RESTRICT_ON_SEND = %i[link_to].freeze
27+
RESTRICT_ON_SEND = %i[link_to link_to_if link_to_unless].freeze
2828

2929
def_node_matcher :blank_target?, <<~PATTERN
3030
(pair {(sym :target) (str "target")} {(str "_blank") (sym :_blank)})

0 commit comments

Comments
 (0)