df_safer_dart_lints provides custom lint rules for df_safer_dart that help enforce safety patterns at compile-time. These rules work with the custom_lint package.
| Rule | Severity | Purpose |
|---|---|---|
must_use_outcome_or_error |
Error | Ensures Option/Result/Resolvable return values are handled |
no_future_outcome_type_or_error |
Error | Prevents Future<Result> types (use Async instead) |
must_await_all_futures |
Warning | Ensures Futures are awaited in annotated scopes |
must_await_all_futures_or_error |
Error | Same as above, but as error |
must_be_anonymous |
Warning | Ensures anonymous functions are passed where required |
must_be_anonymous_or_error |
Error | Same as above, but as error |
must_be_strong_ref |
Warning | Ensures strong-referenced variables are passed (for weak listener patterns) |
must_be_strong_ref_or_error |
Error | Same as above, but as error |
must_handle_return |
Warning | Ensures return values are handled |
must_handle_return_or_error |
Error | Same as above, but as error |
no_futures |
Warning | Prevents Future usage in annotated scopes |
no_futures_or_error |
Error | Same as above, but as error |
must_use_unsafe_wrapper |
Warning | Ensures unsafe calls are wrapped in UNSAFE() |
must_use_unsafe_wrapper_or_error |
Error | Same as above, but as error |
Add to your pubspec.yaml:
dev_dependencies:
custom_lint: any
df_safer_dart_lints: any
df_safer_dart_annotations: any # Optional: for annotation-based rulesEnable in analysis_options.yaml:
analyzer:
plugins:
- custom_lint
# Optional: configure individual rules
custom_lint:
rules:
- must_use_outcome_or_error: true
- no_future_outcome_type_or_error: true
- must_await_all_futures: true
- must_be_anonymous: true
- must_use_unsafe_wrapper_or_error: true
- no_futures: true
# Recommended: suppress warnings for UNSAFE label usage
errors:
unused_label: ignore
non_constant_identifier_names: ignoreimport 'package:df_safer_dart/df_safer_dart.dart';
void main() {
// Error: must_use_outcome_or_error
// The result must be handled
fetchData(); // ❌ Triggers lint error
// OK: Result is handled
final result = fetchData(); // ✅
result.map((data) => print(data)).end(); // ✅
// Error: no_future_outcome_type_or_error
// Don't use Future<Result<T>>
Future<Result<String>> bad() async { ... } // ❌ Use Async<String> instead
}
Async<String> fetchData() {
return Async(() async {
return 'data';
});
}- df_safer_dart - Core safety types (Option, Result, Resolvable)
- df_safer_dart_annotations - Annotations for these lint rules
- custom_lint - Required for running custom lints
🔍 For more information, refer to the API reference.
This is an open-source project, and we warmly welcome contributions from everyone, regardless of experience level. Whether you're a seasoned developer or just starting out, contributing to this project is a fantastic way to learn, share your knowledge, and make a meaningful impact on the community.
- Find us on Discord: Feel free to ask questions and engage with the community here: https://discord.gg/gEQ8y2nfyX.
- Share your ideas: Every perspective matters, and your ideas can spark innovation.
- Help others: Engage with other users by offering advice, solutions, or troubleshooting assistance.
- Report bugs: Help us identify and fix issues to make the project more robust.
- Suggest improvements or new features: Your ideas can help shape the future of the project.
- Help clarify documentation: Good documentation is key to accessibility. You can make it easier for others to get started by improving or expanding our documentation.
- Write articles: Share your knowledge by writing tutorials, guides, or blog posts about your experiences with the project. It's a great way to contribute and help others learn.
No matter how you choose to contribute, your involvement is greatly appreciated and valued!
If you're enjoying this package and find it valuable, consider showing your appreciation with a small donation. Every bit helps in supporting future development. You can donate here: https://www.buymeacoffee.com/dev_cetera
This project is released under the MIT License. See LICENSE for more information.
