FED-2034: Analyzer plugin required props validation: check forwarded props#944
Conversation
Security InsightsNo security relevant content was detected by automated scans. Action Items
Questions or Comments? Reach out on Slack: #support-infosec. |
| bool get isLegacyComponentClass => typeOrBound.element?.isLegacyComponentClass ?? false; | ||
|
|
||
| bool get isReactElement => typeOrBound.element?.isReactElement ?? false; | ||
|
|
There was a problem hiding this comment.
Couldn't get the formatter to not add these empty spaces 🤷
| )(); | ||
| }, _$HasABCConfig); | ||
| ''' | ||
| .replaceAll('METHOD_NAME', methodName)); |
There was a problem hiding this comment.
Went with replaceAll
- so I could use raw strings and not have to escape the $s in the boilerplate lol
- so that the
language=dartlanguage injection wouldn't get messed up by string interpolations
|
|
||
| /// A representation of an over_react consumer's configuration of which props classes to | ||
| /// include or exclude when forwarding props. | ||
| abstract class PropForwardingConfig { |
There was a problem hiding this comment.
I kept going back and forth between combining this class into ForwardedProps, but it seemed cleaner to keep it separate:
- from an organizational/conceptual perspective and
- because information we need to populate
ForwardedProps.propsClassBeingForwardedisn't present everywhere we'd parse one of these configs, and would have to be passed through potentially multiple layers of functions
aaronlademann-wf
left a comment
There was a problem hiding this comment.
Didn't quite make it all the way through. Will finish this up in the morning
| debugHelper.log(() { | ||
| var message = StringBuffer()..writeln(forwardedProps); | ||
| if (debugSuppressedRequiredPropsDueToForwarding.isNotEmpty) { | ||
| final propsNamesByClassName = <String?, Set<String>>{}; |
There was a problem hiding this comment.
Is a null key here indicative of things like ubiquitive / un-namespaced props - or something else?
There was a problem hiding this comment.
No, it's just that technically .name is nullable here, since field.enclosingElement is typed as Element and not InterfaceElement (which has a non-nullable .name).
So in practice, this should never be null
| })) | ||
| )(); | ||
| // de bug:over_react_required_props | ||
| // ^ Also, try deleting this space to enable prop forwarding debug infos on lines where props are forwarded |
aaronlademann-wf
left a comment
There was a problem hiding this comment.
+1
🤩 test coverage
|
QA +1
@Workiva/release-management-pp |
Motivation
The lint for missing required props lints when required props aren't set.
However, there are some common cases where required props aren't explicitly set, but instead get forwarded from wrapper components, which have their own required prop validation.
So, we should update the lint to not warn when we know certain props are getting forwarded.
For example... (click to expand)
Take the following component and a custom wrapper around it:
CustomUserChipforwards all its props to the underlyingUserChip, including the required propUserChipProps.user. If we consumed the wrapper component and failed to set that prop, wed'd get a warning like we'd expect:However, we don't need that first warning when rendering
UserChipinside ofCustomUserChip's render function, since it passes along those forwarded props, and also validates that they're all set.Changes
debug: over_react_required_propsdebug comment with prop requiredness info (see playground example)Release Notes
Review
See CONTRIBUTING.md for more details on review types (+1 / QA +1 / +10) and code review process.
Please review:
QA Checklist
// debug: over_react_required_propslooks goodMerge Checklist
While we perform many automated checks before auto-merging, some manual checks are needed: