Change-Id: I542aa5973aa22725980baf048fa07bc10d7b85bb Reviewed-on: https://dart-review.googlesource.com/c/89902 Reviewed-by: Brian Wilkerson <brianwilkerson@google.com> Commit-Queue: Dan Rubel <danrubel@google.com>
The dartfix tool is a command-line interface
for making automated updates to your Dart code.
The tool isn't in the Dart SDK;
instead, it's distributed in the dartfix package.
Usage
Important: Save a copy of your source code before making changes with
dartfix. Unlike dartfmt, which makes only safe changes (usually to whitespace),dartfixcan make changes that you might need to undo or modify.
Before you can use the dartfix tool, you need to
install it, as described below.
Then invoke it with the name of the directory that you want to update.
When you're ready to make the suggested changes,
add the --overwrite option.
$ dartfix examples/misc
... summary of recommended changes ...
$ dartfix examples/misc --overwrite
Features
As of release 0.1.3, dartfix can make the following changes to your code:
-
Convert code to use the following features added to Dart in 2.1:
- Find classes used as mixins, and convert them to use the
mixinkeyword instead ofclass. - Find
doubleliterals that end in.0, and remove the.0.
- Find classes used as mixins, and convert them to use the
-
Move named constructor type arguments from the name to the type.
For example, givenclass A<T> { A.from(Object obj) { } },dartfixchanges constructor invocations in the following way:Original code: A.from<String>(anObject) // Invokes the `A.from` named constructor. Code produced by dartfix: A<String>.from(anObject) // Same, but the type is directly after `A`.
Installing and updating dartfix
The easiest way to use dartfix is to globally install it,
so that it can be in your path:
$ pub global activate dartfix
Use the same command to update dartfix.
We recommend updating dartfix whenever you update your Dart SDK
or when a new feature is released.
Options
--[no-]color- Use colors when printing messages. On by default.
-f, --force- Apply the recommended changes even if the input code has errors.
-h, --help- See a complete list of `dartfix` options.
-v, --verbose- Verbose output.
-w, --overwrite- Apply the recommended changes.
Filing issues
If you want a new fix, first look at dartfix issues and star the fixes you want. If no issue exists for the fix, create a GitHub issue.