flutter/packages/flutter_tools/tool/global_count.dart
Jonah Williams 74bd7b6f6d
[flutter_tools] opt all flutter tool libraries and tests out of null safety. (#74832)
* opt out the flutter tool

* oops EOF

* fix import

* Update tool_backend.dart

* Update daemon_client.dart

* fix more
2021-01-27 15:17:53 -08:00

39 lines
1.3 KiB
Dart

// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
import 'dart:io';
import 'package:path/path.dart' as path;
/// Count the number of libraries that import globals.dart in lib and test.
///
/// This must be run from the flutter_tools project root directory.
void main() {
final Directory sources = Directory(path.join(Directory.current.path, 'lib'));
final Directory tests = Directory(path.join(Directory.current.path, 'test'));
final int sourceGlobals = countGlobalImports(sources);
final int testGlobals = countGlobalImports(tests);
print('lib/ contains $sourceGlobals libraries with global usage');
print('test/ contains $testGlobals libraries with global usage');
}
final RegExp globalImport = RegExp('import.*globals.dart\' as globals;');
int countGlobalImports(Directory directory) {
int count = 0;
for (final FileSystemEntity file in directory.listSync(recursive: true)) {
if (!file.path.endsWith('.dart') || file is! File) {
continue;
}
final bool hasImport = (file as File).readAsLinesSync().any((String line) {
return globalImport.hasMatch(line);
});
if (hasImport) {
count += 1;
}
}
return count;
}