Dart Code Metrics integration
How to integrate your workflows with Dart Code Metrics using codemagic.yaml
Dart Code Metrics is a powerful static analysis tool that helps improve code quality, ensure code consistency, and identify potential issues early in the development process.
Configuring Access to Dart Code Metrics
To get started with Dart Code Metrics, you need an API key and save it as an environment variable in Codemagic.
To effectively integrate Dart Code Metrics (DCM) into your Codemagic CI/CD pipeline, it’s essential to obtain a Team Plan API key. This key is a crucial component as it authorizes the use of DCM on CI/CD platforms, allowing you to run code analysis as part of your automated workflows.
Open your Codemagic app settings, and go to the Environment variables tab.
Enter the desired Variable name, e.g.
Copy and paste the API key string as Variable value.
Enter the variable group name, e.g. dcm_credntials. Click the button to create the group.
Make sure the Secure option is selected.
Click the Add button to add the variable.
Repeat the above process for
Add the variable group to your
environment: groups: - dcm_credntials
Configuring DCM Rules with
Dart Code Metrics (DCM) provides a flexible way to define and enforce coding standards through its rules. These rules are specified in a file named
analysis_options.yaml, which should be located at the root of your project. By configuring this file, you can tailor DCM to analyze your code according to specific guidelines that align with your project’s requirements and coding standards.
Here is a sample Rule set.
You can further customise the Rule set as per your requirements by visiting the Dart Code Metrics documentation at DCM Rules Documentation. This page provides a comprehensive list of all available rules along with their descriptions and configuration options.
After setting up your
analysis_options.yaml file with the desired Dart Code Metrics (DCM) rules, let’s configure our
- name: install DCM on Codemagic
brew tap CQLabs/dcm
brew install dcm
- name: Install flutter packages
script: flutter pub get
- name: Run DCM Analysis with License key
script: dcm analyze --ci-key=$DCM_KEY --email=$DCM_EMAIL_ID lib --reporter=console
By the end of this configuration process, you will have a fully automated system in place for running Dart Code Metrics analysis within your CI/CD pipeline, enhancing the quality and reliability of your Flutter application.