question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Using eslint-plugin-jsx-a11y with styled-components

See original GitHub issue

If 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 a div, and Nice_Button as a button.

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:21
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

8reactions
garetmckinleycommented, Feb 2, 2019

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

6reactions
ljharbcommented, Jul 14, 2018

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found