-
Notifications
You must be signed in to change notification settings - Fork 58
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
FED-2034: Analyzer plugin required props validation: check forwarded props #944
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 isReactElement => typeOrBound.element?.isReactElement ?? false; | ||
|
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.
Couldn't get the formatter to not add these empty spaces 🤷
)(); | ||
}, _$HasABCConfig); | ||
''' | ||
.replaceAll('METHOD_NAME', methodName)); |
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.
Went with replaceAll
- so I could use raw strings and not have to escape the $s in the boilerplate lol
- so that the
language=dart
language 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.propsClassBeingForwarded
isn't present everywhere we'd parse one of these configs, and would have to be passed through potentially multiple layers of functions
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is a null key here indicative of things like ubiquitive / un-namespaced props - or something else?
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.
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 |
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.
^
🎯
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.
+1
🤩 test coverage
QA +1
@Workiva/release-management-pp |
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.
+1 from RM
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:
CustomUserChip
forwards 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
UserChip
inside ofCustomUserChip
's render function, since it passes along those forwarded props, and also validates that they're all set.Changes
debug: over_react_required_props
debug 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_props
looks goodMerge Checklist
While we perform many automated checks before auto-merging, some manual checks are needed: