Skip to main content
Pro+

Check Parameters

Checks parameters in functions, methods and constructors for various issues.

By default shows optional parameters that are never passed, parameters with unnecessarily nullable types, and optional parameters that are always passed and therefore unnecessarily marked as optional.

Additional checks are available under the corresponding options.

To execute the command, run:

$ dcm check-parameters lib # or dcm p lib

Full command description:

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


--show-same-value Include parameters that always get the same constant argument.
--show-unused-default-value Include parameters with default values that always get an argument.
--show-redundant Include parameters whose values are always passed with another parameter.
--show-unused-vft Include @visibleForTesting parameters that are never used in tests.
--show-broad-types Include parameters whose types can be made more specific.


-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}> Files to exclude (in Glob syntax).
(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.


-m, --monorepo Include publicly exported code into the check.


--[no-]fatal-found Treat parameter issues as fatal.
(defaults to on)

Additional Modes

All additional modes are currently experimental and can change in the future releases.

Parameters with the Same Value

Shows parameters that always receive the same constant value.

For example, passing the same constant string to all invocations of a function allows the parameter to be removed and its usage to be replaced by the passed constant value.

To highlight such parameters, pass the --show-same-value flag.

Parameters with Unused Default Values

Shows parameters with default values that always receive an argument making the default value redundant.

To highlight such parameters, pass the --show-unused-default-value flag.

Redundant Parameters

Shows parameters that are a field of another passed parameter and can be removed.

For example, if you pass a list as an argument and then pass its length as another argument to all invocations of a function, the parameter for length is redundant.

To highlight such parameters, pass the --show-redundant flag.

Parameters with Unused "@visibleForTesting" annotations

Shows all parameters that are not used in tests, but are annotated with @visibleForTesting.

To highlight such parameters, pass the --show-unused-vft flag.

Parameters with Broad Types

Shows parameters that have a broad type (based on passed arguments).

For example, if a function declaration has a parameter with the Object type, but all arguments passed for that parameter have the String type, such parameter will be considered as a broad-type parameter.

To highlight such parameters, pass the --show-broad-types flag.

Suppressing the Command

In order to suppress the command globally, add the ignore_for_file: parameters comment.

For local ignores, each separate issue type supports its own ignore:

  • unnecessary-nullable-parameters
  • never-passed-parameters
  • unnecessary-optional-parameters
  • same-value-parameters
  • redundant-default-value-parameters
  • redundant-parameters
  • unused-visible-for-testing-parameters
  • broad-type-parameters

Monorepo Support

warning

By default, this command treats all code that is exported from the package as used. It uses check-exports-completeness results and won't report even transitive public entities that are not exported directly.

This command also follows this convention of locating implementation files in the lib/src/ folder. If you don't follow this convention, you will need to pass the --monorepo flag for this command to work.

To disable this behavior use --monorepo flag. This might be useful when all the packages in your repository are only used within the repository and are not published to the pub.

Overriding the Monorepo Mode for a Particular Package

To override the monorepo mode for a particular package, set the monorepo entry in the analysis_options.yaml.

For example, if publicly exported files of a particular package are not expected to be changed, setting the monorepo entry to false and passing the --monorepo option will enable the monorepo mode for all other packages, but not the one with monorepo: false.

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 parameter 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
  • parameters - an array of parameter issues
{
"formatVersion": 2,
"timestamp": "2021-04-11 14:44:42",
"parameters": [
{
...
},
{
...
},
{
...
}
]
}

The parameters object fields are

  • path - a relative path of the file with the parameters declaration
  • issues - an array of issues detected in the target class
{
"path": "lib/src/some/class.dart",
"issues": [
...
],
}

The issue object fields are

  • declarationName - the name of a declaration with parameter issues
  • declarationType - the type of a declaration with parameter issues (function, method or constructor)
  • parameterName - the name of the parameter
  • parameterType - the type of the parameter
  • type - the type of the issue ("never-passed", "unnecessary-nullable", "same-value", "redundant-default-value", "unnecessary-optional", "unused-visible-for-testing", "broad-type", "redundant")
  • offset - a zero-based offset of the class member location in the source
  • line - a zero-based line of the class member location in the source
  • column - a zero-based column of class member the location in the source
{
"declarationName": "someFunction",
"declarationType": "function",
"parameterName": "value",
"parameterType": "String?",
"type": "unnecessary-nullable",
"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":"unnecessary-optional-parameter-issue","description":"This parameter is always passed and can be made non-optional","categories":["Bug Risk"],"location":{"path":"lib/src/buttons/pulldown_button.dart","positions":{"begin":{"column":5,"line":32},"end":{"column":17,"line":32}}},"severity":"major","fingerprint":"ebad761af1aaad5e071bea6a03cedff8"}
{"type":"issue","check_name":"unnecessary-nullable-parameter-issue","description":"This parameter is unnecessary nullable","categories":["Bug Risk"],"location":{"path":"lib/src/buttons/pulldown_button.dart","positions":{"begin":{"column":5,"line":149},"end":{"column":17,"line":149}}},"severity":"major","fingerprint":"9c85582a0162139ef3eb6af21de6271c"}

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="This parameter always gets the same value" source="redundant-default-value"/>
</file>
<file name="../class_with_factory_constructors.dart">
<error line="0" severity="warning" message="This parameter is unnecessary nullable" source="unnecessary-nullable-parameter-issue"/>
</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": "CLEAR",
"description": "To learn more, visit the documentation https://dcm.dev/docs/cli/code-quality-checks/check-parameters/",
"engineId": "dcm",
"id": "unnecessary-nullable-parameter-issue",
"impacts": [
{
"severity": "MEDIUM",
"softwareQuality": "MAINTAINABILITY"
}
],
"name": "unnecessary-nullable-parameter-issue"
}
],
"issues": [
{
"primaryLocation": {
"filePath": "lib/src/unnecessary_nullable_widget.dart",
"message": "This parameter is unnecessary nullable",
"textRange": {
"endColumn": 34,
"endLine": 9,
"startColumn": 21,
"startLine": 9
}
},
"ruleId": "unnecessary-nullable-parameter-issue"
}
]
}