Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[no-unknown-property] data-* attributes should be allowed to have uppercase letters as well #3395

Closed
HJain13 opened this issue Sep 5, 2022 · 3 comments
Assignees

Comments

@HJain13
Copy link
Contributor

HJain13 commented Sep 5, 2022

Technically HTML tags and their attributes are case insensitive [1]. But React types generally prevent usage of the uppercase/mixed case version of the tags and attributes as it conflicts with other established conventions (eg: treating tags with the first letter uppercase as a component in JSX). The typings for React also error out for uppercased attributes.

However, data-attributes are special in this regard; From what I can see data-testId is considered to be valid attribute even by react (though it's automatically lowercase by the browser) (TS enabled react sandbox). Right now the lint rule creates a false positive for this and I am not sure if that should be the case.

@ljharb
Copy link
Member

ljharb commented Sep 5, 2022

for tags, not generally - jsx explicitly prevents it.

For attributes, there's a bunch of patterns - some are case sensitive, some case-insensitive. data-testId is a perfectly valid attribute - because it works, even if the browser normalizes it.

@HJain13
Copy link
Contributor Author

HJain13 commented Sep 5, 2022

Right, but what I meant to say was that: the lint rule throws an error for it.

image

The relevant code due to which it throws an error (the regex doesn't have A-Z)

image

data-testId is a perfectly valid attribute - because it works, even if the browser normalizes it.

Given this, I would think that it's a bug and should be fixed.

@HJain13 HJain13 changed the title [no-unknown-property] Should data attributes be treated as case insensitive [no-unknown-property] data-* attributes should be allowed to have uppercase letters as well Sep 5, 2022
@ljharb
Copy link
Member

ljharb commented Sep 5, 2022

hmm - https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/data-* says

The name must not contain any capital letters.

but i guess React and TS lowercase everything to meet that requirement. I'll update.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants