migrate 3 leaf files to null-safety (#3168)
diff --git a/lib/src/package_config.dart b/lib/src/package_config.dart
index fad20f7..0493dcc 100644
--- a/lib/src/package_config.dart
+++ b/lib/src/package_config.dart
@@ -2,10 +2,6 @@
// for details. 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.10
-
-import 'package:meta/meta.dart';
-
import 'package:pub_semver/pub_semver.dart';
import 'language_version.dart';
@@ -22,38 +18,36 @@
/// Date-time the `.dart_tool/package_config.json` file was generated.
///
- /// This property is **optional** and may be `null` if not given.
- DateTime generated;
+ /// `null` if not given.
+ DateTime? generated;
/// Tool that generated the `.dart_tool/package_config.json` file.
///
/// For `pub` this is always `'pub'`.
///
- /// This property is **optional** and may be `null` if not given.
- String generator;
+ /// `null` if not given.
+ String? generator;
/// Version of the tool that generated the `.dart_tool/package_config.json`
/// file.
///
/// For `pub` this is the Dart SDK version from which `pub get` was called.
///
- /// This property is **optional** and may be `null` if not given.
- Version generatorVersion;
+ /// `null` if not given.
+ Version? generatorVersion;
/// Additional properties not in the specification for the
/// `.dart_tool/package_config.json` file.
Map<String, dynamic> additionalProperties;
PackageConfig({
- @required this.configVersion,
- @required this.packages,
+ required this.configVersion,
+ required this.packages,
this.generated,
this.generator,
this.generatorVersion,
- this.additionalProperties,
- }) {
- additionalProperties ??= {};
- }
+ Map<String, dynamic>? additionalProperties,
+ }) : additionalProperties = additionalProperties ?? {};
/// Create [PackageConfig] from JSON [data].
///
@@ -63,7 +57,7 @@
if (data is! Map<String, dynamic>) {
throw FormatException('package_config.json must be a JSON object');
}
- final root = data as Map<String, dynamic>;
+ final root = data;
void _throw(String property, String mustBe) => throw FormatException(
'"$property" in .dart_tool/package_config.json $mustBe');
@@ -87,7 +81,7 @@
}
// Read the 'generated' property
- DateTime generated;
+ DateTime? generated;
final generatedRaw = root['generated'];
if (generatedRaw != null) {
if (generatedRaw is! String) {
@@ -104,7 +98,7 @@
}
// Read the 'generatorVersion' property
- Version generatorVersion;
+ Version? generatorVersion;
final generatorVersionRaw = root['generatorVersion'];
if (generatorVersionRaw != null) {
if (generatorVersionRaw is! String) {
@@ -134,13 +128,13 @@
}
/// Convert to JSON structure.
- Map<String, Object> toJson() => {
+ Map<String, Object?> toJson() => {
'configVersion': configVersion,
'packages': packages.map((p) => p.toJson()).toList(),
- 'generated': generated?.toUtc()?.toIso8601String(),
+ 'generated': generated?.toUtc().toIso8601String(),
'generator': generator,
'generatorVersion': generatorVersion?.toString(),
- }..addAll(additionalProperties ?? {});
+ }..addAll(additionalProperties);
}
class PackageConfigEntry {
@@ -158,8 +152,8 @@
/// Import statements in Dart programs are resolved relative to this folder.
/// This must be in the sub-tree under [rootUri].
///
- /// This property is **optional** and may be `null` if not given.
- Uri packageUri;
+ /// `null` if not given.
+ Uri? packageUri;
/// Language version used by package.
///
@@ -167,16 +161,16 @@
/// comment. This is derived from the lower-bound on the Dart SDK requirement
/// in the `pubspec.yaml` for the given package.
///
- /// This property is **optional** and may be `null` if not given.
- LanguageVersion languageVersion;
+ /// `null` if not given.
+ LanguageVersion? languageVersion;
/// Additional properties not in the specification for the
/// `.dart_tool/package_config.json` file.
- Map<String, dynamic> additionalProperties;
+ Map<String, dynamic>? additionalProperties;
PackageConfigEntry({
- @required this.name,
- @required this.rootUri,
+ required this.name,
+ required this.rootUri,
this.packageUri,
this.languageVersion,
this.additionalProperties,
@@ -193,9 +187,9 @@
throw FormatException(
'packages[] entries in package_config.json must be JSON objects');
}
- final root = data as Map<String, dynamic>;
+ final root = data;
- void _throw(String property, String mustBe) => throw FormatException(
+ Never _throw(String property, String mustBe) => throw FormatException(
'"packages[].$property" in .dart_tool/package_config.json $mustBe');
final name = root['name'];
@@ -203,7 +197,7 @@
_throw('name', 'must be a string');
}
- Uri rootUri;
+ final Uri rootUri;
final rootUriRaw = root['rootUri'];
if (rootUriRaw is! String) {
_throw('rootUri', 'must be a string');
@@ -214,7 +208,7 @@
_throw('rootUri', 'must be a URI');
}
- Uri packageUri;
+ Uri? packageUri;
var packageUriRaw = root['packageUri'];
if (packageUriRaw != null) {
if (packageUriRaw is! String) {
@@ -230,7 +224,7 @@
}
}
- LanguageVersion languageVersion;
+ LanguageVersion? languageVersion;
final languageVersionRaw = root['languageVersion'];
if (languageVersionRaw != null) {
if (languageVersionRaw is! String) {
@@ -252,7 +246,7 @@
}
/// Convert to JSON structure.
- Map<String, Object> toJson() => {
+ Map<String, Object?> toJson() => {
'name': name,
'rootUri': rootUri.toString(),
if (packageUri != null) 'packageUri': packageUri?.toString(),
diff --git a/lib/src/rate_limited_scheduler.dart b/lib/src/rate_limited_scheduler.dart
index 6e62310..daeb76f 100644
--- a/lib/src/rate_limited_scheduler.dart
+++ b/lib/src/rate_limited_scheduler.dart
@@ -2,12 +2,9 @@
// for details. 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.10
-
import 'dart:async';
import 'dart:collection';
-import 'package:meta/meta.dart';
import 'package:pedantic/pedantic.dart';
import 'package:pool/pool.dart';
@@ -65,7 +62,7 @@
final Set<J> _started = {};
RateLimitedScheduler(Future<V> Function(J) runJob,
- {@required int maxConcurrentOperations})
+ {required int maxConcurrentOperations})
: _runJob = runJob,
_pool = Pool(maxConcurrentOperations);
@@ -77,7 +74,7 @@
return;
}
final task = _queue.removeFirst();
- final completer = _cache[task.jobId];
+ final completer = _cache[task.jobId]!;
if (!_started.add(task.jobId)) {
return;
@@ -140,7 +137,7 @@
/// Returns the result of running [jobId] if that is already done.
/// Otherwise returns `null`.
- V peek(J jobId) => _results[jobId];
+ V? peek(J jobId) => _results[jobId];
}
class _Task<J> {
diff --git a/tool/test.dart b/tool/test.dart
index 2f4769d..e7877a2 100755
--- a/tool/test.dart
+++ b/tool/test.dart
@@ -3,8 +3,6 @@
// for details. 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.10
-
/// Test wrapper script.
/// Many of the integration tests runs the `pub` command, this is slow if every
/// invocation requires the dart compiler to load all the sources. This script
@@ -19,7 +17,7 @@
import 'package:pub/src/exceptions.dart';
Future<void> main(List<String> args) async {
- Process testProcess;
+ Process? testProcess;
final sub = ProcessSignal.sigint.watch().listen((signal) {
testProcess?.kill(signal);
});