Skip to content

add rule for riverpod code generation using riverpod annotation #1

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

matthias-prevost
Copy link
Member

@matthias-prevost matthias-prevost commented Apr 10, 2025

Cursor tends to write provider without code generation.
This rule ensure it uses riverpod annotation, and use the Ref type instead of the deprecated <ProviderName>Ref

## Riverpod
- Always use riverpod annotation when writing providers.
- When adding the ref parameter, use Ref type from the riverpod package (please add the riverpod package import statement), instead of using the ref dedicated to the provider (e.g. `<ProviderName>Ref`) which is deprecated and will be removed in version 3.0 of riverpod.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need to give some why to the IA in this case, you just need some clear "do and don't" to make it understand what is good code and what isn't
So here you can just say The ref parameter of a provider is of type "Ref"

If you want to be more explicit, what you can do is giving an example of good code and an example of bad code in xml tags:

<examples>
  <good>
  
import 'package:flutter_riverpod/flutter_riverpod.dart';

@riverpod
Future<int> myProvider(Ref ref){...}

  </good>
  <bad>
  
import 'package:flutter_riverpod/flutter_riverpod.dart';

@riverpod
Future<int> myProvider(MyProviderRef ref){...}

  </bad>
</examples>


## Riverpod
- Always use riverpod annotation when writing providers.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Always use the `@riverpod` annotation when writing providers.

It's more explicit in my opinion

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants