dart-archive / dart2_fix

A tool to migrate API usage to Dart 2
https://pub.dartlang.org/packages/dart2_fix
BSD 3-Clause "New" or "Revised" License
7 stars 3 forks source link

Detect and update imports. #29

Closed lrhn closed 6 years ago

lrhn commented 6 years ago

If a file contains an import of dart:convert with a show clause, please convert all the matching imported names as well. Include the encode/decode functions.

That is:

import 'dart:convert' show JSON, UTF8;

should be come

import 'dart:convert' show json, jsonEncode, jsonDecode, utf8;

(or as many of the first three as are actually used, it might just be one of them).

devoncarew commented 6 years ago

This will need a full analysis server refactoring to support. This tool can't do that as it; we use the analysis server to locate deprecated references, but then use simple heuristics to modify the source code. In order to do a better job here, we'll need additional metadata on deprecated annotations (https://github.com/dart-lang/sdk/issues/32726), and then we can create real analysis server refactorings.

lrhn commented 6 years ago

Or a small RegExp based script. If you ever insert jsonEncode, jsonDecode or json, remember that. Then if there is a show json in the import for dart:convert (or any import, let's not be stingy, it might be reexported), then replace that by the necessary ones. Ditto for base64.

Otherwise you can get "jsonEncode not declared" errors and/or unused import warnings.

devoncarew commented 6 years ago

You'd end up chasing a long tail of smaller issues. The analysis server has a semantic understanding of the code, and can do a much better job here in terms of leaving behind correct code.

devoncarew commented 6 years ago

I'd like to close this in favor of dart-lang/sdk#32726.