Recently, I want 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 create a file
analysis_options.yaml under the root directory and setup 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, then you only need to
include the plugins 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 specially for flutter.
Officially recommend version flutter_lints. The official flutter lint needs the Flutter version is greater or equal to
2.12, if you are now using an old flutter version that you can use this community version.
- Community flutter lint lint, it’s document is very clearly.