Skip to main content

Analyze

Reports lint rules violations.

info

You need to configure rules entry in the analysis_options.yaml before running this command.

To execute the command, run:

$ dcm analyze lib # or dcm a lib

Full command description:

Usage: dcm analyze [arguments] <directories>
-h, --help Print this usage information.


-r, --reporter=<console> Analysis output format.
[console(Free+) (default), json(Teams+), codeclimate(Teams+), gitlab(Teams+), checkstyle(Teams+), github(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)
--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.
--exclude=<{**/*.g.dart,**/*.freezed.dart}> File paths in Glob syntax to be exclude.
(defaults to "{**/*.g.dart,**/*.freezed.dart}")


--[no-]congratulate Show output even when there are no issues.


--verbose Show verbose logs.


--ci-key The license key to run on CI server.
--email The email used to purchase the license.


--no-analytics Disable sending anonymous usage statistics.


--[no-]fatal-style Treat style level issues as fatal.
--[no-]fatal-warnings Treat warning level issues as fatal.
(defaults to on)

Output Example

Console (default)

Use --reporter=console to get output in console format.

Console

JSON

Use --reporter=json to get output as a single JSON object containing metadata and the list of lint 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 format
  • records - an array of objects
{
"formatVersion": 2,
"timestamp": "2021-04-11 14:44:42",
"records": [
{
...
},
{
...
},
{
...
}
]
}

The record object fields are

  • path - a relative path to the target file
  • issues - an array of issues detected in the target file
{
"path": "lib/src/metrics/metric_computation_result.dart",
"issues": [
...
]
}

The issue object fields are

  • ruleId - an id of the rule associated with the issue
  • documentation - an url of a page containing documentation associated with the issue
  • codeSpan - a source code span associated with the issue
  • severity - a severity of the issue
  • message - a short message
{
"ruleId": "avoid-long-parameter-list",
"documentation": "https://dcm.dev/docs/rules/commont/avoid-long-parameter-list",
"codeSpan": {
...
},
"severity": "warning",
"message": "Long Parameter List. This function require 5 arguments.",
}

The code span object fields are

  • start - a start location of an entity
  • end - an end location of an entity
  • text - a source code text of an entity
{
"start": {
...
},
"end": {
...
},
"text": "entity source code"
}

The location object fields are

  • offset - a zero-based offset of the location in the source
  • line - a zero-based line of the location in the source
  • column - a zero-based column of the location in the source
{
"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":"prefer-match-file-name","description":"The first class name does not match the file name. Try renaming it.","categories":["Bug Risk"],"location":{"path":"lib/main.dart","positions":{"begin":{"column":7,"line":12},"end":{"column":12,"line":12}}},"severity":"critical","fingerprint":"99d316420d21b4c371325ad8d3092980"}
{"type":"issue","check_name":"proper-super-calls","description":"This 'super' call must come first.","categories":["Bug Risk"],"location":{"path":"lib/main.dart","positions":{"begin":{"column":5,"line":51},"end":{"column":23,"line":51}}},"severity":"critical","fingerprint":"5088440ac641ab4c3dc9e8282c95bab7"}

Checkstyle

Use --reporter=checkstyle to get output in Checkstyle format.

Output example
<?xml version="1.0"?>
<checkstyle version="10.0">
<file name="lib/src/analyzers/lint_analyzer/lint_analyzer.dart">
<error line="168" column="3" severity="ignore" message="Long method. This method contains 63 lines with code." source="long-method"/>
</file>
<file name="lib/src/analyzers/lint_analyzer/rules/rules_list/avoid_returning_widgets/visit_declaration.dart">
<error line="3" column="1" severity="ignore" message="Long Parameter List. This function require 6 arguments." source="long-parameter-list"/>
</file>
<file name="lib/src/analyzers/lint_analyzer/reporters/utility_selector.dart">
<error line="27" column="3" severity="ignore" message="Long method. This method contains 53 lines with code." source="long-method"/>
</file>
<file name="lib/src/analyzers/lint_analyzer/reporters/reporters_list/html/utility_functions.dart">
<error line="45" column="1" severity="ignore" message="Long function. This function contains 56 lines with code." source="long-method"/>
</file>
<file name="lib/src/analyzers/lint_analyzer/reporters/reporters_list/html/lint_html_reporter.dart">
<error line="74" column="3" severity="ignore" message="Long method. This method contains 136 lines with code." source="long-method"/>
<error line="330" column="3" severity="ignore" message="Long method. This method contains 159 lines with code." source="long-method"/>
</file>
</checkstyle>
note

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": "LOGICAL",
"description": "To learn more, visit the documentation https://dcm.dev/docs/rules/common/prefer-match-file-name",
"engineId": "dcm",
"id": "prefer-match-file-name",
"impacts": [
{
"severity": "MEDIUM",
"softwareQuality": "RELIABILITY"
}
],
"name": "prefer-match-file-name"
},
{
"cleanCodeAttribute": "LOGICAL",
"description": "To learn more, visit the documentation https://dcm.dev/docs/rules/flutter/proper-super-calls",
"engineId": "dcm",
"id": "proper-super-calls",
"impacts": [
{
"severity": "MEDIUM",
"softwareQuality": "RELIABILITY"
}
],
"name": "proper-super-calls"
},
],
"issues": [
{
"effortMinutes": 2,
"primaryLocation": {
"filePath": "lib/main.dart",
"message": "The first class name does not match the file name. Try renaming it.",
"textRange": {
"endColumn": 12,
"endLine": 12,
"startColumn": 7,
"startLine": 12
}
},
"ruleId": "prefer-match-file-name"
},
{
"effortMinutes": 5,
"primaryLocation": {
"filePath": "lib/main.dart",
"message": "This 'super' call must come first.",
"textRange": {
"endColumn": 23,
"endLine": 51,
"startColumn": 5,
"startLine": 51
}
},
"ruleId": "proper-super-calls"
}
]
}