Getting Started
DCM (formerly Dart Code Metrics) is a tool that helps improve the quality and consistency of Dart code by identifying and reporting problems, such as bugs and code that doesn't follow best practices.
It also collects analytical data on the code through calculating code metrics and can be configured to set thresholds for these metrics.
To learn more about the tool capabilities, see the Core Concepts documentation.
Installation
The installation process is similar to the Dart SDK.
First, download the executable for your platform:
- Windows
- Linux
- macOS
You can install the DCM executable using Chocolatey.
To install the executable:
C:/> choco install dcm
To upgrade the executable:
C:/> choco upgrade dcm
If you can't use the executables, add it to your PATH:
- In the Windows search box, type env.
- Click Edit the system environment variables.
- Click Environment Variables….
- In the user variable section, select Path and click Edit….
- Click New, and enter the path to the executable.
- In each window that you just opened, click Apply or OK to dismiss it and apply the path change.
You can also download the .zip
archive with executable from our GitHub.
$ sudo apt-get update
$ wget -qO- https://dcm.dev/pgp-key.public | sudo gpg --dearmor -o /usr/share/keyrings/dcm.gpg
$ echo 'deb [signed-by=/usr/share/keyrings/dcm.gpg arch=amd64] https://dcm.dev/debian stable main' | sudo tee /etc/apt/sources.list.d/dart_stable.list
Then install the executable:
$ sudo apt-get update
$ sudo apt-get install dcm
Alternatively, download the executable as a Debian package in the .deb package format.
You can also download the .zip
archive with executable from our GitHub.
Don't forget to add the executable to PATH.
Install Homebrew, and then run the following commands:
$ brew tap CQLabs/dcm
$ brew install dcm
Important: Make sure the Homebrew bin directory is in your PATH. Setting up the path correctly makes it easier to use the executable. For help configuring your path, consult the Homebrew FAQ.
To upgrade when a new release DCM release is available:
$ brew tap CQLabs/dcm
$ brew upgrade dcm
Sometimes brew might not pickup the latest changes, in that case try
$ brew reinstall dcm
You can also download the .zip
archive with executable from our GitHub.
And then install the VS Code extension or IntelliJ / Android Studio plugin (depending on what IDE you use).
System requirements:
- 64-bit Windows OS, Linux OS or macOS system
- Installed Dart / Flutter SDK
Activating the license
After the installation of the executable and the IDE extension it's required to activate the tool. This is a one time operation.
To activate the license use dcm activate --license-key=YOUR_KEY
CLI command or IDEs extension command DCM: Activate license key
.
License activation uses the device id, so attempts to activate a license multiple times on the same device won't subtract the activations count.
Running executable on CI/CD
CI/CD integration is available only for the Teams version
In order to run commands on CI, instead of using dcm activate
it is expected that each command will be called with --ci-key
and --email
options. For example, dcm analyze --ci-key=YOUR_CI_KEY --email=LICENSE_EMAIL
.
Alternatively, you can set DCM_CI_KEY
and DCM_EMAIL
env variables and they will be picked up automatically.
Migrating from plugin version
If you're migrating from the plugin version, follow these steps:
- Remove DCM as your package dependency.
- Remove DCM from the
plugins
section of theanalysis_options.yaml
. All other configuration can be left unchanged. - Instead of calling
dart pub run dart_code_metrics:metrics analyze lib
simply calldcm analyze lib
. - Update CI/CD to also call
dcm
executable.
If you any feedback about the migration process or the tool, please join our Discord server or send us a message.
Integrating DCM into an existing project
DCM provides a command to generate a baseline. All the issues included onto the baseline file won't be reported by IDE and CLI. After which you can gradually remove generated issues from the file and fix them.
Read more about the command to generate the baseline.
There are other techniques available that can help you with the integration. You can learn more about them here.
Next Steps
- Learn about the configuration options for customizing DCM's behavior.
- Add rules from the rules list you find useful to your
analysis_options.yaml
configuration. - Get familiar with the Command Line Interface for running DCM from the console.
- Explore VS Code extension and IntelliJ plugin.