Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix handling of warnOnSpreadAttributes being false #2953

Merged
merged 1 commit into from Apr 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
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
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
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
}]
}
]
});