Skip to main content
Teams

Fix

Fixes issues produced by dcm analyze, dcm check-unused-code or dcm check-dependencies commands.

info

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.


--type=<lints> Type of issues to fix.
[lints (default), unused-code, dependencies]
--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)
--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}> 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.


--monorepo Include publicly exported code into the check.

Currently supported rules

Almost all rules that have 🛠 are supported by dcm fix.

Of the 110 rules that have fixes, here is a list of those (32 rule) that cannot be fixed from the CLI:

  • avoid-banned-annotations
  • avoid-banned-imports
  • avoid-bloc-public-methods
  • avoid-cascade-after-if-null
  • avoid-declaring-call-method
  • avoid-double-slash-imports
  • avoid-duplicate-cascades
  • avoid-duplicate-map-keys
  • avoid-duplicate-mixins
  • avoid-empty-test-groups
  • avoid-equal-expressions
  • avoid-importing-entrypoint-exports
  • avoid-top-level-members-in-tests
  • 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-correct-bloc-provider
  • prefer-correct-error-name
  • prefer-correct-future-return-type
  • prefer-correct-stream-return-type
  • prefer-define-hero-tag
  • prefer-explicit-type-arguments
  • prefer-match-file-name
  • prefer-parentheses-with-if-null
  • prefer-private-extension-type-field
  • prefer-specific-cases-first
  • prefer-text-rich
  • prefer-widget-private-members
  • tag-name

Overriding rules set

By default, the command takes the rules list from the configuration, but you can override this behavior with several CLI options:

  1. --include-rules allows you to add rules that are not listed in your config, but you want to apply their fixes as well
  2. Use --exclude-rules to exclude rules listed in your config from fixes calculation
  3. 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. If you have a monorepo, don't forget to pass the --monorepo flag.

Fixing dependency issues

To fix dependency issus with dcm fix set the --type option to dependencies --type=dependencies.