Fix
Fixes issues produced by dcm analyze
, dcm check-unused-code
, dcm check-unused-files
or dcm check-dependencies
commands.
Some quick fixes can break your code (e.g. the avoid-unused-parameters
fix removes a parameter, but any invocation will still have an argument for that parameter). It's up to you to choose the fixes and to ensure that the code works after they are applied.
To execute the command, run:
$ dcm fix lib # or dcm f lib
Full command description:
Usage: dcm fix [arguments] <directories>
-h, --help Print this usage information.
-t, --type=<lints> Type of issues to fix.
[lints (default), unused-code, unused-files, dependencies]
--unsafe Include unsafe fixes (fixes that can change the meaning/intent of your code).
--apply-to=<.*.g.dart> List of file to apply fixes to (all by default).
--dry-run Preview the proposed changes but make no changes.
--include-rules=<rule-id1,rule-id2,...> Include additional lint rules that are not listed in the config.
--exclude-rules=<rule-id1,rule-id2,...> Exclude lint rules from the fixes calculation.
--only-rules=<rule-id1,rule-id2,...> Calculate fixes for only listed rules.
Unused code options:
--no-exclude-overridden Do not treat overridden members as always used.
Formatter options:
-l, --line-length Wrap lines longer than this.
-i, --indent Add this many spaces of leading indentation.
--cascading-widget-extensions Format widget extensions in a more readable way.
-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.
--email The email used to purchase the license.
--no-analytics Disable sending anonymous usage statistics.
--exclude-public-api (--ep) Exclude publicly exported code from the analysis output.
Currently Supported Rules​
Almost all rules that have 🛠are supported by dcm fix
.
Rules with auto-fixes, but not fixable by dcm fix
:
Of the 138 rules that support auto-fixes, here is the list of those (47 rule) that cannot be fixed from the CLI:
- avoid-banned-annotations
- avoid-banned-imports
- avoid-bloc-public-methods
- avoid-cascade-after-if-null
- avoid-casting-to-extension-type
- avoid-declaring-call-method
- avoid-double-slash-imports
- avoid-duplicate-cascades
- avoid-duplicate-map-keys
- avoid-duplicate-mixins
- avoid-duplicate-patterns
- avoid-duplicate-test-assertions
- avoid-empty-test-groups
- avoid-equal-expressions
- avoid-importing-entrypoint-exports
- avoid-missing-image-alt
- avoid-missing-tr
- avoid-mutable-rx-variables
- avoid-non-final-exception-class-fields
- avoid-renaming-representation-getters
- avoid-suspicious-super-overrides
- avoid-top-level-members-in-tests
- avoid-unnecessary-if
- avoid-unsafe-collection-methods
- correct-game-instantiating
- match-positional-field-names-on-assignment
- move-records-to-typedefs
- move-variable-outside-iteration
- prefer-action-button-tooltip
- prefer-any-or-every
- prefer-correct-bloc-provider
- prefer-correct-error-name
- prefer-correct-future-return-type
- prefer-correct-setter-parameter-name
- prefer-correct-stream-return-type
- prefer-correct-throws
- prefer-dedicated-media-query-methods
- prefer-define-hero-tag
- prefer-explicit-type-arguments
- prefer-match-file-name
- prefer-parentheses-with-if-null
- prefer-private-extension-type-field
- prefer-public-exception-classes
- prefer-specific-cases-first
- prefer-text-rich
- prefer-widget-private-members
- tag-name
Unsafe Fixes​
Some fixes can change the meaning/intent of your code and are considered unsafe. Such fixes are disabled by default.
To enabled unsafe fixes, pass the --unsafe
CLI option.
Rules with unsafe
fixes:
- avoid-unused-parameters
- avoid-unnecessary-super
- avoid-unnecessary-nullable-return-type
- use-existing-variable
Overriding the Rules Set​
By default, the command takes the rules list from the configuration, but you can override this behavior with several CLI options:
--include-rules
allows you to add rules that are not listed in your config, but you want to apply their fixes as well- Use
--exclude-rules
to exclude rules listed in your config from fixes calculation - Use
--only-rules
to run calculate fixes only for the given list of rules
Dry Run​
If you want to see the proposed changes without applying them, run the command with the --dry-run
option. It will output the code that will be changed marking removed code with the red color and the code that will be added with the green.
Removing Unused Code​
To remove unused code with dcm fix
set the --type
option to unused-code --type=unused-code
. To exclude publicly exported code, don't forget to pass --exclude-public-api
.
Removing Unused Files​
To remove unused files with dcm fix
set the --type
option to unused-files --type=unused-files
. To exclude publicly exported code, don't forget to pass --exclude-public-api
.
Fixing Dependency Issues​
To fix dependency issus with dcm fix
set the --type
option to dependencies --type=dependencies
.