From 0bde67e73475032dfcbe676c6f4b9cd5c9129246 Mon Sep 17 00:00:00 2001 From: Jenn Magder Date: Tue, 23 Mar 2021 10:02:59 -0700 Subject: [PATCH] Migrate flutter_tool tool helper files to null safety (#78845) --- .../flutter_tools/lib/src/android/adb.dart | 2 -- .../lib/src/android/android.dart | 2 -- .../flutter_tools/lib/src/base/template.dart | 2 -- .../lib/src/base/user_messages.dart | 4 +--- .../lib/src/build_system/hash.dart | 4 +--- .../lib/src/isolated/mustache_template.dart | 2 -- .../src/localizations/gen_l10n_templates.dart | 2 -- .../language_subtag_registry.dart | 2 -- .../lib/src/test/test_device.dart | 2 -- .../flutter_tools/lib/src/test/watcher.dart | 2 -- .../flutter_tools/lib/src/web/bootstrap.dart | 21 ++++++++----------- .../flutter_tools/tool/daemon_client.dart | 6 ++---- packages/flutter_tools/tool/global_count.dart | 4 +--- .../flutter_tools/tool/unit_coverage.dart | 10 ++++----- 14 files changed, 18 insertions(+), 47 deletions(-) diff --git a/packages/flutter_tools/lib/src/android/adb.dart b/packages/flutter_tools/lib/src/android/adb.dart index c74838f747..a500a1b3ee 100644 --- a/packages/flutter_tools/lib/src/android/adb.dart +++ b/packages/flutter_tools/lib/src/android/adb.dart @@ -2,8 +2,6 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// @dart = 2.8 - final RegExp _whitespace = RegExp(r'\s+'); /// Convert adb device names into more human readable descriptions. diff --git a/packages/flutter_tools/lib/src/android/android.dart b/packages/flutter_tools/lib/src/android/android.dart index 26a35b7ac3..6ecd6b6938 100644 --- a/packages/flutter_tools/lib/src/android/android.dart +++ b/packages/flutter_tools/lib/src/android/android.dart @@ -2,8 +2,6 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// @dart = 2.8 - const int minApiLevel = 16; const String minVersionName = 'Jelly Bean'; const String minVersionText = '4.1.x'; diff --git a/packages/flutter_tools/lib/src/base/template.dart b/packages/flutter_tools/lib/src/base/template.dart index 44462693b9..5072e6de5f 100644 --- a/packages/flutter_tools/lib/src/base/template.dart +++ b/packages/flutter_tools/lib/src/base/template.dart @@ -2,8 +2,6 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// @dart = 2.8 - /// An indirection around our mustache templating system to avoid a /// dependency on mustache.. abstract class TemplateRenderer { diff --git a/packages/flutter_tools/lib/src/base/user_messages.dart b/packages/flutter_tools/lib/src/base/user_messages.dart index 568151ec98..95b325e5bd 100644 --- a/packages/flutter_tools/lib/src/base/user_messages.dart +++ b/packages/flutter_tools/lib/src/base/user_messages.dart @@ -2,8 +2,6 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// @dart = 2.8 - import 'context.dart'; import 'platform.dart'; @@ -16,7 +14,7 @@ class UserMessages { 'Please report a bug at https://github.com/flutter/flutter/issues.'; // Messages used in FlutterValidator - String flutterStatusInfo(String channel, String version, String os, String locale) => + String flutterStatusInfo(String? channel, String? version, String os, String locale) => 'Channel ${channel ?? 'unknown'}, ${version ?? 'Unknown'}, on $os, locale $locale'; String flutterVersion(String version, String flutterRoot) => 'Flutter version $version at $flutterRoot'; diff --git a/packages/flutter_tools/lib/src/build_system/hash.dart b/packages/flutter_tools/lib/src/build_system/hash.dart index 3e5ac4011d..3f83633124 100644 --- a/packages/flutter_tools/lib/src/build_system/hash.dart +++ b/packages/flutter_tools/lib/src/build_system/hash.dart @@ -2,8 +2,6 @@ // 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:typed_data'; /// Data from a non-linear mathematical function that functions as @@ -51,7 +49,7 @@ class Md5Hash { int _remainingLength = 0; int _contentLength = 0; - void addChunk(Uint8List data, [int stop]) { + void addChunk(Uint8List data, [int? stop]) { assert(_remainingLength == 0); stop ??= data.length; int i = 0; diff --git a/packages/flutter_tools/lib/src/isolated/mustache_template.dart b/packages/flutter_tools/lib/src/isolated/mustache_template.dart index be02adfe71..8e21ec7efd 100644 --- a/packages/flutter_tools/lib/src/isolated/mustache_template.dart +++ b/packages/flutter_tools/lib/src/isolated/mustache_template.dart @@ -2,8 +2,6 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// @dart = 2.8 - import 'package:mustache_template/mustache_template.dart'; import '../base/template.dart'; diff --git a/packages/flutter_tools/lib/src/localizations/gen_l10n_templates.dart b/packages/flutter_tools/lib/src/localizations/gen_l10n_templates.dart index e3c8348139..5169ef912d 100644 --- a/packages/flutter_tools/lib/src/localizations/gen_l10n_templates.dart +++ b/packages/flutter_tools/lib/src/localizations/gen_l10n_templates.dart @@ -2,8 +2,6 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// @dart = 2.8 - const String emptyPubspecTemplate = ''' # Generated by the flutter tool name: synthetic_package diff --git a/packages/flutter_tools/lib/src/localizations/language_subtag_registry.dart b/packages/flutter_tools/lib/src/localizations/language_subtag_registry.dart index b7bc68fa95..6372d6dfca 100644 --- a/packages/flutter_tools/lib/src/localizations/language_subtag_registry.dart +++ b/packages/flutter_tools/lib/src/localizations/language_subtag_registry.dart @@ -2,8 +2,6 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// @dart = 2.8 - /// Cache of https://www.iana.org/assignments/language-subtag-registry/language-subtag-registry. const String languageSubtagRegistry = ''' File-Date: 2020-03-16 diff --git a/packages/flutter_tools/lib/src/test/test_device.dart b/packages/flutter_tools/lib/src/test/test_device.dart index ef1b1e1e10..e1106794ac 100644 --- a/packages/flutter_tools/lib/src/test/test_device.dart +++ b/packages/flutter_tools/lib/src/test/test_device.dart @@ -2,8 +2,6 @@ // 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:async'; import 'package:meta/meta.dart'; diff --git a/packages/flutter_tools/lib/src/test/watcher.dart b/packages/flutter_tools/lib/src/test/watcher.dart index ec505c2888..17455d1470 100644 --- a/packages/flutter_tools/lib/src/test/watcher.dart +++ b/packages/flutter_tools/lib/src/test/watcher.dart @@ -2,8 +2,6 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// @dart = 2.8 - import 'test_device.dart'; /// Callbacks for reporting progress while running tests. diff --git a/packages/flutter_tools/lib/src/web/bootstrap.dart b/packages/flutter_tools/lib/src/web/bootstrap.dart index 8909f2cc46..ce922010dc 100644 --- a/packages/flutter_tools/lib/src/web/bootstrap.dart +++ b/packages/flutter_tools/lib/src/web/bootstrap.dart @@ -2,9 +2,6 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// @dart = 2.8 - -import 'package:meta/meta.dart'; import 'package:package_config/package_config.dart'; /// The JavaScript bootstrap script to support in-browser hot restart. @@ -17,8 +14,8 @@ import 'package:package_config/package_config.dart'; /// and is responsible for bootstrapping the RequireJS modules and attaching /// the hot reload hooks. String generateBootstrapScript({ - @required String requireUrl, - @required String mapperUrl, + required String requireUrl, + required String mapperUrl, }) { return ''' "use strict"; @@ -54,9 +51,9 @@ document.head.appendChild(requireEl); /// `foo__bar__baz`. Rather than attempt to guess, we assume the first property of /// this object is the module. String generateMainModule({ - @required String entrypoint, - @required bool nullAssertions, - @required bool nativeNullAssertions, + required String entrypoint, + required bool nullAssertions, + required bool nativeNullAssertions, String bootstrapModule = 'main_module.bootstrap', }) { // TODO(jonahwilliams): fix typo in dwds and update. @@ -102,10 +99,10 @@ define("$bootstrapModule", ["$entrypoint", "dart_sdk"], function(app, dart_sdk) /// /// This hard-codes the device pixel ratio to 3.0 and a 2400 x 1800 window size. String generateTestEntrypoint({ - @required String relativeTestPath, - @required String absolutePath, - @required String testConfigPath, - @required LanguageVersion languageVersion, + required String relativeTestPath, + required String absolutePath, + required String testConfigPath, + required LanguageVersion languageVersion, }) { return ''' // @dart = ${languageVersion.major}.${languageVersion.minor} diff --git a/packages/flutter_tools/tool/daemon_client.dart b/packages/flutter_tools/tool/daemon_client.dart index 07f3fb0166..c4033ae88b 100644 --- a/packages/flutter_tools/tool/daemon_client.dart +++ b/packages/flutter_tools/tool/daemon_client.dart @@ -2,14 +2,12 @@ // 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:convert'; import 'dart:io'; import 'package:flutter_tools/src/base/common.dart'; -Process daemon; +late Process daemon; // To use, start from the console and enter: // version: print version @@ -85,7 +83,7 @@ Future main() async { }); // Print in the callback can't fail. - unawaited(daemon.exitCode.then((int code) { + unawaited(daemon.exitCode.then((int code) { print('daemon exiting ($code)'); exit(code); })); diff --git a/packages/flutter_tools/tool/global_count.dart b/packages/flutter_tools/tool/global_count.dart index cab9c59389..2f6bc7e6ee 100644 --- a/packages/flutter_tools/tool/global_count.dart +++ b/packages/flutter_tools/tool/global_count.dart @@ -2,8 +2,6 @@ // 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; @@ -27,7 +25,7 @@ int countGlobalImports(Directory directory) { if (!file.path.endsWith('.dart') || file is! File) { continue; } - final bool hasImport = (file as File).readAsLinesSync().any((String line) { + final bool hasImport = file.readAsLinesSync().any((String line) { return globalImport.hasMatch(line); }); if (hasImport) { diff --git a/packages/flutter_tools/tool/unit_coverage.dart b/packages/flutter_tools/tool/unit_coverage.dart index 0b26d4a340..bbb822c13c 100644 --- a/packages/flutter_tools/tool/unit_coverage.dart +++ b/packages/flutter_tools/tool/unit_coverage.dart @@ -2,8 +2,6 @@ // 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'; /// Produces a per-library coverage summary when fed an lcov file, sorted by @@ -17,7 +15,7 @@ void main(List args) { } final List lines = File(args.single).readAsLinesSync(); final List coverages = []; - Coverage currentCoverage; + Coverage? currentCoverage; for (final String line in lines) { if (line.startsWith('SF:')) { @@ -26,9 +24,9 @@ void main(List args) { coverages.add(currentCoverage); } if (line.startsWith('DA')) { - currentCoverage.totalLines += 1; + currentCoverage?.totalLines += 1; if (!line.endsWith(',0')) { - currentCoverage.testedLines += 1; + currentCoverage?.testedLines += 1; } } if (line == 'end_of_record') { @@ -53,7 +51,7 @@ void main(List args) { } class Coverage { - String library; + String? library; int totalLines = 0; int testedLines = 0; }