Skip to content

Commit

Permalink
[Fix] no-unknown-property: make onLoad and onError be accepted on m…
Browse files Browse the repository at this point in the history
…ore elements
  • Loading branch information
sjarva authored and ljharb committed Sep 4, 2022
1 parent bc33ad7 commit 57e8ec6
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -12,6 +12,7 @@ This change log adheres to standards from [Keep a CHANGELOG](https://keepachange
* [`no-unknown-property`]: move allowfullscreen to case ignored attributes ([#3390][] @sjarva)
* [`no-unknown-property`]: fill works on line, mask, and use elements ([#3390][] @sjarva)
* [`no-unknown-property`]: add onMouseMoveCapture as valid react-specific attribute ([#3390][] @sjarva)
* [`no-unknown-property`]: make onLoad and onError be accepted on more elements ([#3390][] @sjarva)

[#3390]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3390
[#3388]: https://github.com/jsx-eslint/eslint-plugin-react/issues/3388
Expand Down
4 changes: 2 additions & 2 deletions lib/rules/no-unknown-property.js
Expand Up @@ -66,8 +66,8 @@ const ATTRIBUTE_TAGS_MAP = {
onEmptied: ['audio', 'video'],
onEncrypted: ['audio', 'video'],
onEnded: ['audio', 'video'],
onError: ['audio', 'video', 'img', 'script'],
onLoad: ['script', 'img'],
onError: ['audio', 'video', 'img', 'link', 'source', 'script'],
onLoad: ['script', 'img', 'link'],
onLoadedData: ['audio', 'video'],
onLoadedMetadata: ['audio', 'video'],
onLoadStart: ['audio', 'video'],
Expand Down
17 changes: 16 additions & 1 deletion tests/lib/rules/no-unknown-property.js
Expand Up @@ -60,6 +60,8 @@ ruleTester.run('no-unknown-property', rule, {
{ code: '<video playsInline />' },
{ code: '<img onError={foo} onLoad={bar} />' },
{ code: '<script onLoad={bar} onError={foo} />' },
{ code: '<source onError={foo} />' },
{ code: '<link onLoad={bar} onError={foo} />' },
{
code: '<div allowTransparency="true" />',
settings: {
Expand Down Expand Up @@ -389,7 +391,20 @@ ruleTester.run('no-unknown-property', rule, {
data: {
name: 'onError',
tagName: 'div',
allowedTags: 'audio, video, img, script',
allowedTags: 'audio, video, img, link, source, script',
},
},
],
},
{
code: '<div onLoad={this.load} />',
errors: [
{
messageId: 'invalidPropOnTag',
data: {
name: 'onLoad',
tagName: 'div',
allowedTags: 'script, img, link',
},
},
],
Expand Down

0 comments on commit 57e8ec6

Please sign in to comment.