Flutter & Dart Lint

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.

Adding Dart Lint for your project, you only need create a file analysis_options.yaml under the root directory and setup some configuration.

Dart Lint Rules

The whole rules have many entries, usually we don’t need all of them. I list some configurations used by some famous companies.

  1. Effective Dart
  2. Google Team
  3. Flutter Official

Using Package to import lint rules

Dart Lints

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.

  1. Install lints
dart pub add --dev lints
  1. Include lint file into analysis_options.yaml
include: package:lints/recommended.yaml


include: package:lints/core.yaml

Flutter Lints

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.