[New] allow polymorphic linting to be restricted to specified components#984
Merged
ljharb merged 1 commit intojsx-eslint:mainfrom Sep 4, 2024
Merged
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.
ljharb
requested changes
May 21, 2024
Member
|
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
Contributor
Author
|
This is ready for another review 🙇♀️ |
2178c5f to
6cd1a70
Compare
ljharb
approved these changes
Sep 4, 2024
Member
ljharb
left a comment
There was a problem hiding this comment.
i still find polymorphic components horrific, and i hope you're able to fix your codebase by removing them :-) but let's land this
This was referenced Oct 27, 2024
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.polymorphicAllowlistis undefined, the polymorphic prop will be used for any components of the prop name specified bypolymorphicPropNameis present.polymorphicAllowlistis defined, then there is an additional check to make sure that components are part of thepolymorphicAllowlistbefore 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
Avatarcomponent may render as animgby default and automatically render analtbased on a username. The linter may raise a false positive ifAvataris linted as animgfor the alt text lint rule. This can be avoided by not adding theAvatarto thejsx-a11ycomponent map. IfAvatar(for whatever reason) explicitly hasas="img"set, since it can also be rendered as ansvg, it will end up automatically linted via thepolymorphicPropNamesetting.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
Boxelement), 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).