github / eslint-plugin-github

An opinionated collection of ESLint rules used by GitHub.
MIT License
286 stars 51 forks source link

Check for presence of attribute in `getRole` rather than the value #463

Closed khiga8 closed 11 months ago

khiga8 commented 11 months ago

In https://github.com/github/eslint-plugin-github/pull/461, we switched to use getLiteralPropValue in the getRole definition. However, this is resulting in:

<Foo as="a" href={someMethod ? "#" : "github.com"} />

being interpreted as having a generic role despite the as="a" and the presence of an href. This is because the href for getLiteralPropValue returns undefined, so the linter thinks that <Foo /> is an anchor tag without an href.

We do care about the literal value of role so we want to call getLiteralPropValue, but for the other attributes like this href, we only care about the presence of the attribute.

Therefore, I've updated the logic accordingly and added tests which would fail without this change.