Skip to content

Commit

Permalink
add link_to_if and link_to_unless to matched calls
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
fwolfst and koic committed Jun 17, 2024
1 parent 7c4ad0c commit e8d60f3
Show file tree
Hide file tree
Showing 3 changed files with 396 additions and 93 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* [#1288](https://github.com/rubocop/rubocop-rails/issues/1288): Let `Rails/LinkToBlank` look into `link_to_if` and `link_to_unless`, too. ([@fwolfst][])
4 changes: 2 additions & 2 deletions lib/rubocop/cop/rails/link_to_blank.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
module RuboCop
module Cop
module Rails
# Checks for calls to `link_to` that contain a
# Checks for calls to `link_to`, `link_to_if`, and `link_to_unless` methods that contain a
# `target: '_blank'` but no `rel: 'noopener'`. This can be a security
# risk as the loaded page will have control over the previous page
# and could change its location for phishing purposes.
Expand All @@ -24,7 +24,7 @@ class LinkToBlank < Base
extend AutoCorrector

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

def_node_matcher :blank_target?, <<~PATTERN
(pair {(sym :target) (str "target")} {(str "_blank") (sym :_blank)})
Expand Down
Loading

0 comments on commit e8d60f3

Please sign in to comment.