-
Notifications
You must be signed in to change notification settings - Fork 7
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
AF-3838 Replace python implementation with dart using dart_codemod #12
Conversation
Merge Requirements Met ✅Request Rosie to automerge this pull request by including @Workiva/release-management-p in a comment. General InformationTicket(s): Code Review(s): #12 Reviewers: corwinsheahan-wf, smaifullerton-wk, sebastianmalysa-wf Additional InformationWatchlist Notifications: None
Note: This is a shortened report. Click here to view Rosie's full evaluation. |
Security InsightsNo security relevant content was detected by automated scans. Action Items
Questions or Comments? Reach out on Slack: #support-infosec. |
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.
Almost done, I'll finish up tomorrow. This looks awesome!
return; | ||
} | ||
|
||
final targetMetaInitializer = '\$metaFor${node.name.name}'; |
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 we pass node.name.name
to stripPrivateGeneratedPrefix
first?
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.
Since this is for the Dart1 -> Dart1/Dart2 migration, and since this is only visiting props and state mixins, there shouldn't ever be a _$
prefix.. but it wouldn't hurt and it would be a good reminder when writing the dart2-only migration
); | ||
} else { | ||
// Meta field already exists. | ||
if (existingMetaField.initializer.toSource() != targetMetaInitializer) { |
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 we instead error here? Thinking of the case where the user has defined the meta
field already as something else. Then the user gets a heads up that something is not right.
implements Suggestor { | ||
@override | ||
visitWithClause(WithClause node) { | ||
final allMixins = node.mixinTypes.map((n) => n.name.name); |
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.
In reference to the TODO above, can we look for the metadata
off of any mixin node and determine whether it contains an over_react mixin annotation?
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.
Talked about this offline, but this isn't possible with an AstVisitor. We'd need to use an ElementVisitor, which is something I'd like to pursue but is more complicated because we have to setup an AnalysisDriver in order to resolve all of the elements.
|
||
static getFactoryInitializerValue(String factoryName) { | ||
if (factoryName.startsWith(privatePrefix)) { | ||
final factoryNameWithoutUnderscore = |
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.
#nit factoryNameWithoutPrivatePrefix
return; | ||
} | ||
|
||
if (factoryNode.initializer != null) { |
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.
This is another situation that I'm not sure we shouldn't error on.
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.
We talked about this offline, and decided that we will error if there is an unexpected value in this initializer (same thing for if the meta field is already defined or initialized with something unexpected. If it's an incorrect value, but one that we would expect from a previous iteration of the codemod, then it will just update it.
// Part library that uses over_react. | ||
final partLib = './lib/part.dart'; | ||
final parentLib = './lib/parent.dart'; | ||
final partSourceFile = SourceFile.fromString('''part of 'parent.dart'; |
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.
We should also run the collector on the parent source file in this test to ensure that there is not a duplicity in the libraries detected.
>>> @Props() private (patches 1) | ||
@Props() class _Foo {} | ||
<<< | ||
@Props() class _$_Foo {} |
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.
Private classes should be this statement is now incorrect. Private classes should be _$Foo
, not _$_Foo
._$_Foo
class _Foo extends _$_Foo | ||
with | ||
// ignore: mixin_of_non_class, undefined_class | ||
_$_FooAccessorsMixin { |
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.
This should also be it should be _$FooAccessorsMixin
_$_FooAccessorsMixin
// ignore: mixin_of_non_class, undefined_class | ||
_$_FooAccessorsMixin { | ||
// ignore: const_initialized_with_non_constant_value, undefined_class, undefined_identifier | ||
static const PropsMeta meta = $metaFor_Foo; |
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.
This should be . Should be $metaForFoo
_$metaFor_Foo
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.
@evanweible-wf this comment reflects a needed change^
|
||
>>> @State() retains doc comments (patches 1) | ||
/// A doc comment. | ||
/// And a second line! |
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.
Can we get 1 more test which retains both the doc comment and the metadata?
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.
ok I'm done now :)
}); | ||
} | ||
|
||
test('returns a false negative when annotation found in a 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.
why not just:
test('returns a false negative when annotation found in a string', () { | |
test('returns true when annotation found in a 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 was trying to make it clear that this is a known limitation in the implementation 🤷♂️
- Added a readme - Updated expected initializer values for static meta fields and UI factories - Added support for ignoring patch suggestions via single-line comments - Added support for a --comment-prefix CLI option
@corwinsheahan-wf addressed most of your comments. I'm going to leave out some of the error-throwing that we talked about for now because I think it will be mainly a corner case. We can add it as a follow up if need be. |
README.md
Outdated
- `pub global run over_react_codemod:dart1_and_dart2_to_dart2` | ||
|
||
Use this codemod to migrate over_react code that has previously been | ||
migrated via the `dart1_to_dart1_and_dart1` codemod to the form that is only |
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.
#nit should this be ...'dart1_to_dart1_and_dart2'?
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.
Yup, good catch
lib/src/d1_to_d1_and_d2/util.dart
Outdated
class $strippedClassName$typeParamsOnClass extends ${privateGeneratedPrefix}$strippedClassName$typeParamsOnSuper | ||
with | ||
$mixinIgnoreComment | ||
${privateGeneratedPrefix}${strippedClassName}AccessorsMixin { |
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.
${privateGeneratedPrefix}${strippedClassName}AccessorsMixin { | |
${privateGeneratedPrefix}${strippedClassName}AccessorsMixin$typeParamsOnSuper { |
@Workiva/release-management-p |
@corwinsheahan-wf I will not merge this because:
|
QA +1
@Workiva/release-management-p |
+1 from RM |
Description
The python version of this tool fell short and was unable to handle all the necessary edge cases. Now that we have dart_codemod, this tool should be ported to dart.
This PR adds the first of 3 codemods:
dart1_to_dart1_and_dart2
As well as a readme and tests.
Testing
Code Review
@corwinsheahan-wf @sebastianmalysa-wf @georgelesica-wf @smaifullerton-wk