Skip to main content

Getting Started

DCM (formerly Dart Code Metrics) is a toolkit that helps you identify and fix problems in your Dart and Flutter code. These problems can range from potential runtime bugs and violations of best practices to styling issues. DCM includes over 280 built-in rules to validate your code against various expectations, and you can customize these rules to fit your specific needs.

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 Features page.

Installation

The installation process is similar to the Dart SDK.

First, download the executable for your platform:

You can install the DCM executable using Chocolatey.

To install the executable:

C:/> choco install dcm

To install a specific version:

C:/> choco install --version 1.15.0

To upgrade the executable:

C:/> choco upgrade dcm

If you can't use the executables, add it to your PATH:

  1. In the Windows search box, type env.
  2. Click Edit the system environment variables.
  3. Click Environment Variables….
  4. In the user variable section, select Path and click Edit….
  5. Click New, and enter the path to the executable.
  6. In each window that you just opened, click Apply or OK to dismiss it and apply the path change.

You can also download a .zip archive with the 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

Ensuring the entire team installs the IDE extensions

To ensure that your team members who use VS Code install the extension, configure the "Workspace recommended extensions".

For IntelliJ / AS, to be notified when a plugin is not installed, configure the list of "Required plugins".

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.

info

License activation uses the device id, so attempts to activate a license multiple times on the same device won't subtract the activations count.

Deactivating the device

To deactivate the current device, run dcm deactivate. After the command completes you get one restored activation back to your license.

This command is not available during the trial period.

warning

If you have the Teams license, you won't be able to reactivate the same device.

If you deactivated your device by a mistake, please contact our support.

Running executable on CI/CD

info

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.

warning

Consider pinning the tool's version on CI, as each new release usually comes with fixes for false positives / new cases that can cause unexpected CI failures.

Migrating from the plugin version

If you're migrating from the plugin version, follow these steps:

  1. Remove DCM as your package dependency.
  2. Remove DCM from the plugins section of the analysis_options.yaml. All other configuration can be left unchanged.
  3. Instead of calling dart pub run dart_code_metrics:metrics analyze lib simply call dcm analyze lib.
  4. 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.

Enabling DCM rules

To quickly start with DCM rules, enable the "recommended" preset.

analysis_options.yaml
dart_code_metrics:
extends:
- recommended

Next Steps