Skip to content

Commit 57e8ec6

Browse files
sjarvaljharb
authored andcommitted
[Fix] no-unknown-property: make onLoad and onError be accepted on more elements
1 parent bc33ad7 commit 57e8ec6

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ This change log adheres to standards from [Keep a CHANGELOG](https://keepachange
1212
* [`no-unknown-property`]: move allowfullscreen to case ignored attributes ([#3390][] @sjarva)
1313
* [`no-unknown-property`]: fill works on line, mask, and use elements ([#3390][] @sjarva)
1414
* [`no-unknown-property`]: add onMouseMoveCapture as valid react-specific attribute ([#3390][] @sjarva)
15+
* [`no-unknown-property`]: make onLoad and onError be accepted on more elements ([#3390][] @sjarva)
1516

1617
[#3390]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3390
1718
[#3388]: https://github.com/jsx-eslint/eslint-plugin-react/issues/3388

lib/rules/no-unknown-property.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ const ATTRIBUTE_TAGS_MAP = {
6666
onEmptied: ['audio', 'video'],
6767
onEncrypted: ['audio', 'video'],
6868
onEnded: ['audio', 'video'],
69-
onError: ['audio', 'video', 'img', 'script'],
70-
onLoad: ['script', 'img'],
69+
onError: ['audio', 'video', 'img', 'link', 'source', 'script'],
70+
onLoad: ['script', 'img', 'link'],
7171
onLoadedData: ['audio', 'video'],
7272
onLoadedMetadata: ['audio', 'video'],
7373
onLoadStart: ['audio', 'video'],

tests/lib/rules/no-unknown-property.js

+16-1
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ ruleTester.run('no-unknown-property', rule, {
6060
{ code: '<video playsInline />' },
6161
{ code: '<img onError={foo} onLoad={bar} />' },
6262
{ code: '<script onLoad={bar} onError={foo} />' },
63+
{ code: '<source onError={foo} />' },
64+
{ code: '<link onLoad={bar} onError={foo} />' },
6365
{
6466
code: '<div allowTransparency="true" />',
6567
settings: {
@@ -389,7 +391,20 @@ ruleTester.run('no-unknown-property', rule, {
389391
data: {
390392
name: 'onError',
391393
tagName: 'div',
392-
allowedTags: 'audio, video, img, script',
394+
allowedTags: 'audio, video, img, link, source, script',
395+
},
396+
},
397+
],
398+
},
399+
{
400+
code: '<div onLoad={this.load} />',
401+
errors: [
402+
{
403+
messageId: 'invalidPropOnTag',
404+
data: {
405+
name: 'onLoad',
406+
tagName: 'div',
407+
allowedTags: 'script, img, link',
393408
},
394409
},
395410
],

0 commit comments

Comments
 (0)