-
-
Notifications
You must be signed in to change notification settings - Fork 967
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
Add conversion assists for various widgets, including Hook-based widgets #2306
Conversation
packages/riverpod_lint/lib/src/assists/convert_to_hook_consumer_widget.dart
Outdated
Show resolved
Hide resolved
), | ||
), | ||
hookConsumerWidget( | ||
widgetName: 'HookConsumerWidget', |
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'd expect hook variants to have a higher priority than non-hook variants, but only show up if the analyzed package depends on hooks_riverpod/fluter_hooks.
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.
Bump on this, how that hooks are optional :)
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 tried to change the priority order as follows:
- ConvertToHookConsumerWidget
- ConvertToHookWidget
- ConvertToConsumerWidget
- ConvertToStatelessWidget
- ConvertToStatefulHookConsumerWidget
- ConvertToStatefulHookWidget
- ConvertToConsumerStatefulWidget
- ConvertToStatefulWidget
However, I'm not very confident about this order, so I'd appreciate it if you could let me know if this order seems good.
Additionally, I made some conversions optional.
Display only when there is a dependency on hooks_riverpod
- ConvertToHookConsumerWidget
- ConvertToStatefulHookConsumerWidget
Display only when there is a dependency on flutter_hooks
- ConvertToHookWidget
- ConvertToStatefulHookWidget
Great! Thanks for the change :) |
Sorry for the delay. I've updated custom_lint's Would you be interested in updating these to only apply hooks assists if hooks_riverpod is in the pubspec's dependencies? It should be a simple if condition. |
I'll give it a try👍 |
…_riverpod. (#1) * check hooks_riverpod dependency * fix test * add without hooks_riverpod dependency test
packages/riverpod_lint_flutter_test/test/assists/convert_to_consumer_widget_test.dart
Outdated
Show resolved
Hide resolved
…dency on flutter_hooks.
packages/riverpod_lint_flutter_test/test/assists/convert_to_widget_test.dart
Outdated
Show resolved
Hide resolved
node, | ||
resolver.source, | ||
// This adjustment assumes that the priority of the standard "Convert to StatelessWidget" is 30. | ||
isExactlyStatefulWidget ? -4 : 0, |
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.
Use named parameters
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.
Also, what is this supposed to be doing?
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 adjustment is due to the fact that the existing Convert to StatefulWidget and Convert to StatelessWidget both have a priority of 30.
https://github.com/dart-lang/sdk/blob/main/pkg/analysis_server/lib/src/services/correction/assist.dart#L224-L233
The priority of assists is generally set with Convert to StatefulWidget as 30, but the order will not be as expected when the source Widget is a StatefulWidget.
By making an adjustment of -4 to the priority only when it's a StatefulWidget, the priority is based on Convert to StatelessWidget 30, resulting in the expected display.
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 see, thanks!
This is looking pretty good! I'm currently having a second look at the code to make sure, but it's good so far :) |
Looking good! Thanks for your work :) |
Since ConvertToConsumerWidget and ConvertToConsumerStatefulWidget are useful, I've added conversions to other Widgets.
List of assists I've added:
Priority of Assists
Optional Assists
Display only when there is a dependency on hooks_riverpod
Display only when there is a dependency on flutter_hooks