Skip to content
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

aria-proptypes rule incorrectly fails when converting Boolean variable to string #1040

Open
kburk1997 opened this issue Dec 13, 2024 · 3 comments

Comments

@kburk1997
Copy link

Hello,

I am using eslint-plugin-jsx-a11y in a custom component library. One of our custom components sets aria-expanded based on a boolean variable:

@State() private _booleanVar: boolean;

renderComponent(): JSX.Element {
    return (
        <button aria-expanded={`${_booleanVar}`}>Test</button>
    );
}

jsx-a11y/aria-proptypes flags this as an error even though I'm converting a boolean to a string - is this a bug? Or is converting a boolean to string for aria-expanded no longer recommended?

@ljharb
Copy link
Member

ljharb commented Dec 13, 2024

The issue is that we can't easily statically tell that that's a stringified boolean, If you do _booleanVar ? 'true' : 'false' then I expect it would work?

@michaelfaith
Copy link
Contributor

If the rule had access to the type information of _booleanVar, I feel like that wouldn't be too hard. I.e. Does the TemplateLiteral only have one express, and that expression is an Identifier who's type annotation is TSBooleanKeyword. With that said, that flow would require the typescript-eslint parser and that the code is in typescript.

@ljharb
Copy link
Member

ljharb commented Dec 20, 2024

Exactly - it's fine if there's improved behavior when type information is provided by the parser, as long as there's still some functionality for non-TS users.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants