Closed khiga8 closed 1 month ago
we'll also need documentation.
All modified and coverable lines are covered by tests :white_check_mark:
Project coverage is 98.84%. Comparing base (
882bd4d
) to head (dd807b6
).:exclamation: Current head dd807b6 differs from pull request most recent head 2178c5f
Please upload reports for the commit 2178c5f to get more accurate results.
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
This is ready for another review 🙇♀️
Change
This builds on the setting introduced in https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/pull/945.
This change allows the consumer to restrict the polymorphic setting to a specified list of components via a new optional setting,
polymorphicAllowlist
.polymorphicAllowlist
is undefined, the polymorphic prop will be used for any components of the prop name specified bypolymorphicPropName
is present.polymorphicAllowlist
is defined, then there is an additional check to make sure that components are part of thepolymorphicAllowlist
before we use the polymorphic prop specified bypolymorphicPropName
.Motivation
Linting components can raise false positives when a component handles behavior that the linter has no way to know.
For example, an
Avatar
component may render as animg
by default and automatically render analt
based on a username. The linter may raise a false positive ifAvatar
is linted as animg
for the alt text lint rule. This can be avoided by not adding theAvatar
to thejsx-a11y
component map. IfAvatar
(for whatever reason) explicitly hasas="img"
set, since it can also be rendered as ansvg
, it will end up automatically linted via thepolymorphicPropName
setting.In some projects, polymorphic linting may be useful but it may be safer on utility/basic components that don't do much (e.g. a generic
Box
element), rather than opening it up to any component that allows the polymorphic prop to be set.I acknowledge that polymorphism is not an ideal pattern that can add complexity (as warned in the README).