Skip to content

Commit 3306b92

Browse files
terrymunljharb
authored andcommitted
[Fix] no-unknown-property: allow imageSrcSet and imageSizes attributes on <link>
Fixes #3401.
1 parent 033fcc5 commit 3306b92

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ This change log adheres to standards from [Keep a CHANGELOG](https://keepachange
1313
* [`no-unknown-property`]: add more capture event properties ([#3402][] @sjarva)
1414
* [`no-unknown-property`]: Add more one word properties found in DefinitelyTyped's react/index.d.ts ([#3402][] @sjarva)
1515
* [`no-unknown-property`]: Mark onLoad/onError as supported on iframes ([#3398][] @maiis, [#3406][] @akx)
16+
* [`no-unknown-property`]: allow `imageSrcSet` and `imageSizes` attributes on `<link>` ([#3407][] @terrymun)
1617

18+
[#3407]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3407
1719
[#3406]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3406
1820
[#3402]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3402
1921
[#3398]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3398

lib/rules/no-unknown-property.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ const ATTRIBUTE_TAGS_MAP = {
5757
'animateTransform',
5858
'set',
5959
],
60+
imageSizes: ['link'],
61+
imageSrcSet: ['link'],
6062
property: ['meta'],
6163
viewBox: ['svg'],
6264
as: ['link'],
@@ -230,7 +232,7 @@ const DOM_PROPERTY_NAMES_TWO_WORDS = [
230232
// To be considered if these should be added also to ATTRIBUTE_TAGS_MAP
231233
'acceptCharset', 'autoComplete', 'autoPlay', 'cellPadding', 'cellSpacing', 'classID', 'codeBase',
232234
'colSpan', 'contextMenu', 'dateTime', 'encType', 'formAction', 'formEncType', 'formMethod', 'formNoValidate', 'formTarget',
233-
'frameBorder', 'hrefLang', 'httpEquiv', 'isMap', 'keyParams', 'keyType', 'marginHeight', 'marginWidth',
235+
'frameBorder', 'hrefLang', 'httpEquiv', 'imageSizes', 'imageSrcSet', 'isMap', 'keyParams', 'keyType', 'marginHeight', 'marginWidth',
234236
'maxLength', 'mediaGroup', 'minLength', 'noValidate', 'onAnimationEnd', 'onAnimationIteration', 'onAnimationStart',
235237
'onBlur', 'onChange', 'onClick', 'onContextMenu', 'onCopy', 'onCompositionEnd', 'onCompositionStart',
236238
'onCompositionUpdate', 'onCut', 'onDoubleClick', 'onDrag', 'onDragEnd', 'onDragEnter', 'onDragExit', 'onDragLeave',

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

+27
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ ruleTester.run('no-unknown-property', rule, {
6565
{ code: '<script onLoad={bar} onError={foo} />' },
6666
{ code: '<source onError={foo} />' },
6767
{ code: '<link onLoad={bar} onError={foo} />' },
68+
{ code: '<link rel="preload" as="image" href="someHref" imageSrcSet="someImageSrcSet" imageSizes="someImageSizes" />' },
6869
{ code: '<div allowFullScreen webkitAllowFullScreen mozAllowFullScreen />' },
6970
{
7071
code: '<div allowTransparency="true" />',
@@ -483,5 +484,31 @@ ruleTester.run('no-unknown-property', rule, {
483484
},
484485
],
485486
},
487+
{
488+
code: '<div imageSrcSet="someImageSrcSet" />',
489+
errors: [
490+
{
491+
messageId: 'invalidPropOnTag',
492+
data: {
493+
name: 'imageSrcSet',
494+
tagName: 'div',
495+
allowedTags: 'link',
496+
},
497+
},
498+
],
499+
},
500+
{
501+
code: '<div imageSizes="someImageSizes" />',
502+
errors: [
503+
{
504+
messageId: 'invalidPropOnTag',
505+
data: {
506+
name: 'imageSizes',
507+
tagName: 'div',
508+
allowedTags: 'link',
509+
},
510+
},
511+
],
512+
},
486513
]),
487514
});

0 commit comments

Comments
 (0)