Skip to content

Commit 1d373c9

Browse files
sjarvaljharb
authored andcommitted
[Fix] no-unknown-property: data-* attributes can have numbers
1 parent 51ec858 commit 1d373c9

File tree

3 files changed

+5
-2
lines changed

3 files changed

+5
-2
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ This change log adheres to standards from [Keep a CHANGELOG](https://keepachange
77

88
### Fixed
99
* [`no-unknown-property`]: `onError` and `onLoad` both work on `img` and `script` ([#3388][] @ljharb)
10+
* [`no-unknown-property`]: data-* attributes can have numbers ([#3390][] @sjarva)
1011

12+
[#3390]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3390
1113
[#3388]: https://github.com/jsx-eslint/eslint-plugin-react/issues/3388
1214

1315
## [7.31.5] - 2022.09.03

lib/rules/no-unknown-property.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -338,14 +338,14 @@ function isValidHTMLTagInJSX(childNode) {
338338

339339
/**
340340
* Checks if an attribute name is a valid `data-*` attribute:
341-
* if the name starts with "data-" and has some lowcase (a to z) words, separated but hyphens (-)
341+
* if the name starts with "data-" and has some lowcase (a to z) words that can contain numbers, separated but hyphens (-)
342342
* (which is also called "kebab case" or "dash case"), then the attribute is valid data attribute.
343343
*
344344
* @param {String} name - Attribute name to be tested
345345
* @returns {boolean} Result
346346
*/
347347
function isValidDataAttribute(name) {
348-
const dataAttrConvention = /^data(-[a-z]*)*$/;
348+
const dataAttrConvention = /^data(-[a-z1-9]*)*$/;
349349
return !!dataAttrConvention.test(name);
350350
}
351351

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ ruleTester.run('no-unknown-property', rule, {
8181
{ code: '<div data-foo-bar="baz"></div>;' },
8282
{ code: '<div data-parent="parent"></div>;' },
8383
{ code: '<div data-index-number="1234"></div>;' },
84+
{ code: '<div data-e2e-id="5678"></div>;' },
8485
// Ignoring should work
8586
{
8687
code: '<div class="bar"></div>;',

0 commit comments

Comments
 (0)