eslint-plugin-react icon indicating copy to clipboard operation
eslint-plugin-react copied to clipboard

[New] Rule jsx-no-uppercase-data-aria-attributes

Open donabrams opened this issue 8 years ago • 5 comments

As per https://facebook.github.io/react/docs/dom-elements.html , data-* and aria-* attributes should be lowercase. This rule enforces that.

Justification to be added to recommended rules: Without this rule, data-myProp and aria-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 how master was passing tests before.

donabrams avatar Sep 18 '17 19:09 donabrams

There's a PR for the no-typos test, so you can actually ignore it. It happened due to a bump in ESLint that caused an unsupported case to be supported.

jseminck avatar Sep 18 '17 20:09 jseminck

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

screen shot 2017-09-18 at 23 19 07

Otherwise looks good to me, ( but I'm not the one to decide if it should be included or not 😄 )

jseminck avatar Sep 18 '17 20:09 jseminck

This is definitely still useful to avoid warnings, but not as critical as I thought previously (silently ignore the attribute).

screen shot 2017-09-18 at 3 44 18 pm

donabrams avatar Sep 18 '17 21:09 donabrams

The aria-* restriction could go in js-a11y, but the data-* rules would be irrelevant there. This is also clearly a react/jsx constraint and not an accessibility helper which is why it's documented in the 2nd paragraph of https://facebook.github.io/react/docs/dom-elements.html rather than just in https://facebook.github.io/react/docs/accessibility.html

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 data-* or aria-* except as pass-throughs to HTML components.

donabrams avatar Sep 19 '17 14:09 donabrams

Unlikely isn't impossible, however.

Using semantic HTML attributes is still part of a11y, including data- attributes.

ljharb avatar Sep 20 '17 01:09 ljharb