jsx-eslint / eslint-plugin-jsx-a11y

Static AST checker for a11y rules on JSX elements.
MIT License
3.39k stars 637 forks source link

Support `for` attribute #977

Closed edoardocavazza closed 1 month ago

edoardocavazza commented 6 months ago

This PR introduces support for for attribute as equivalent for the htmlFor property.

Related issues: #894, #961

ljharb commented 6 months ago

This must not be done by default, since that's not how react (the original, default, and most common usage of jsx) works.

I think a global setting should be used to map htmlFor to for, and rules updated to respect that setting - that way, custom renderers can map whatever attributes they want.

edoardocavazza commented 6 months ago

In most of the rendering engine, both for (as attribute) and htmlFor (as property) are valid. Maybe the global setting should be an array of property names to check?

ljharb commented 6 months ago

React's is the primary one that matters since it has almost the entirety of the usage, but it's good to design the schema so it can support all the renderers.

how about an object, which defaults to { for: ['htmlFor'], 'class': ['className'] } etc, and then you can set it to any combination you want?

edoardocavazza commented 6 months ago

I think it would fit a lot, but I have some issues creating the test cases for the settings :(

ljharb commented 6 months ago

I’d prefer to reuse this PR (but now that you’ve opened a second one, please keep both open)