-
-
Notifications
You must be signed in to change notification settings - Fork 638
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
[New] allow polymorphic linting to be restricted to specified components #984
Conversation
This changes allows the consumer to restrict polymorphic linting to specified components. Linting components may raise false positives when a component handles behavior that the linter has no way to know. This means that linting components is preferred on very basic utility components.
we'll also need documentation. |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #984 +/- ##
==========================================
- Coverage 99.03% 98.84% -0.19%
==========================================
Files 107 105 -2
Lines 1651 1640 -11
Branches 581 580 -1
==========================================
- Hits 1635 1621 -14
- Misses 16 19 +3 ☔ View full report in Codecov by Sentry. |
dd807b6
to
e928282
Compare
This is ready for another review 🙇♀️ |
2178c5f
to
6cd1a70
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i still find polymorphic components horrific, and i hope you're able to fix your codebase by removing them :-) but let's land this
Change
This builds on the setting introduced in #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).