Command Line Interface
To use the package as a command-line tool, run:
- Flutter
- Dart
$ flutter pub run dart_code_metrics:metrics <command> lib
$ dart run dart_code_metrics:metrics <command> lib
Alternatively, the package can be installed globally:
- Flutter
- Dart
$ flutter pub global activate dart_code_metrics
$ metrics <command> lib
$ dart pub global activate dart_code_metrics
$ metrics <command> lib
It will produce a result in one of the supported formats:
- Console
- GitHub
- Checkstyle
- Codeclimate
- HTML
- JSON
You need to configure rules
entry in the analysis_options.yaml
to have rules report included into the result.
Available commands
The following table shows which commands you can use with the tool:
Command | Example of use | Short description |
---|---|---|
analyze | dart run dart_code_metrics:metrics analyze lib | Reports code metrics, rules and anti-patterns violations. |
check-unnecessary-nullable | dart run dart_code_metrics:metrics check-unnecessary-nullable lib | Checks unnecessary nullable parameters. |
check-unused-files | dart run dart_code_metrics:metrics check-unused-files lib | Checks unused *.dart files. |
check-unused-l10n | dart run dart_code_metrics:metrics check-unused-l10n lib | Checks unused localization in *.dart files. |
check-unused-code | dart run dart_code_metrics:metrics check-unused-code lib | Checks unused code in *.dart files. |
For additional help on any of the commands:
- Flutter
- Dart
$ flutter pub run dart_code_metrics:metrics --help <command>
$ dart run dart_code_metrics:metrics --help <command>
Multi-package repositories usage
If you run a command from the root of a multi-package repository (a.k.a. monorepo), it'll pick up analysis_options.yaml
files correctly.
Additionally, if you use Melos, you can add custom command to the melos.yaml
.
metrics:
run: |
melos exec -c 1 --ignore="*example*" -- \
flutter pub run dart_code_metrics:metrics analyze lib
description: |
Run `dart_code_metrics` in all packages.
- Note: you can also rely on your IDEs Dart Analysis / Issues window.
Calling DCM CLI from your own package with the linter configuration
If you have a separate package with all the linter and DCM configurations which is used by your other packages and you want to call DCM transitively add a bin
folder with a Dart file, for example
import 'package:dart_code_metrics/cli_runner.dart';
Future<void> main(List<String> args) async {
await CliRunner().run(args);
}
After that you will be able to run DCM by running your package executable.