Check Exports Completeness
Checks that an exported API exports all used types (even transitive).
To execute the command, run:
$ dcm check-exports-completeness lib # or dcm ec lib
Full command description:
Usage: dcm check-exports-completeness [arguments] <directories>
-h, --help Print this usage information.
-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 found not exported code as fatal.
(defaults to on)
Suppressing the Command​
To suppress the command for an entire file, add the ignore_for_file: exports
comment to the beginning of a file.
@visibleForTesting Annotation Support​
This command does no report types that are used in parameters marked "@visibleForTesting" as they are not expected to be part of the public API.
@internal Annotation Support​
Any exported declarations marked @internal is reported by this command as internal declarations are not expected to be exported. To fix these issues, try hiding reported declarations, making them private or removing the @internal annotation.
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 incomplete export 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 formatincompleteExports
- an array of incomplete exports issues
{
"formatVersion": 2,
"timestamp": "2021-04-11 14:44:42",
"incompleteExports": [
{
...
},
{
...
},
{
...
}
]
}
The incompleteExports object fields are​
path
- a relative path of the file with the declaration that needs to be exportedissues
- an array of issues detected in the target class
{
"path": "lib/src/some/class.dart",
"issues": [
...
],
}
The issue object fields are​
referencePath
- the path representing the call chain from the entrypoint to this declarationisMarkedInternal
- a boolean flag value that indicates declarations marked @internaldeclarationName
- the name of a declaration that needs to be exporteddeclarationType
- the type of a declaration that needs to be exported (function, method or constructor)offset
- a zero-based offset of the class member location in the sourceline
- a zero-based line of the class member location in the sourcecolumn
- a zero-based column of class member the location in the source
{
"referencePath": "entrypoint > someClass",
"isMarkedInternal": false,
"declarationName": "someFunction",
"declarationType": "function",
"offset": 156,
"line": 7,
"column": 1
}
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":"exports-issue","description":"class DuplicationAnalysisConfig is part of the public API and should be exported","categories":["Bug Risk"],"location":{"path":"lib/src/analyzers/duplication_analyzer/duplication_analysis_config.dart","positions":{"begin":{"column":1,"line":3},"end":{"column":2,"line":30}}},"severity":"major","fingerprint":"e45515ff56de0dcd92be41d3bd2797d1"}
{"type":"issue","check_name":"exports-issue","description":"class StructureAnalysisConfig is part of the public API and should be exported","categories":["Bug Risk"],"location":{"path":"lib/src/analyzers/structure_analyzer/structure_analysis_config.dart","positions":{"begin":{"column":1,"line":3},"end":{"column":2,"line":31}}},"severity":"major","fingerprint":"a40b1c5a31b1687ad12e9c068c18c8b3"}
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="function myFunction is part of the public API and should be exported" source="exports-issue"/>
</file>
<file name="../class_with_factory_constructors.dart">
<error line="0" severity="warning" message="class MyClass is part of the public API and should be exported" source="exports-issue"/>
<error line="0" severity="warning" message="function myFunction is marked as 'internal' but is publicly accessible" source="exports-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/exports-completeness/",
"engineId": "dcm",
"id": "exports-issue",
"impacts":[
{
"severity": "MEDIUM",
"softwareQuality": "MAINTAINABILITY"
}
],
"name": "exports-issue"
}
],
"issues": [
{
"effortMinutes": 5,
"primaryLocation": {
"filePath": "lib/src/umbrella/models/umbrella_reports.dart",
"message": "class UmbrellaReports is part of the public API and should be exported",
"textRange": {
"endColumn": 2,
"endLine": 84,
"startColumn": 1,
"startLine": 13
}
},
"ruleId": "exports-issue"
}
]
}