dartfix 0.1.6

  • Readme
  • Changelog
  • Example
  • Installing
  • 61

dartfix is a command-line tool for migrating your Dart code to use newer syntax styles.

Usage #

Important: Save a copy of your source code before making changes with dartfix. Unlike dartfmt, which makes only safe changes (usually to whitespace), dartfix can 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 #

dartfix applies different types of "fixes" to migrate your Dart code. By default, all fixes are applied, but you can select only the specific fixes you want. See dartfix --help for more about the available command line options.

Some of the fixes that you can apply are "required" in that the Dart language is changing and at some point the old syntax will no longer be supported. To only apply these changes, pass the --required option on the command line. The required fixes include:

  • Find classes used as mixins, and convert them to use the mixin keyword instead of class. Mixin support is one of the features added to Dart in 2.1. At some point in the future, the Dart team plans to disallow using classes as mixins.

  • Move named constructor type arguments from the name to the type.
    For example, given class A<T> { A.from(Object obj) { } }, dartfix changes 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`.
    

Other changes are recommended but not required. These include:

  • Find double literals that end in .0, and remove the .0. Language support for this was added in Dart in 2.1.

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.

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.

0.1.6 #

  • Improve experimental non-nullable migration support.

0.1.5 #

  • Add command line options for selecting/excluding fixes to apply (--fix, --excludeFix, and --required). Call with --help for more details.
  • Add a --color option for printing messages with ANSI colors. This defaults to true if the terminal supports ANSI colors.
  • Add a --pedantic option for specifying fixes relating to the pedantic lints.
  • Add experimental non-nullable migration support.

0.1.4 #

  • update protocol version constraints

0.1.3 #

  • update SDK constraints

0.1.2 #

  • update SDK constraints
  • add example.dart showing what can be "fixed"

0.1.1 #

  • Remove reading dartfix version from pubspec

0.1.0 #

  • Initial version

example/example.dart

// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

// This file contains code that is modified by running dartfix.
// After running dartfix, this content matches a file in the "fixed" directory.

// Dart will automatically convert int literals to doubles.
// Running dartfix converts this double literal to an int
// if --double-to-int is specified on the command line.
const double myDouble = 4.0;

// This class is used as a mixin but does not use the new mixin syntax.
// Running dartfix converts this class to use the new syntax.
class MyMixin {
  final someValue = myDouble;
}

class MyClass with MyMixin {}

main(List<String> args) {
  if (args.length == 0) {
    print('myDouble = ${MyClass().someValue}');
  }
}

Use this package as an executable

1. Install it

You can install the package from the command line:


$ pub global activate dartfix

2. Use it

The package has the following executables:


$ dartfix

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  dartfix: ^0.1.6

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:dartfix/handler/analysis_complete_handler.dart';
import 'package:dartfix/listener/bad_message_listener.dart';
import 'package:dartfix/listener/recording_listener.dart';
import 'package:dartfix/listener/timed_listener.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
22
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
61
Learn more about scoring.

We analyzed this package on Nov 22, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.6.1
  • pana: 0.12.21

Platforms

Detected platforms: Flutter, other

Platform components identified in package: io.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.3.0 <3.0.0
analysis_server_client 1.1.2 1.1.2
args ^1.4.0 1.5.2
cli_util ^0.1.3 0.1.3+2
path ^1.6.0 1.6.4
pub_semver ^1.4.2 1.4.2
Transitive dependencies
collection 1.14.12
Dev dependencies
analyzer ^0.37.0
pedantic ^1.8.0
test ^1.3.0