Recently, I wanted to add
Dart Lint for our flutter projects. The core function of the
Dart SDK analyzes the dart language is running an
Analysis Server at a background process. Dart can get the whole syntax tree of the project and then execute syntax detection and analysis.
Dart Lint for your project, you only need to create a file
analysis_options.yaml under the root directory and set up some configuration.
- The official website lists all rules：https://dart-lang.github.io/linter/lints/options/options.html
- The annotation of these rules: https://dart-lang.github.io/linter/lints/index.html
The whole rules have many entries. Usually, we don’t need all of them. I list some configurations used by some famous companies.
The lint rules will change when the Flutter and Dart version upgrade. If you don’t want to update these rules manually, you can depend on a flutter lint plugin, and then you only need to
include the plugin’s lint file in your
analysis_options.yaml. Of course, you can still write rules in the file to override the imported rules.
- Install lints
dart pub add --dev lints
- Include lint file into
The flutter lint contains some rules special for flutter.
Officially recommend version flutter_lints. The official flutter lint needs the Flutter version to be greater or equal to
2.12. If you are now using an old flutter version, you can use this community version.
- Community flutter lint lint, its document is very clear.