Enable lint prefer asserts in initializer lists (#12903) * enable lint prefer_asserts_in_initializer_lists * enable --assert-initializer
diff --git a/packages/flutter_tools/lib/src/application_package.dart b/packages/flutter_tools/lib/src/application_package.dart index 7f0e687..ad41013 100644 --- a/packages/flutter_tools/lib/src/application_package.dart +++ b/packages/flutter_tools/lib/src/application_package.dart
@@ -21,9 +21,8 @@ /// Package ID from the Android Manifest or equivalent. final String id; - ApplicationPackage({ @required this.id }) { - assert(id != null); - } + ApplicationPackage({ @required this.id }) + : assert(id != null); String get name; @@ -46,10 +45,9 @@ String id, @required this.apkPath, @required this.launchActivity - }) : super(id: id) { - assert(apkPath != null); - assert(launchActivity != null); - } + }) : assert(apkPath != null), + assert(launchActivity != null), + super(id: id); /// Creates a new AndroidApk from an existing APK. factory AndroidApk.fromApk(String applicationBinary) {
diff --git a/packages/flutter_tools/lib/src/base/build.dart b/packages/flutter_tools/lib/src/base/build.dart index dcb4ad1..0f92167 100644 --- a/packages/flutter_tools/lib/src/base/build.dart +++ b/packages/flutter_tools/lib/src/base/build.dart
@@ -21,9 +21,8 @@ /// A snapshot build configuration. class SnapshotType { - SnapshotType(this.platform, this.mode) { - assert(mode != null); - } + SnapshotType(this.platform, this.mode) + : assert(mode != null); final TargetPlatform platform; final BuildMode mode;
diff --git a/packages/flutter_tools/lib/src/base/flags.dart b/packages/flutter_tools/lib/src/base/flags.dart index 8007266..a6b750f 100644 --- a/packages/flutter_tools/lib/src/base/flags.dart +++ b/packages/flutter_tools/lib/src/base/flags.dart
@@ -17,9 +17,8 @@ /// the Flutter tool (immediately after the arguments have been parsed in /// [FlutterCommandRunner]) and is available via the [flags] global property. class Flags { - Flags(this._globalResults) { - assert(_globalResults != null); - } + Flags(this._globalResults) + : assert(_globalResults != null); final ArgResults _globalResults;
diff --git a/packages/flutter_tools/lib/src/base/logger.dart b/packages/flutter_tools/lib/src/base/logger.dart index 8770efa..053012b 100644 --- a/packages/flutter_tools/lib/src/base/logger.dart +++ b/packages/flutter_tools/lib/src/base/logger.dart
@@ -177,8 +177,8 @@ } class VerboseLogger extends Logger { - VerboseLogger(this.parent) { - assert(terminal != null); + VerboseLogger(this.parent) + : assert(terminal != null) { stopwatch.start(); }
diff --git a/packages/flutter_tools/lib/src/commands/build_apk.dart b/packages/flutter_tools/lib/src/commands/build_apk.dart index 63c757d..2041908 100644 --- a/packages/flutter_tools/lib/src/commands/build_apk.dart +++ b/packages/flutter_tools/lib/src/commands/build_apk.dart
@@ -21,9 +21,7 @@ this.password, this.keyAlias, @required this.keyPassword, - }) { - assert(keystore != null); - } + }) : assert(keystore != null); final String keystore; final String password;
diff --git a/packages/flutter_tools/lib/src/commands/drive.dart b/packages/flutter_tools/lib/src/commands/drive.dart index d0d67ad..fe62bf8 100644 --- a/packages/flutter_tools/lib/src/commands/drive.dart +++ b/packages/flutter_tools/lib/src/commands/drive.dart
@@ -297,7 +297,7 @@ ..add('-rexpanded'); final String dartVmPath = fs.path.join(dartSdkPath, 'bin', 'dart'); final int result = await runCommandAndStreamOutput( - <String>[dartVmPath]..addAll(args), + <String>[dartVmPath]..addAll(dartVmFlags)..addAll(args), environment: <String, String>{ 'VM_SERVICE_URL': observatoryUri } ); if (result != 0)
diff --git a/packages/flutter_tools/lib/src/compile.dart b/packages/flutter_tools/lib/src/compile.dart index 7d4912f..d2b6607 100644 --- a/packages/flutter_tools/lib/src/compile.dart +++ b/packages/flutter_tools/lib/src/compile.dart
@@ -104,8 +104,8 @@ /// The wrapper is intended to stay resident in memory as user changes, reloads, /// restarts the Flutter app. class ResidentCompiler { - ResidentCompiler(this._sdkRoot) { - assert(_sdkRoot != null); + ResidentCompiler(this._sdkRoot) + : assert(_sdkRoot != null) { // This is a URI, not a file path, so the forward slash is correct even on Windows. if (!_sdkRoot.endsWith('/')) _sdkRoot = '$_sdkRoot/';
diff --git a/packages/flutter_tools/lib/src/dart/sdk.dart b/packages/flutter_tools/lib/src/dart/sdk.dart index 64f128d..c8d6fe9 100644 --- a/packages/flutter_tools/lib/src/dart/sdk.dart +++ b/packages/flutter_tools/lib/src/dart/sdk.dart
@@ -11,6 +11,9 @@ return fs.path.join(Cache.flutterRoot, 'bin', 'cache', 'dart-sdk'); } +/// The required Dart language flags +const List<String> dartVmFlags = const <String>['--assert-initializer']; + /// Return the platform specific name for the given Dart SDK binary. So, `pub` /// ==> `pub.bat`. The default SDK location can be overridden with a specified /// [sdkLocation].
diff --git a/packages/flutter_tools/lib/src/flutter_manifest.dart b/packages/flutter_tools/lib/src/flutter_manifest.dart index b1bff4b..c909ee6 100644 --- a/packages/flutter_tools/lib/src/flutter_manifest.dart +++ b/packages/flutter_tools/lib/src/flutter_manifest.dart
@@ -102,11 +102,10 @@ } class Font { - Font(this.familyName, this.fontAssets) { - assert(familyName != null); - assert(fontAssets != null); - assert(fontAssets.isNotEmpty); - } + Font(this.familyName, this.fontAssets) + : assert(familyName != null), + assert(fontAssets != null), + assert(fontAssets.isNotEmpty); final String familyName; final List<FontAsset> fontAssets; @@ -123,9 +122,8 @@ } class FontAsset { - FontAsset(this.asset, {this.weight, this.style}) { - assert(asset != null); - } + FontAsset(this.asset, {this.weight, this.style}) + : assert(asset != null); final String asset; final int weight;
diff --git a/packages/flutter_tools/lib/src/protocol_discovery.dart b/packages/flutter_tools/lib/src/protocol_discovery.dart index 8a8b5cb..1bc35d3 100644 --- a/packages/flutter_tools/lib/src/protocol_discovery.dart +++ b/packages/flutter_tools/lib/src/protocol_discovery.dart
@@ -18,9 +18,9 @@ this.portForwarder, this.hostPort, this.defaultHostPort, - }) : _prefix = '$serviceName listening on ' { - assert(logReader != null); - assert(portForwarder == null || defaultHostPort != null); + }) : assert(logReader != null), + assert(portForwarder == null || defaultHostPort != null), + _prefix = '$serviceName listening on ' { _deviceLogSubscription = logReader.logLines.listen(_handleLine); }
diff --git a/packages/flutter_tools/lib/src/test/flutter_platform.dart b/packages/flutter_tools/lib/src/test/flutter_platform.dart index 21630ea..86f5bf1 100644 --- a/packages/flutter_tools/lib/src/test/flutter_platform.dart +++ b/packages/flutter_tools/lib/src/test/flutter_platform.dart
@@ -88,9 +88,7 @@ this.startPaused, this.explicitObservatoryPort, this.host, - }) { - assert(shellPath != null); - } + }) : assert(shellPath != null); final String shellPath; final TestWatcher watcher;
diff --git a/packages/flutter_tools/test/commands/create_test.dart b/packages/flutter_tools/test/commands/create_test.dart index bf93aa3..9f060c0 100644 --- a/packages/flutter_tools/test/commands/create_test.dart +++ b/packages/flutter_tools/test/commands/create_test.dart
@@ -209,12 +209,12 @@ // TODO(pq): enable when sky_shell is available if (!io.Platform.isWindows) { // Verify that the sample widget test runs cleanly. - final List<String> args = <String>[ - fs.path.absolute(fs.path.join('bin', 'flutter_tools.dart')), - 'test', - '--no-color', - fs.path.join(projectDir.path, 'test', 'widget_test.dart'), - ]; + final List<String> args = <String>[] + ..addAll(dartVmFlags) + ..add(fs.path.absolute(fs.path.join('bin', 'flutter_tools.dart'))) + ..add('test') + ..add('--no-color') + ..add(fs.path.join(projectDir.path, 'test', 'widget_test.dart')); final ProcessResult result = await Process.run( fs.path.join(dartSdkPath, 'bin', 'dart'), @@ -338,7 +338,10 @@ 'flutter_tools.dart', )); - final List<String> args = <String>[flutterToolsPath, 'analyze']; + final List<String> args = <String>[] + ..addAll(dartVmFlags) + ..add(flutterToolsPath) + ..add('analyze'); if (target != null) args.add(target);
diff --git a/packages/flutter_tools/test/commands/test_test.dart b/packages/flutter_tools/test/commands/test_test.dart index 52e3d15..9f24323 100644 --- a/packages/flutter_tools/test/commands/test_test.dart +++ b/packages/flutter_tools/test/commands/test_test.dart
@@ -143,11 +143,13 @@ if (!testFile.existsSync()) fail('missing test file: $testFile'); - final List<String> args = <String>[ - fs.path.absolute(fs.path.join('bin', 'flutter_tools.dart')), - 'test', - '--no-color' - ]..addAll(extraArgs)..add(testFilePath); + final List<String> args = <String>[] + ..addAll(dartVmFlags) + ..add(fs.path.absolute(fs.path.join('bin', 'flutter_tools.dart'))) + ..add('test') + ..add('--no-color') + ..addAll(extraArgs) + ..add(testFilePath); while (_testExclusionLock != null) await _testExclusionLock;