Using eslint-plugin-jsx-a11y with styled-components
See original GitHub issueIf you use Styled-Components, eslint-plugin-jsx-a11y cannot detect tags and apply rules, so it’s rendered practically useless.
const Styled_Div = styled.div`...`;
const Nice_Button = styled.button`...`;
render() {
return <Styled_Div... />...<Nice_Button...> ... </Nice_Button>...</Styled_Div>;
}
I have two suggestions:
- add some definitions for equivalences in the configuration file:
equivalences = {
'Styled_Div' : 'div',
'Nice_Button' : 'button'
}
- alternatively, if the name of an tag ends with underscore and a HTML tag (as in my examples) just assume the tag:
Styled_Div
would be processed as adiv
, andNice_Button
as abutton
.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:21
- Comments:8 (3 by maintainers)
Top Results From Across the Web
eslint-plugin-styled-components-a11y
This plugin adds the ability to lint styled components according to the rules outlined in eslint-plugin-jsx-a11y.. Latest version: 1.0.0, ...
Read more >brendanmorrell/eslint-plugin-styled-components-a11y
This plugin adds the ability to lint styled components according to the rules outlined in eslint-plugin-jsx-a11y. ... -Visible, non-interactive elements with ...
Read more >Using `eslint-plugin-jsx-a11y` with `styled-components`
The problem is that because the component created from styled.div ES-Lint can't see it. Is there a plugin or a solution for this...
Read more >eslint-plugin-styled-components-a11y examples
Learn how to use eslint-plugin-styled-components-a11y by viewing and forking example apps that make use of eslint-plugin-styled-components-a11y on CodeSandbox.
Read more >eslint-plugin-styled-components-a11y vulnerabilities
version published direct vulnerabilities
1.0.0 29 Jul, 2022 0. C. 0. H. 0. M. 0. L
0.0.40 16 Jun, 2022 0. C. 0. H. 0....
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Any update on this? Most of my projects use styled-components pretty heavily and it’s a serious bummer missing out on getting a11y hints
I think that “rendered practically useless” is true of just about any static analysis tool for JS, when using a template tag DSL like styled-components.
Regardless, I can see the benefit (even for idiomatic jsx users) of specifying a settings-level map - from
'div'
to['Styled_Div', 'OtherDiv']
etc - that all rules used.This wouldn’t be a trivial amount of work - and would require lots of tests, for every single rule - but I think it’d be useful.