Skip to content

Commit 6b6a14a

Browse files
Nokel81ljharb
authored andcommitted
[Fix] jsx-no-target-blank: fix handling of warnOnSpreadAttributes being false
Fixes #2952
1 parent 7ce9106 commit 6b6a14a

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@ This change log adheres to standards from [Keep a CHANGELOG](http://keepachangel
77

88
### Fixed
99
* [`jsx-max-depth`]: Prevent getting stuck in circular references ([#2957][] @AriPerkkio)
10+
* [`jsx-no-target-blank`]: fix handling of `warnOnSpreadAttributes` being false ([#2953][] @Nokel81)
1011

1112
### Changed
1213
* Fix CHANGELOG.md ([#2950][] @JounQin)
1314

15+
[#2953]: https://github.com/yannickcr/eslint-plugin-react/pull/2953
1416
[#2957]: https://github.com/yannickcr/eslint-plugin-react/pull/2957
1517
[#2950]: https://github.com/yannickcr/eslint-plugin-react/pull/2950
1618

lib/rules/jsx-no-target-blank.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ module.exports = {
148148

149149
if (warnOnSpreadAttributes && hasSpread) {
150150
// continue to check below
151-
} else if ((hasSpread && targetIndex < spreadAttributeIndex) || !hasSpread) {
151+
} else if ((hasSpread && targetIndex < spreadAttributeIndex) || !hasSpread || !warnOnSpreadAttributes) {
152152
return;
153153
}
154154
}

tests/lib/rules/jsx-no-target-blank.js

+20
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,12 @@ ruleTester.run('jsx-no-target-blank', rule, {
109109
},
110110
{
111111
code: '<a target={3} />'
112+
},
113+
{
114+
code: '<a href="some-link" {...otherProps} target="some-non-blank-target"></a>'
115+
},
116+
{
117+
code: '<a href="some-link" target="some-non-blank-target" {...otherProps}></a>'
112118
}
113119
],
114120
invalid: [
@@ -266,6 +272,20 @@ ruleTester.run('jsx-no-target-blank', rule, {
266272
options: [{enforceDynamicLinks: 'always'}],
267273
settings: {linkComponents: {name: 'Link', linkAttribute: 'to'}},
268274
errors: defaultErrors
275+
},
276+
{
277+
code: '<a href="some-link" {...otherProps} target="some-non-blank-target"></a>',
278+
errors: defaultErrors,
279+
options: [{
280+
warnOnSpreadAttributes: true
281+
}]
282+
},
283+
{
284+
code: '<a href="some-link" target="some-non-blank-target" {...otherProps}></a>',
285+
errors: defaultErrors,
286+
options: [{
287+
warnOnSpreadAttributes: true
288+
}]
269289
}
270290
]
271291
});

0 commit comments

Comments
 (0)