Skip to content

Instantly share code, notes, and snippets.

@GZGavinZhao
Last active October 5, 2021 16:21
Show Gist options
  • Save GZGavinZhao/0eeccc69e3f8309a6bfef050d6c87248 to your computer and use it in GitHub Desktop.
Save GZGavinZhao/0eeccc69e3f8309a6bfef050d6c87248 to your computer and use it in GitHub Desktop.
Detect how many files have been migrated to NNBD in a Dart project.
import 'dart:io';
import 'dart:convert';
import 'package:path/path.dart' as p;
main(List<String> args) async {
print('Counting number of Dart files...');
var count = 0;
await Directory('lib').list(recursive: true).forEach((element) {
if (element is File && p.extension(element.path) == '.dart') {
count++;
}
});
print('Analyzing...');
final analyze = await Process.start('dart', ['analyze', '--format=machine']);
var need_migrate = Set<String>();
await analyze.stdout
.transform(utf8.decoder)
.transform(const LineSplitter())
.forEach((element) {
final output = element.split('|');
if (output[0] == 'ERROR') {
need_migrate.add(output[3]);
}
});
print('${((1 - need_migrate.length / count) * 100).round()}% Done!');
print(
'${need_migrate.length} out of $count files still needs to be migrated!');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment