From 1d373c9d5cf0764ed7831da6b293de1462e0271a Mon Sep 17 00:00:00 2001 From: Senja Jarva Date: Sun, 4 Sep 2022 15:31:04 +0300 Subject: [PATCH 1/7] [Fix] `no-unknown-property`: data-* attributes can have numbers --- CHANGELOG.md | 2 ++ lib/rules/no-unknown-property.js | 4 ++-- tests/lib/rules/no-unknown-property.js | 1 + 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7f627147e4..19bc86900b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,7 +7,9 @@ This change log adheres to standards from [Keep a CHANGELOG](https://keepachange ### Fixed * [`no-unknown-property`]: `onError` and `onLoad` both work on `img` and `script` ([#3388][] @ljharb) +* [`no-unknown-property`]: data-* attributes can have numbers ([#3390][] @sjarva) +[#3390]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3390 [#3388]: https://github.com/jsx-eslint/eslint-plugin-react/issues/3388 ## [7.31.5] - 2022.09.03 diff --git a/lib/rules/no-unknown-property.js b/lib/rules/no-unknown-property.js index 2867c5d5b1..474fd2cb6d 100644 --- a/lib/rules/no-unknown-property.js +++ b/lib/rules/no-unknown-property.js @@ -338,14 +338,14 @@ function isValidHTMLTagInJSX(childNode) { /** * Checks if an attribute name is a valid `data-*` attribute: - * if the name starts with "data-" and has some lowcase (a to z) words, separated but hyphens (-) + * if the name starts with "data-" and has some lowcase (a to z) words that can contain numbers, separated but hyphens (-) * (which is also called "kebab case" or "dash case"), then the attribute is valid data attribute. * * @param {String} name - Attribute name to be tested * @returns {boolean} Result */ function isValidDataAttribute(name) { - const dataAttrConvention = /^data(-[a-z]*)*$/; + const dataAttrConvention = /^data(-[a-z1-9]*)*$/; return !!dataAttrConvention.test(name); } diff --git a/tests/lib/rules/no-unknown-property.js b/tests/lib/rules/no-unknown-property.js index d25c3d7cb4..864b40defd 100644 --- a/tests/lib/rules/no-unknown-property.js +++ b/tests/lib/rules/no-unknown-property.js @@ -81,6 +81,7 @@ ruleTester.run('no-unknown-property', rule, { { code: '
;' }, { code: '
;' }, { code: '
;' }, + { code: '
;' }, // Ignoring should work { code: '
;', From 9a77a1bc4e75871d9fdff7da679bf5b40be49177 Mon Sep 17 00:00:00 2001 From: Senja Jarva Date: Sun, 4 Sep 2022 15:35:21 +0300 Subject: [PATCH 2/7] [Fix] `no-unknown-property`: add more audio/video attributes --- CHANGELOG.md | 1 + lib/rules/no-unknown-property.js | 14 +++++++++ tests/lib/rules/no-unknown-property.js | 40 +++++++++++++++++++++++++- 3 files changed, 54 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 19bc86900b..2aee95eadb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ This change log adheres to standards from [Keep a CHANGELOG](https://keepachange ### Fixed * [`no-unknown-property`]: `onError` and `onLoad` both work on `img` and `script` ([#3388][] @ljharb) * [`no-unknown-property`]: data-* attributes can have numbers ([#3390][] @sjarva) +* [`no-unknown-property`]: add more audio/video attributes ([#3390][] @sjarva) [#3390]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3390 [#3388]: https://github.com/jsx-eslint/eslint-plugin-react/issues/3388 diff --git a/lib/rules/no-unknown-property.js b/lib/rules/no-unknown-property.js index 474fd2cb6d..87efa391ed 100644 --- a/lib/rules/no-unknown-property.js +++ b/lib/rules/no-unknown-property.js @@ -82,6 +82,16 @@ const ATTRIBUTE_TAGS_MAP = { onWaiting: ['audio', 'video'], scrolling: ['iframe'], playsInline: ['video'], + // Video related attributes + autoPictureInPicture: ['video'], + controls: ['audio', 'video'], + controlList: ['video'], + disablePictureInPicture: ['video'], + disableRemotePlayback: ['audio', 'video'], + loop: ['audio', 'video'], + muted: ['audio', 'video'], + poster: ['video'], + preload: ['audio', 'video'], }; const SVGDOM_ATTRIBUTE_NAMES = { @@ -199,6 +209,8 @@ const DOM_PROPERTY_NAMES_ONE_WORD = [ 'property', // React specific attributes 'ref', 'key', 'children', + // Video specific + 'controls', ]; const DOM_PROPERTY_NAMES_TWO_WORDS = [ @@ -258,6 +270,8 @@ const DOM_PROPERTY_NAMES_TWO_WORDS = [ 'onAbort', 'onCanPlay', 'onCanPlayThrough', 'onDurationChange', 'onEmptied', 'onEncrypted', 'onEnded', 'onLoadedData', 'onLoadedMetadata', 'onLoadStart', 'onPause', 'onPlay', 'onPlaying', 'onProgress', 'onRateChange', 'onSeeked', 'onSeeking', 'onStalled', 'onSuspend', 'onTimeUpdate', 'onVolumeChange', 'onWaiting', + // Video specific, + 'autoPictureInPicture', 'controlList', 'disablePictureInPicture', 'disableRemotePlayback', ]; const DOM_PROPERTIES_IGNORE_CASE = ['charset']; diff --git a/tests/lib/rules/no-unknown-property.js b/tests/lib/rules/no-unknown-property.js index 864b40defd..ccdaf0dc88 100644 --- a/tests/lib/rules/no-unknown-property.js +++ b/tests/lib/rules/no-unknown-property.js @@ -102,7 +102,8 @@ ruleTester.run('no-unknown-property', rule, { { code: '
Some details
' }, { code: '' }, { code: 'Audio content' }, - { code: '' }, + { code: '' }, + { code: '' }, ]), invalid: parsers.all([ { @@ -391,5 +392,42 @@ ruleTester.run('no-unknown-property', rule, { }, ], }, + { + code: '
', + errors: [ + { + messageId: 'invalidPropOnTag', + data: { + name: 'controls', + tagName: 'div', + allowedTags: 'audio, video', + }, + }, + { + messageId: 'invalidPropOnTag', + data: { + name: 'loop', + tagName: 'div', + allowedTags: 'audio, video', + }, + }, + { + messageId: 'invalidPropOnTag', + data: { + name: 'muted', + tagName: 'div', + allowedTags: 'audio, video', + }, + }, + { + messageId: 'invalidPropOnTag', + data: { + name: 'playsInline', + tagName: 'div', + allowedTags: 'video', + }, + }, + ], + }, ]), }); From 487ef7055959a160aa546dc0753aa173c48383a3 Mon Sep 17 00:00:00 2001 From: Senja Jarva Date: Sun, 4 Sep 2022 15:36:53 +0300 Subject: [PATCH 3/7] [Fix] `no-unknown-property`: move allowfullscreen to case ignored attributes --- CHANGELOG.md | 1 + lib/rules/no-unknown-property.js | 4 ++-- tests/lib/rules/no-unknown-property.js | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2aee95eadb..2579fe0ba1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ This change log adheres to standards from [Keep a CHANGELOG](https://keepachange * [`no-unknown-property`]: `onError` and `onLoad` both work on `img` and `script` ([#3388][] @ljharb) * [`no-unknown-property`]: data-* attributes can have numbers ([#3390][] @sjarva) * [`no-unknown-property`]: add more audio/video attributes ([#3390][] @sjarva) +* [`no-unknown-property`]: move allowfullscreen to case ignored attributes ([#3390][] @sjarva) [#3390]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3390 [#3388]: https://github.com/jsx-eslint/eslint-plugin-react/issues/3388 diff --git a/lib/rules/no-unknown-property.js b/lib/rules/no-unknown-property.js index 87efa391ed..5ae19a207a 100644 --- a/lib/rules/no-unknown-property.js +++ b/lib/rules/no-unknown-property.js @@ -221,7 +221,7 @@ const DOM_PROPERTY_NAMES_TWO_WORDS = [ // Element specific attributes // See https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes (includes global attributes too) // To be considered if these should be added also to ATTRIBUTE_TAGS_MAP - 'acceptCharset', 'allowFullScreen', 'autoComplete', 'autoPlay', 'cellPadding', 'cellSpacing', 'classID', 'codeBase', + 'acceptCharset', 'autoComplete', 'autoPlay', 'cellPadding', 'cellSpacing', 'classID', 'codeBase', 'colSpan', 'contextMenu', 'dateTime', 'encType', 'formAction', 'formEncType', 'formMethod', 'formNoValidate', 'formTarget', 'frameBorder', 'hrefLang', 'httpEquiv', 'isMap', 'keyParams', 'keyType', 'marginHeight', 'marginWidth', 'maxLength', 'mediaGroup', 'minLength', 'noValidate', 'onAnimationEnd', 'onAnimationIteration', 'onAnimationStart', @@ -274,7 +274,7 @@ const DOM_PROPERTY_NAMES_TWO_WORDS = [ 'autoPictureInPicture', 'controlList', 'disablePictureInPicture', 'disableRemotePlayback', ]; -const DOM_PROPERTIES_IGNORE_CASE = ['charset']; +const DOM_PROPERTIES_IGNORE_CASE = ['charset', 'allowfullscreen']; const ARIA_PROPERTIES = [ // See https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes diff --git a/tests/lib/rules/no-unknown-property.js b/tests/lib/rules/no-unknown-property.js index ccdaf0dc88..e9da7da27a 100644 --- a/tests/lib/rules/no-unknown-property.js +++ b/tests/lib/rules/no-unknown-property.js @@ -393,7 +393,7 @@ ruleTester.run('no-unknown-property', rule, { ], }, { - code: '
', + code: '
', errors: [ { messageId: 'invalidPropOnTag', From 38572e835279955b02ef0ac0e2171502283c2d24 Mon Sep 17 00:00:00 2001 From: Senja Jarva Date: Sun, 4 Sep 2022 15:55:27 +0300 Subject: [PATCH 4/7] [Fix] `no-unknown-property`: fill works on line, mask, and use elements --- CHANGELOG.md | 1 + lib/rules/no-unknown-property.js | 3 +++ tests/lib/rules/no-unknown-property.js | 15 +++++++++++++++ 3 files changed, 19 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2579fe0ba1..6ecd5f7808 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ This change log adheres to standards from [Keep a CHANGELOG](https://keepachange * [`no-unknown-property`]: data-* attributes can have numbers ([#3390][] @sjarva) * [`no-unknown-property`]: add more audio/video attributes ([#3390][] @sjarva) * [`no-unknown-property`]: move allowfullscreen to case ignored attributes ([#3390][] @sjarva) +* [`no-unknown-property`]: fill works on line, mask, and use 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 diff --git a/lib/rules/no-unknown-property.js b/lib/rules/no-unknown-property.js index 5ae19a207a..fe75696aa9 100644 --- a/lib/rules/no-unknown-property.js +++ b/lib/rules/no-unknown-property.js @@ -36,6 +36,8 @@ const ATTRIBUTE_TAGS_MAP = { 'circle', 'ellipse', 'g', + 'line', + 'mask', 'path', 'polygon', 'polyline', @@ -45,6 +47,7 @@ const ATTRIBUTE_TAGS_MAP = { 'textPath', 'tref', 'tspan', + 'use', // Animation final state 'animate', 'animateColor', diff --git a/tests/lib/rules/no-unknown-property.js b/tests/lib/rules/no-unknown-property.js index e9da7da27a..1b2c999cc6 100644 --- a/tests/lib/rules/no-unknown-property.js +++ b/tests/lib/rules/no-unknown-property.js @@ -54,6 +54,7 @@ ruleTester.run('no-unknown-property', rule, { { code: ';' }, { code: '' }, { code: '' }, + { code: '' }, { code: '' }, { code: '' }, { code: '