-
Notifications
You must be signed in to change notification settings - Fork 67
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-1569 Prepare for null safety: fix lints and implicit casts #366
Conversation
…er_generic_function_type_aliases
The fewer explicit types we have, the fewer need to be updated during the transition to null safety Done via replacement of `(@OverRide\n )(?![gs]et )([^(=\n]+ )([^(=\n]+\()` with `$1/$3`
The fewer explicit types we have, the fewer need to be updated during the transition to null safety Done via replacement of `(@OverRide\n )([^(=\n]+ )(get [^(=\n]+=)` with `$1/$3`
Security InsightsNo security relevant content was detected by automated scans. Action Items
Questions or Comments? Reach out on Slack: #support-infosec. |
.github/workflows/dart_ci.yml
Outdated
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.
Reminder to review commits one-by-one!
This should make review much easier. See PR description for more info
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.
Mostly some questions...
Other than that, I can plus one / ten this after that...
/// Create React DOM `Component`s by calling the specified [creator]. | ||
_createDOMComponents(creator) { | ||
a = creator('a'); | ||
abbr = creator('abbr'); | ||
address = creator('address'); |
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.
How long has this been hanging around unused?
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.
Looks like almost 3 years 💀 1ef1196#diff-971a483a502cde928eaed632c11bd797a2a1e6c112fb9152dbe374291d7c8dbaL2804
String get displayName { | ||
var value; | ||
String value; |
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'm assuming there's no reason to worry about this type being tightened?
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.
Nope; originally it was a dynamic
variable that would always be either assigned to a String
or uninitialized, then implicitly casted to a String
when it was returned.
@@ -7,6 +7,7 @@ import 'dart:collection'; | |||
import 'dart:js_util'; | |||
|
|||
import 'package:js/js.dart'; | |||
import 'package:react/react_client/react_interop.dart' show forwardRef2; |
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.
Note for posterity: this was added for a reference in a doc comment.
children = shouldAlwaysBeList ? childrenArgs.map(listifyChildren).toList() : childrenArgs; | ||
markChildrenValidated(children); | ||
markChildrenValidated(children as List); |
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.
Should this still get cast as List
if shouldAlwaysBeList
is 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.
On the line above, the value chlidren is reassigned to is always a List
, and markChildrenValidated takes in a List
, but the static type of children is still dynamic
so we need a cast here.
In null safety, with Dart's type inference improvements, children
actually has a static type of List
, and this becomes an unnecessary cast warning and ends up getting removed.
final files = List<File>.from(rawFiles ?? []); | ||
final types = List<String>.from(rawTypes ?? []); |
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.
Shouldn't this be
final files = List<File>.from(rawFiles ?? []); | |
final types = List<String>.from(rawTypes ?? []); | |
final files = List.from(rawFiles ?? []).cast<File>(); | |
final types = List.from(rawTypes ?? []).cast<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.
I think in this case, either would be acceptable.
List<File>.from(rawFiles ?? [])
creates a new list and casts objects to the target type as they're copied.
List.from(rawFiles ?? []).cast<File>()
creates a new List<dynamic>
and then returns a view on that list that casts items as they're accessed.
Casting them on copy feels better to me in this case, though, so that any bad typing is revealed always, when the event is dispatched, as opposed to only when these properties are accessed.
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
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 on Aaron's commit
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
A while back @aaronlademann-wf started a branch to update react-dart's to use workiva_analysis_options and updated lints, and clean things up.
I then based off that branch, made some adjustments, and enabled implicit casts to improve type safety and make things easier when migrating to null safety. I then used that as a base for a null safety branch.
As a result, all of the null safety changes are dependent on these unmerged lint and implicit cast changes.
To get this repo in a better state, and to enable the merge of null safety changes, let's land these lint and implicit cast changes.
Changes
The original commits also ended up getting pretty messy, with some larger commits and quite a few merge commits in between. The changes also were based on workiva_analysis_options v1 instead of v2.
So, I ended up redoing/rebasing most of these changes, splitting them up into very granular and easy-to-review commits, and rebasing the null safety branch on top of those. Shoutout to @aaronlademann-wf for your original work on this! ❤️
For review, I highly recommend reviewing the changes commit-by-commit since there are so many different lint fixes that touch a lot of code. There's a lot of commits, but most of them are either small or
dart fix --apply
ones that are very easy to review.Summary of changes:
dart fix --apply
final
and remove LHS typing where possibleexample
andtest
directories; changes tolib
were minimal, so the risk of regression here should be pretty low so long as thelib
changes are reviewed thoroughly.ReactComponentFactoryProxy.call
returningdynamic
as opposed toReactElement
. I'd like to change that typing, but since that's technically a major change, let's save that for another PR.Testing