-
-
Notifications
You must be signed in to change notification settings - Fork 945
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
Migrate widget field when convert Stateless-based and Stateful-based to each other. #3275
Migrate widget field when convert Stateless-based and Stateful-based to each other. #3275
Conversation
@@ -3,11 +3,22 @@ import 'package:hooks_riverpod/hooks_riverpod.dart'; | |||
import 'package:flutter_hooks/flutter_hooks.dart'; | |||
|
|||
class Stateless extends StatelessWidget { | |||
const Stateless({super.key}); | |||
const Stateless({ |
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.
Rather than editing existing scenarios, could you add new ones at the end of the file? This would make the diff in golden tests much simplers to read.
At the moment, I wouldn't know if there's a regression.
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.
Lovely PR! This will definitely help folks a bunch :) |
"offset": 1167, | ||
"length": 0, | ||
"replacement": "" |
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.
Sounds incorrect. We're now replacing nothing with nothing
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.
Fixed in d5b8b6d .
I've updated how goldens are formatted. It should be clearer to spot differences. Ideally this should only add new lines to goldens. It shouldn't edit existing lines. Also, could you update the changelog? |
@rrousselGit First, the previous method takes following steps:
Now, considering deleting the reference of the
Thus, even in existing cases, there will be a difference. |
@@ -147,89 +150,250 @@ class ConvertToStatelessBaseWidget extends RiverpodAssist { | |||
.whereType<MethodDeclaration>() | |||
.firstWhereOrNull((element) => element.name.lexeme == 'createState'); | |||
if (createStateMethod != null) { | |||
builder.addDeletion(createStateMethod.sourceRange); | |||
builder.addDeletion(createStateMethod.sourceRange.getExpanded(1)); |
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.
Could you add a comment about what this is about? The line isn't very clear to me
packages/riverpod_lint/lib/src/assists/convert_to_stateless_base_widget.dart
Outdated
Show resolved
Hide resolved
packages/riverpod_lint/lib/src/assists/convert_to_stateless_base_widget.dart
Show resolved
Hide resolved
packages/riverpod_lint/lib/src/assists/convert_to_stateless_base_widget.dart
Show resolved
Hide resolved
packages/riverpod_lint/lib/src/assists/convert_to_stateless_base_widget.dart
Show resolved
Hide resolved
packages/riverpod_lint/lib/src/assists/convert_to_stateless_base_widget.dart
Show resolved
Hide resolved
packages/riverpod_lint/lib/src/assists/convert_to_stateless_base_widget.dart
Show resolved
Hide resolved
} | ||
} | ||
|
||
// Original implemenation in |
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.
Do you mind extracting all analyzer code in a separate file, explicitly stated as such?
); | ||
} | ||
|
||
// ignore: prefer_foreach |
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.
Don't ignore the lint :)
} | ||
|
||
// Search for the associated State class | ||
final stateClass = findStateClass(widgetClass); | ||
if (stateClass == null) return; | ||
|
||
final fieldFinder = _FieldFinder(); |
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.
It would likely be worth extracting the field conversion logic to a method
Thanks for your response! I'll try running your PR locally to better understand the goldens diffs. At the moment it's a bit hard to understand why we have differences :) |
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 approving this for now, but probably will merge at a later date.
I'd like to maybe change how goldens are stored. I don't like that I need to manually run the tests to understand the diffs
I'll try computing the actual resulting code, rather than the changes.
Found a neat way to execute "changes" on a file. I'll update goldens accordingly, and check again your PR |
… pr/Kurogoma4D/3275-1
Alright, that's wayyy more readable now. Let's have a second look! |
...es/riverpod_lint_flutter_test/test/assists/convert_to_widget/convert_to_consumer_widget.diff
Show resolved
Hide resolved
Alright, I've looked at all the diffs, and everything looks great! Thanks again for this :) |
Sorry for the late response, and thanks to the detailed confirmation :) I haven't yet changes that you reviewed points, should I do it later? |
I figured it wasn't worth delaying such a change for these small code improvements. |
In the official Dart
analysis_server
, when converting between Flutter'sStatefulWidget
andStatelessWidget
, thewidget
field used inStatefulWidget
is automatically added or removed.However, this was not supported in the Assists within riverpod_lint.
In this PR, I have improved it to include the migration of that field in the conversion.