From 6b6a14a65a1d0e8b6644f15491cd78aecbf56c48 Mon Sep 17 00:00:00 2001 From: Sebastian Malton Date: Wed, 24 Mar 2021 11:54:45 -0400 Subject: [PATCH] [Fix] `jsx-no-target-blank`: fix handling of `warnOnSpreadAttributes` being false Fixes #2952 --- CHANGELOG.md | 2 ++ lib/rules/jsx-no-target-blank.js | 2 +- tests/lib/rules/jsx-no-target-blank.js | 20 ++++++++++++++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 73276dc81f..f4bb6c35cf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,10 +7,12 @@ This change log adheres to standards from [Keep a CHANGELOG](http://keepachangel ### Fixed * [`jsx-max-depth`]: Prevent getting stuck in circular references ([#2957][] @AriPerkkio) +* [`jsx-no-target-blank`]: fix handling of `warnOnSpreadAttributes` being false ([#2953][] @Nokel81) ### Changed * Fix CHANGELOG.md ([#2950][] @JounQin) +[#2953]: https://github.com/yannickcr/eslint-plugin-react/pull/2953 [#2957]: https://github.com/yannickcr/eslint-plugin-react/pull/2957 [#2950]: https://github.com/yannickcr/eslint-plugin-react/pull/2950 diff --git a/lib/rules/jsx-no-target-blank.js b/lib/rules/jsx-no-target-blank.js index 6ce338bff2..9e3f9d75d4 100644 --- a/lib/rules/jsx-no-target-blank.js +++ b/lib/rules/jsx-no-target-blank.js @@ -148,7 +148,7 @@ module.exports = { if (warnOnSpreadAttributes && hasSpread) { // continue to check below - } else if ((hasSpread && targetIndex < spreadAttributeIndex) || !hasSpread) { + } else if ((hasSpread && targetIndex < spreadAttributeIndex) || !hasSpread || !warnOnSpreadAttributes) { return; } } diff --git a/tests/lib/rules/jsx-no-target-blank.js b/tests/lib/rules/jsx-no-target-blank.js index 703168aef1..ee59331399 100644 --- a/tests/lib/rules/jsx-no-target-blank.js +++ b/tests/lib/rules/jsx-no-target-blank.js @@ -109,6 +109,12 @@ ruleTester.run('jsx-no-target-blank', rule, { }, { code: '' + }, + { + code: '' + }, + { + code: '' } ], invalid: [ @@ -266,6 +272,20 @@ ruleTester.run('jsx-no-target-blank', rule, { options: [{enforceDynamicLinks: 'always'}], settings: {linkComponents: {name: 'Link', linkAttribute: 'to'}}, errors: defaultErrors + }, + { + code: '', + errors: defaultErrors, + options: [{ + warnOnSpreadAttributes: true + }] + }, + { + code: '', + errors: defaultErrors, + options: [{ + warnOnSpreadAttributes: true + }] } ] });