Skip to main content
Pro+

Check Unused L10n

Checks unused members of classes that provide localization strings.

An example of such class:

class ClassWithLocalization {
String get title {
return Intl.message(
'Hello World',
name: 'title',
desc: 'Title for the Demo application',
locale: localeName,
);
}
}

Read more about this localization approach in the Flutter docs.

warning

This command uses --class-pattern option to find classes that are used for accessing localization string. Passing it is mandatory.

To execute the command, run:

$ dcm check-unused-l10n lib # or dcm ul lib

Full command description:

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


-p, --class-pattern (mandatory) The pattern to detect classes providing localization.


-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-unused Treat find unused l10n 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 localization 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
  • unusedLocalizations - an array of unused files
{
"formatVersion": 2,
"timestamp": "2021-04-11 14:44:42",
"unusedLocalizations": [
{
...
},
{
...
},
{
...
}
]
}

The unusedLocalizations object fields are

  • path - a relative path of the unused file
  • className - a name of the class that has unused members
  • issues - an array of issues detected in the target class
{
"path": "lib/src/some/class.dart",
"className": "class",
"issues": [
...
],
}

The issue object fields are

  • memberType - unused class member type
  • memberName - unused class member name
  • 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
{ 
"memberType": "getter",
"memberName": "someGetter",
"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":"unused-localization-issue","description":"Unused getter homeTab","categories":["Bug Risk"],"location":{"path":"lib/src/home_i18n.dart","positions":{"begin":{"column":3,"line":10},"end":{"column":9,"line":14}}},"severity":"major","fingerprint":"1582e402ed53506873775a66a99a0611"}
{"type":"issue","check_name":"unused-localization-issue","description":"Unused getter profileTab","categories":["Bug Risk"],"location":{"path":"lib/src/home_i18n.dart","positions":{"begin":{"column":3,"line":16},"end":{"column":9,"line":20}}},"severity":"major","fingerprint":"fbbf8fd71cb883d03389d4797087bf8e"}

Checkstyle

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

Output example
<?xml version="1.0"?>
<checkstyle version="10.0">
<file name="example.dart">
<error line="5" column="3" severity="warning" message="Unused method someMethod()" source="unused-localization-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/unused-l10n/",
"engineId": "dcm",
"id": "unused-localization-issue",
"impacts": [
{
"severity": "MEDIUM",
"softwareQuality": "MAINTAINABILITY"
}
],
"name": "unused-localization-issue"
}
],
"issues": [
{
"primaryLocation": {
"filePath": "lib/src/home_i18n.dart",
"message": "Unused getter homeTab",
"textRange": {
"endColumn": 9,
"endLine": 14,
"startColumn": 3,
"startLine": 10
}
},
"ruleId": "unused-localization-issue"
},
{
"primaryLocation": {
"filePath": "lib/src/home_i18n.dart",
"message": "Unused getter profileTab",
"textRange": {
"endColumn": 9,
"endLine": 20,
"startColumn": 3,
"startLine": 16
}
},
"ruleId": "unused-localization-issue"
}
]
}