-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
[New] Rule jsx-no-uppercase-data-aria-attributes #1441
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
base: master
Are you sure you want to change the base?
[New] Rule jsx-no-uppercase-data-aria-attributes #1441
Conversation
There's a PR for the |
Hmm, just wondering, Is this still valid with React 16? https://facebook.github.io/react/blog/2017/09/08/dom-attributes-in-react-16.html It seems the data attribute is no longer ignored, but it does get lowercased: https://codesandbox.io/s/6nx6p1r0rn Otherwise looks good to me, ( but I'm not the one to decide if it should be included or not 😄 ) |
// ------------------------------------------------------------------------------ | ||
|
||
function isDataOrAriaAttributeWithUppercase(attr) { | ||
return (attr.name.name.indexOf('data-') === 0 || |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.startsWith()
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add more test cases that illustrate that this rule only applies to host components (HTML), and not to custom components.
Separately, we should probably add an option to define an array of custom component names that should be treated like they're HTML components (it would default to []
).
However, I don't think this rule belongs in eslint-plugin-react at all - are you familiar with https://github.com/evcohen/eslint-plugin-jsx-a11y/ ?
The Currently this rule does apply to custom AND host components. I could have restricted it to just host/HTML components, but the performance would suffer and complexity of the rule would increase with little reward: I find it very unlikely that custom components would have an attribute key named |
Unlikely isn't impossible, however. Using semantic HTML attributes is still part of a11y, including data- attributes. |
59af733
to
865ed16
Compare
4a2c918
to
6217370
Compare
069314a
to
181c68f
Compare
380e32c
to
51d342b
Compare
As per https://facebook.github.io/react/docs/dom-elements.html ,
data-*
andaria-*
attributes should be lowercase. This rule enforces that.Justification to be added to recommended rules: Without this rule,
data-myProp
andaria-describedBy
will both throw warnings. It's also pretty lightweight.Small strange thing:
no-typos.js
tests were failing on master. I had to guess at the intention, but unsure howmaster
was passing tests before.