Check Dependencies
Checks missing, under-promoted, over-promoted, and unused dependencies.
To execute the command, run:
$ dcm check-dependencies lib # or dcm d lib
Full command description:
Usage: dcm check-dependencies [arguments] <directories>
-h, --help Print this usage information.
--ignored-packages=<my-package,other,...> Package names that should be ignored.
-r, --reporter=<console> Analysis output format.
[console(Pro+) (default), json(Teams+), codeclimate(Teams+), gitlab(Teams+), checkstyle(Teams+), sonar(Teams+)]
-a, --absolute-path Show absolute paths in console reporter output.
--json-path=<path/to/file.json> Path to the JSON file with the analysis output.
-c, --print-config Print resolved config.
--root-folder=<./> Root folder.
(defaults to the current directory)
-s, --sdk-path=<directory-path> Dart SDK directory path.
If the project has a `.fvm/flutter_sdk` symlink, it will be used if the SDK is not found.
-e, --exclude=<{**/*.g.dart,**/*.freezed.dart}> File paths in Glob syntax to be exclude.
(defaults to "{**/*.g.dart,**/*.freezed.dart}")
--[no-]congratulate Don't show output even when there are no issues.
--verbose Show verbose logs.
--ci-key The license key to run on CI server. Can be provided via DCM_CI_KEY env variable.
--email The email used to purchase the license. Can be provided via DCM_EMAIL env variable.
--no-analytics Disable sending anonymous usage statistics.
--[no-]fatal-found Treat dependency issues as fatal.
(defaults to on)
Suppressing the Command​
To suppress issues produced by the command, use the # ignore: dependencies
comment. To suppress the command for an entire file, add the # ignore_for_file: dependencies
comment to the beginning of a file.
Automatically Excluded Packages​
By default the command looks for direct usage in Dart code, but for some packages this is not how they are used (e.g. codegen packages).
Here is the list of packages that the command considers used:
flutter_gen
,flutter_launcher_icons
andflutter_native_splash
(if there is a configuration entry in the pubspec file)riverpod_generator
,mobx_codegen
,go_router_builder
,freezed
,json_serializable
and many others (if the corresponding package, for exampleriverpod
forriverpod_generator
, is present in the dependencies)
When any of the codegen packages are present, build_runner
is automatically marked as used.
Ignoring Particular Packages from the Report​
In order to ignore particular packages from the report, pass the --ignored-packages
option to the CLI.
Output Example​
Console (default)​
Use --reporter=console
to get output in console format.
JSON​
Use --reporter=json
to get output as a single JSON object containing metadata and the list of dependency issues.
Format specification
The root object fields are​
formatVersion
- an integer representing the format version (will be incremented each time the serialization format changes)timestamp
- a creation time of the report in YYYY-MM-DD HH:MM:SS formatdependencyIssues
- an array of dependency issues
{
"formatVersion": 1,
"timestamp": "2021-04-11 14:44:42",
"dependencyIssues": [
{
...
},
{
...
},
{
...
}
]
}
The dependencyIssues object fields are​
path
- a relative path of the unused fileissues
- an array of issues detected in the target file
{
"path": "lib/src/some/file.dart",
"issues": [
...
],
}
The issue object fields are​
message
- the message associated with the issuetargetDependencyType
- the type of the pubspec dependency (can be "regular" or "dev")type
- the type of the issue (can be "unused", "promotion" or "missing")offset
- a zero-based offset of the dependency location in the pubspec.yaml fileline
- a zero-based line of the dependency location in the pubspec.yaml filecolumn
- a zero-based column of the dependency location in the pubspec.yaml file
{
"message": "Dependency is unused",
"offset": 156,
"line": 7,
"column": 1,
"type": "unused",
"targetDependencyType": "regular"
}
GitLab​
Use --reporter=gitlab
to get output in a GitLab-compatible format. To learn how to integrate DCM with GitLab, refer to this guide.
Code Climate​
Use --reporter=codeclimate
to get output in Code Climate
format.
Output example
{"type":"issue","check_name":"unused-dependency-issue","description":"mocktail is not used","categories":["Bug Risk"],"location":{"path":"pubspec.yaml","positions":{"begin":{"column":3,"line":23},"end":{"column":11,"line":23}}},"severity":"major","fingerprint":"7d8ebc838a392534d11bf306281be92b"}
Checkstyle​
Use --reporter=checkstyle
to get output in Checkstyle
format.
Output example
<?xml version="1.0"?>
<checkstyle version="10.0">
<file name="../abstract_class.dart">
<error line="0" severity="warning" message="another_package, package should be listed in dev dependencies" source="missing-dependency-issue"/>
</file>
<file name="../class_with_factory_constructors.dart">
<error line="0" severity="warning" message="some_package is not used" source="unused-dependency-issue"/>
</file>
</checkstyle>
Checkstyle
format is supported by Bitbucket. To learn how to integrate DCM with Bitbucket, refer to this guide.
Sonar​
Use --reporter=sonar
to get output in SonarQube's generic format for external issues.
Output example
{
"rules": [
{
"cleanCodeAttribute": "CLEAR",
"description": "To learn more, visit the documentation https://dcm.dev/docs/cli/code-quality-checks/check-dependencies/",
"engineId": "dcm",
"id": "unused-dependency-issue",
"impacts": [
{
"severity": "MEDIUM",
"softwareQuality": "MAINTAINABILITY"
}
],
"name": "unused-dependency-issue"
}
],
"issues": [
{
"effortMinutes": 2,
"primaryLocation": {
"filePath": "pubspec.yaml",
"message": "cupertino_icons is not used",
"textRange": {
"endColumn": 18,
"endLine": 14,
"startColumn": 3,
"startLine": 14
}
},
"ruleId": "unused-dependency-issue"
},
{
"effortMinutes": 2,
"primaryLocation": {
"filePath": "pubspec.yaml",
"message": "dart_code_metrics is not used",
"textRange": {
"endColumn": 20,
"endLine": 18,
"startColumn": 3,
"startLine": 18
}
},
"ruleId": "unused-dependency-issue"
}
]
}