This is collection of Flutter lints that we use and follow in Miquido Software development company.
This is strict, large and robust collection because we strive for high quality code, good practices and we want follow the same coding style in all our mobile apps.
And we just looooove lots of lints. 💙
For a start please make sure you work with latest version of Flutter & Dart.
environment:
sdk: ">=3.4.4 <4.0.0"
flutter: ^3.22.3
Then add a dev dependency in your pubspec.yaml
:
From command line:
flutter pub add --dev lint_quido
#then
pub get
or directly in pubspec.yaml
dev_dependencies:
lint_quido: 1.22.3
At last in analysis_options.yaml
add:
include: package:lint_quido/miquido_lints.yaml
And that is all folks! You are good to go!
If for some reason you don't want follow some lints, you can exclude or suppress them. You can always check example.
To completely exclude rule from linter, modify analysis_options.yaml
:
analyzer:
errors: #linters from flutter sdk
unawaited_futures: ignore
dart_code_metrics:
rules-exclude: #linters from dart_code_metrics
- prefer-last
In code add ignore comments
- at line level (comment directly above the specific line of code):
// ignore: public_member_api_docs
- at file level (comment at the top of the file):
// ignore: public_member_api_docs
To analyze your code in terminal use this commands:
# Default flutter analyze, mandatory to pass!
flutter analyze
# Dart metrics analyze, not mandatory to pass!
# Also it calculate total technical debt of your project.
dart run dart_code_metrics:metrics analyze lib
# Find unused files in your code! Nice to keep eye on this one.
dart run dart_code_metrics:metrics check-unused-files lib
# You can check if all nullable variables are necessary in your code with
dart run dart_code_metrics:metrics check-unnecessary-nullable lib
# find unused line of codes
dart pub run dart_code_metrics:metrics check-unused-code lib
Here you can find documentation about dart metrics commands.
Sometimes working with cutting-edge versions might cause dependencies incompatibilities. For example lint_quido
do not want to cooperate with test_api package or analyzer package and so on.
To overcome this use older version of package or try using
dependency_overrides
in your pubspec.yaml file.
In your pubspec add:
dependency_overrides:
test_api: 0.4.18
This is set of sources from which we are getting our linters and about good practices in Dart/Flutter:
- All Dart lints
- All Dart lints, but this time linter source code
- Customizing static analysis in Dart
- Effective Dart: Usage
- Flutter lints
- Dart Code Metrics
- Dart language type system