Skip to content

Commit

Permalink
[Fix] jsx-no-target-blank: fix handling of warnOnSpreadAttributes
Browse files Browse the repository at this point in the history
… being false

Fixes #2952
  • Loading branch information
Nokel81 authored and ljharb committed Mar 24, 2021
1 parent 7ce9106 commit 6b6a14a
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion lib/rules/jsx-no-target-blank.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
20 changes: 20 additions & 0 deletions tests/lib/rules/jsx-no-target-blank.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,12 @@ ruleTester.run('jsx-no-target-blank', rule, {
},
{
code: '<a target={3} />'
},
{
code: '<a href="some-link" {...otherProps} target="some-non-blank-target"></a>'
},
{
code: '<a href="some-link" target="some-non-blank-target" {...otherProps}></a>'
}
],
invalid: [
Expand Down Expand Up @@ -266,6 +272,20 @@ ruleTester.run('jsx-no-target-blank', rule, {
options: [{enforceDynamicLinks: 'always'}],
settings: {linkComponents: {name: 'Link', linkAttribute: 'to'}},
errors: defaultErrors
},
{
code: '<a href="some-link" {...otherProps} target="some-non-blank-target"></a>',
errors: defaultErrors,
options: [{
warnOnSpreadAttributes: true
}]
},
{
code: '<a href="some-link" target="some-non-blank-target" {...otherProps}></a>',
errors: defaultErrors,
options: [{
warnOnSpreadAttributes: true
}]
}
]
});

0 comments on commit 6b6a14a

Please sign in to comment.