dart2_fix 1.0.6

  • Readme
  • Changelog
  • Installing
  • 26

Build Status

A tool to migrate API usage to Dart 2.

What does it do? #

dart2_fix is a command line utility that can automatically migrate some Dart 1 API usages in your source code to Dart 2 ones. Currently, it focuses on updating deprecated constant names; for example:

  • update dart:convert's UTF8 to utf8
  • update dart:core's Duration.ZERO to Duration.zero
  • update dart:math's PI to pi

For more information about preparing your code for Dart 2, please see the Dart 2 migration guide.

How do I use it? #

To install, run pub global activate dart2_fix. Then, from your project directory, run:

pub global run dart2_fix

When run without any arguments, it will check your project, but will not make changes; it'll indicate what would be changed if asked to make modifications. For example:

  line 56 • Duration.ZERO => Duration.zero
  line 60 • Duration.ZERO => Duration.zero
  line 86 • Duration.ZERO => Duration.zero

  line 169 • JSON => json
  line 173 • JSON => json

Found 5 fixes in 2.3s.

To apply these fixes, run again using the --apply argument.

To actually modify your project source code, run with the --apply argument (pub global run dart2_fix --apply):

Updating test...

  3 fixes applied for Duration.ZERO => Duration.zero

  2 fixes applied for JSON => json

Applied 5 fixes in 1.9s.

What about Flutter code? #

To run this tool on Flutter code, use:

flutter packages pub global activate dart2_fix

then - to check your code - run:

flutter packages pub global run dart2_fix

and to apply fixes, run:

flutter packages pub global run dart2_fix --apply

Will this make all of my code Dart 2 compliant? #

No. Currently this only fixes the renaming of various deprecated constant names. Some of the less uniform constant renamings are not handled by this tool. For example Endianness.BIG_ENDIAN has been renamed to Endian.big but this will not be caught. After running this tool, remaining issues can be found by running the dart analyzer (or flutter analyze) and fixing any deprecation warnings.

I'm getting new static (or runtime errors) after running dart2_fix, what went wrong? #

This tool can't catch conflicts between the new constant names and any fields or local variables that you might have in scope. If you get new analysis warnings or runtime failures after running this tool, check to see whether one of the changes made has caused a naming conflict with something else in scope. The most common cause of this is having a local variable named json in a scope where JSON.decode gets renamed to json.decode. To help with fixing these kinds of conflicts, the following top level members have been added to dart:convert: jsonDecode, jsonEncode, base64Decode, base64Encode, and base64UrlEncode. These top level members are equivalent to json.decode, json.decode, etc, and can be used to avoid naming conflicts where required.

Features and bugs #

Please file feature requests and bugs at the issue tracker.

1.0.6 #

  • Upgraded dependencies for Dart 2.

1.0.5 #

  • Support more constants related to HTTP.

1.0.4 #

  • Add support for removing @proxy annotations.
  • Convert JSON.encode references to jsonEncode (and similarly for jsonDecode, base64Encode, and base64Decode).

1.0.3 #

  • Add support for deprecated dart:io constants.

1.0.2 #

  • Add a dart2_fix pub run entry-point.
  • Updates to the latest version of packages.
  • Added an --check-package=<package name> option.

1.0.1 #

  • Made the tool work under Dart 2 runtime semantics.
  • Updated when we print timing info for the tool.
  • Added an SDK lower bound of 2.0.0-dev.36.0.
  • Added a --verbose flag.

1.0.0+2 #

  • Fix an issue converting DateTime.AUGUST.

1.0.0+1 #

  • Fix an issue converting double.INFINITY.

1.0.0 #

  • Initial version.

Use this package as an executable

1. Install it

You can install the package from the command line:

$ pub global activate dart2_fix

2. Use it

The package has the following executables:

$ dart2_fix
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

We analyzed this package on Jan 27, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.1
  • pana: 0.13.4

Health suggestions

Fix lib/src/dart_fix.dart. (-9.54 points)

Analysis of lib/src/dart_fix.dart reported 20 hints, including:

line 17 col 26: Unnecessary new keyword.

line 20 col 25: Unnecessary new keyword.

line 51 col 12: Unnecessary new keyword.

line 56 col 33: Unnecessary new keyword.

line 60 col 14: Unnecessary new keyword.

Fix lib/src/deprecation_analysis_server.dart. (-5.84 points)

Analysis of lib/src/deprecation_analysis_server.dart reported 12 hints, including:

line 25 col 27: Unnecessary new keyword.

line 26 col 5: Future results in async function bodies must be awaited or marked unawaited using package:pedantic.

line 32 col 51: Unnecessary new keyword.

line 34 col 10: The value of the local variable 'hadServerError' isn't used.

line 40 col 13: Unnecessary new keyword.

Fix lib/src/deprecation_analyzer.dart. (-2.48 points)

Analysis of lib/src/deprecation_analyzer.dart reported 5 hints:

line 21 col 3: Prefer using /// for doc comments.

line 33 col 9: Unnecessary new keyword.

line 35 col 17: 'locateContexts' is deprecated and shouldn't be used.

line 37 col 34: Unnecessary new keyword.

line 73 col 10: Unnecessary new keyword.

Fix lib/src/changes.dart. (-1.99 points)

Analysis of lib/src/changes.dart reported 4 hints:

line 358 col 12: Unnecessary new keyword.

line 367 col 12: Unnecessary new keyword.

line 372 col 11: Unnecessary new keyword.

line 438 col 12: Unnecessary new keyword.

Fix lib/src/model.dart. (-0.50 points)

Analysis of lib/src/model.dart reported 1 hint:

line 57 col 32: Unnecessary new keyword.

Maintenance issues and suggestions

Support latest dependencies. (-20 points)

The version constraint in pubspec.yaml does not support the latest published versions for 2 dependencies (analyzer, intl).

Package is getting outdated. (-51.78 points)

The package was last published 79 weeks ago.

The package description is too short. (-20 points)

Add more detail to the description field of pubspec.yaml. Use 60 to 180 characters to describe the package, what it does, and its target use case.


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev.17.0 <3.0.0
analysis_server_lib ^0.1.4 0.1.9
analyzer ^0.32.0 0.32.6 0.39.4
args ^1.4.0 1.5.2
cli_util ^0.1.2 0.1.3+2
intl ^0.15.0 0.15.8 0.16.1
path ^1.5.0 1.6.4
Transitive dependencies
async 2.4.0
charcode 1.1.2
collection 1.14.12
convert 2.1.1
crypto 2.1.4
csslib 0.16.1
front_end 0.1.4+2 0.1.29
glob 1.2.0
html 0.14.0+3
js 0.6.1+1
kernel 0.3.4+2 0.3.29
logging 0.11.4
meta 1.1.8
node_interop 1.0.3
node_io 1.0.1+2
package_config 1.1.0 2.0.0
pedantic 1.9.0
plugin 0.2.0+3
source_span 1.6.0
string_scanner 1.0.5
term_glyph 1.1.0
typed_data 1.1.6
watcher 0.9.7+13
yaml 2.2.0
Dev dependencies
test ^1.0.0