Presets
DCM includes 15 sets of predefined configurations:
- All: contains all available lint rules for Dart and Flutter.
- Recommended: contains recommended Dart and Flutter rules (with an emphasis on finding errors).
- Dart: contains all lint rules applicable to any Dart app.
- Flutter: contains all lint rules applicable to any Flutter app.
- Bloc: contains lint rules for the Bloc package.
- Equatable: contains lint rules for the Equatable package.
- Flame: contains lint rules for the Flame package.
- Provider: contains lint rules for the Provider package.
- Patrol: contains lint rules for the Patrol package.
- FakeAsync: contains lint rules for the FakeAsync package.
- GetIt: contains lint rules for the GetIt package.
- FlutterHooks: contains lint rules for the FlutterHooks package.
- Intl: contains lint rules for the Intl package.
- Pub: contains lint rules to check for issues in the pubspec.yaml file.
- Recommended metrics: contains recommended configured metrics.
While presets are a great way to keep track of rule list updates, upgrading to a newer version of DCM can introduce new issues if the preset has been updated.
Consider this before choosing a preset.
Built-in presets
To simplify the tool's integration, the "recommended" preset can be enabled without installing the "dart_code_metrics_presets" package.
dart_code_metrics:
extends:
- recommended
Since this preset comes with the executable, the list of rules included into it depends on the executable version, but is expected to match the latest version of located here.
Enabling a preset
To enable a preset:
-
Install dart_code_metrics_presets as a dev dependency:
- Flutter
- Dart
$ flutter pub add --dev dart_code_metrics_presets
$ dart pub add --dev dart_code_metrics_presets
-
For DCM configuration add the
extends
entry:analysis_options.yamldart_code_metrics:
extends:
- package:dart_code_metrics_presets/all.yaml
If you are reusing a shared configuration between multiple packages, they should all have dart_code_metrics_presets
as dev dependency.
If the preset cannot be resolved, a preset-not-found
warning will be shown.
Reconfiguring a rule
To reconfigure a rule included into a preset:
dart_code_metrics:
extends:
- package:dart_code_metrics_presets/all.yaml
rules:
- arguments-ordering:
child-last: true
Disabling a rule
To disable a rule set its configuration to : false
:
dart_code_metrics:
extends:
- package:dart_code_metrics_presets/all.yaml
rules:
- avoid-banned-imports: false
Defining a custom preset
Any other preset can be passed to the extends
entry. To create a custom preset create a yaml
file with the same structure as for regular DCM configuration.