Skip to content

Commit

Permalink
fix: allow imageSrcSet and imageSizes attributes on link element
Browse files Browse the repository at this point in the history
  • Loading branch information
terrymun committed Sep 5, 2022
1 parent 7ba7ec4 commit 0c5a8a3
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
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 @@ -228,7 +230,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 @@ -63,6 +63,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 @@ -481,5 +482,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 0c5a8a3

Please sign in to comment.