Skip to content

Commit

Permalink
[Fix] no-unknown-property: allow imageSrcSet and imageSizes att…
Browse files Browse the repository at this point in the history
…ributes on `<link>`

Fixes #3401.
  • Loading branch information
terrymun authored and ljharb committed Sep 5, 2022
1 parent 033fcc5 commit 3306b92
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -13,7 +13,9 @@ This change log adheres to standards from [Keep a CHANGELOG](https://keepachange
* [`no-unknown-property`]: add more capture event properties ([#3402][] @sjarva)
* [`no-unknown-property`]: Add more one word properties found in DefinitelyTyped's react/index.d.ts ([#3402][] @sjarva)
* [`no-unknown-property`]: Mark onLoad/onError as supported on iframes ([#3398][] @maiis, [#3406][] @akx)
* [`no-unknown-property`]: allow `imageSrcSet` and `imageSizes` attributes on `<link>` ([#3407][] @terrymun)

[#3407]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3407
[#3406]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3406
[#3402]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3402
[#3398]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3398
Expand Down
4 changes: 3 additions & 1 deletion lib/rules/no-unknown-property.js
Expand Up @@ -57,6 +57,8 @@ const ATTRIBUTE_TAGS_MAP = {
'animateTransform',
'set',
],
imageSizes: ['link'],
imageSrcSet: ['link'],
property: ['meta'],
viewBox: ['svg'],
as: ['link'],
Expand Down Expand Up @@ -230,7 +232,7 @@ const DOM_PROPERTY_NAMES_TWO_WORDS = [
// To be considered if these should be added also to ATTRIBUTE_TAGS_MAP
'acceptCharset', 'autoComplete', 'autoPlay', 'cellPadding', 'cellSpacing', 'classID', 'codeBase',
'colSpan', 'contextMenu', 'dateTime', 'encType', 'formAction', 'formEncType', 'formMethod', 'formNoValidate', 'formTarget',
'frameBorder', 'hrefLang', 'httpEquiv', 'isMap', 'keyParams', 'keyType', 'marginHeight', 'marginWidth',
'frameBorder', 'hrefLang', 'httpEquiv', 'imageSizes', 'imageSrcSet', 'isMap', 'keyParams', 'keyType', 'marginHeight', 'marginWidth',
'maxLength', 'mediaGroup', 'minLength', 'noValidate', 'onAnimationEnd', 'onAnimationIteration', 'onAnimationStart',
'onBlur', 'onChange', 'onClick', 'onContextMenu', 'onCopy', 'onCompositionEnd', 'onCompositionStart',
'onCompositionUpdate', 'onCut', 'onDoubleClick', 'onDrag', 'onDragEnd', 'onDragEnter', 'onDragExit', 'onDragLeave',
Expand Down
27 changes: 27 additions & 0 deletions tests/lib/rules/no-unknown-property.js
Expand Up @@ -65,6 +65,7 @@ ruleTester.run('no-unknown-property', rule, {
{ code: '<script onLoad={bar} onError={foo} />' },
{ code: '<source onError={foo} />' },
{ code: '<link onLoad={bar} onError={foo} />' },
{ code: '<link rel="preload" as="image" href="someHref" imageSrcSet="someImageSrcSet" imageSizes="someImageSizes" />' },
{ code: '<div allowFullScreen webkitAllowFullScreen mozAllowFullScreen />' },
{
code: '<div allowTransparency="true" />',
Expand Down Expand Up @@ -483,5 +484,31 @@ ruleTester.run('no-unknown-property', rule, {
},
],
},
{
code: '<div imageSrcSet="someImageSrcSet" />',
errors: [
{
messageId: 'invalidPropOnTag',
data: {
name: 'imageSrcSet',
tagName: 'div',
allowedTags: 'link',
},
},
],
},
{
code: '<div imageSizes="someImageSizes" />',
errors: [
{
messageId: 'invalidPropOnTag',
data: {
name: 'imageSizes',
tagName: 'div',
allowedTags: 'link',
},
},
],
},
]),
});

0 comments on commit 3306b92

Please sign in to comment.