Skip to content
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

[riverpod_lint] Dependencies lint misses providers used in methods #2417

Closed
gaetschwartz opened this issue Apr 1, 2023 · 2 comments · Fixed by #2435
Closed

[riverpod_lint] Dependencies lint misses providers used in methods #2417

gaetschwartz opened this issue Apr 1, 2023 · 2 comments · Fixed by #2435
Labels
bug Something isn't working linter

Comments

@gaetschwartz
Copy link

gaetschwartz commented Apr 1, 2023

Describe the bug
When using a provider inside a method that is being called in the build method, the provider usage is not detected.

To Reproduce
In this code, the linter doesn't detect the usage of eventsWithStreamedCompletionProvider:

@Riverpod(dependencies: [calendars])
class CalendarFeed extends _$CalendarFeed {
  @override
  Future<CalendarFeedState> build() async {
    final calendars = await ref.watch(calendarsProvider.future);
    final events = await listenToEvents();
    return CalendarFeedState(events: events, calendars: calendars);
  }

  Future<List<EventWithAsyncCompletion>> listenToEvents() async {
    final completer = Completer<List<EventWithAsyncCompletion>>();
    ref.listen(
		eventsWithStreamedCompletionProvider(),  
		/*function that completes the completer*/
	);
    final events = await completer.future;
    return events;
  }
}

but it does here:

@Riverpod(dependencies: [calendars])
class CalendarFeed extends _$CalendarFeed {
  @override
  Future<CalendarFeedState> build() async {
    final calendars = await ref.watch(calendarsProvider.future);
    final completer = Completer<List<EventWithAsyncCompletion>>();
    ref.listen(
		eventsWithStreamedCompletionProvider(),  
		/*function that completes the completer*/
	);
    final events = await completer.future;
    return CalendarFeedState(events: events, calendars: calendars);
  }
}

Expected behavior
It should detect it as well or at least give a way to add it manually to then dependencies without the linter complaining (forcing).

@gaetschwartz gaetschwartz added bug Something isn't working needs triage labels Apr 1, 2023
@gaetschwartz gaetschwartz changed the title [riverpod_lint] Dependencies lint misses providers used in functions [riverpod_lint] Dependencies lint misses providers used in methods Apr 1, 2023
@rrousselGit
Copy link
Owner

It's not necessarily a bug

Only scoped providers need to be specified. Is eventsWithStreamedCompletionProvider() scoped?
If not, then the lint is fine.

I'd need to see eventsWithStreamedCompletionProvider() to be sure.

@rrousselGit rrousselGit added question Further information is requested and removed needs triage labels Apr 1, 2023
@gaetschwartz
Copy link
Author

I'm not sure what you mean by scoped. But here is a rough implementation of it:

@Riverpod(dependencies: [eventsWith, profiles])
Stream<List<EventWithAsyncCompletion>> eventsWithStreamedCompletion(
  EventsWithStreamedCompletionRef ref, [
  EventProviderParam param = const EventProviderParam(),
]) async* {
  final f = await ref.watch(profilesProvider.future);
  final events = await ref.watch(eventsWithProvider(param).future);

  final cache = events
      .map((e) => EventWithAsyncCompletion(e, const AsyncLoading()))
      .toList();
  yield cache;
  yield* Stream.fromFutures(events.map(updateCache)).map((_) => cache);
}

@rrousselGit rrousselGit added linter and removed question Further information is requested labels Apr 6, 2023
rrousselGit added a commit that referenced this issue Apr 7, 2023
rrousselGit added a commit that referenced this issue Apr 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working linter
Projects
None yet
2 participants