-
-
Notifications
You must be signed in to change notification settings - Fork 972
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
Linter #1034
Comments
What about inside a Provider, isn't it also a valid usage? |
I consider the body of a provider as a build method too. It's just that instead of taking a context and returning a Widget, it takes a ref and return your state. |
It'd be interesting if lints were to be used to highlight and offer quick fixes for performance optimizations, such as: // dart-lang/sdk#57147 AnalysisErrorType.info when provider could be watched further down the widget tree,
// at the lowest common denominator of all Widgets consuming counterProvider
Widget build(BuildContext context, WidgetRef ref) {
final counterValue = ref.watch(counterProvider); // throws lint error (info level)
return Scaffold(
body: Center(
child: Padding(
padding: const EdgeInsets.all(10.0),
child: Column(
children: <Widget>[
const Text(
"You have pushed the button this many times:",
),
// quick fix wraps Text widget in a ConsumerWidget
Text(
counterValue.toString(),
),
],
),
),
),
);
// dart-lang/sdk#57148 AnalysisErrorType.info when select() method can be used instead
Widget build(BuildContext context, WidgetRef ref) {
// throws lint error (info level)
final counterValue = ref.watch(asyncCounterProvider);
// quick fix replacement:
// final counterValue = ref.watch(asyncCounterProvider.select((value) => value.valueOrNull));
return Scaffold(
body: Column(
children: <Widget>[
const Text(
"You have pushed the button this many times:",
),
Text(
counterValue.value.toString(),
// quick fix replacement:
// counterValue.toString(),
),
],
),
);
}
I'm already comfortable with the analyzer APIs / custom_lint APIs from my own analyzer plugin development, so I could take this on myself if it seems worthwhile. What do you think @rrousselGit ? |
@pattobrien |
I just took a look at your PR / fork (looks top notch by the way), and see what you mean regarding potential conflicts. I don't want to unnecessarily derail any of the 2.0 plans, but would be more than happy to help in whatever timeline and capacity you see fit. |
@TimWhiting I'm not working on any lint. So as long as your PR is ready to merge, I'll do so. |
There would be too many false positives. We don't always need a select I think what's more appropriate is a refactoring command, like "refactor to use select". |
That's true if used strictly as a lint, but in a CI/CD environment or an environment where this enhancement were to be supported, such optimization analyses could be reserved for pre-launch or refactoring phases, rather than being enabled at all times in the IDE. Dart code metrics has some thought provoking use cases in this area, e.g. calculating total technical debt project-wide, # of independent paths in a method to determine code cleanliness. Such warnings would likely be annoying to deal with at all times, but for certain points in a development cycle the benefits are obvious. |
@pattobrien |
@TimWhiting awesome! today I familiarized myself with structure of the package (AsyncRecursiveVisitor, ProviderDeclaration, RiverpodVisitor etc).. I feel caught up to speed. But regarding the refactorings, are you talking about AnalysisErrorFixes or actual refactoring like |
Refactorings would need a PR to custom_lint to expose the associated API on the There's one, in analyzer_plugin. It's just not exposed by custom_lint yet |
@rrousselGit in an analyzer plugin I've been working on myself, the methods you're talking about I think there's a missing implementation on the |
I'm pretty sure they work. It's been a while, but I believe I used them before. |
Okay cool! Then I'll try it out tomorrow and open up a PR against custom_lint 👍🏼 |
I tried to implement refactorings by overriding the two I came across this sdk issue, as well as a recent groups discussion about the limitation of the analyzer plugin API. However, we can most likely use the assists API, as mentioned here. I'll explore implementing this into the |
Ah yes, I thought refactorings were quick assists If you're talking about things like "rename a property" which requires user input, there's no such thing. |
Right - for reference, anything requiring user input seems to be blocked by this LSP issue. Of the original 3 'Refactorings' and my proposed 2, only "extract to consumer widget" would make use of user input, so I'll plan to focus on all others first. |
There are a few more "convert to x" cases for the new code generator |
Riverpod_lint is out, so I'll close this :) riverpod_lint has an internal list of TODOs for tracking implemented lints. |
Let's add custom lint rules for helping to catch mistakes
It can include things such as:
dependencies
ref.read(autoDispose)
ref.watch(autoDispose)
(typically inside FutureProviders)ref.watch(family([]))
(or other non-constant object instantiation with no == override)and refactoring options such as:
The text was updated successfully, but these errors were encountered: