Ban sync*/async* from user facing code (#95050)

This commit is contained in:
Dan Field
2021-12-12 13:05:03 -08:00
committed by GitHub
parent 895beb04bb
commit ab0a335973
55 changed files with 656 additions and 580 deletions

View File

@@ -740,26 +740,22 @@ class PubspecYaml {
}
/// This returns all the explicit dependencies that this pubspec.yaml lists under dependencies.
Iterable<PubspecDependency> get dependencies sync* {
Iterable<PubspecDependency> get dependencies {
// It works by iterating over the parsed data from _parse above, collecting
// all the dependencies that were found, ignoring any that are flagged as as
// overridden by subsequent entries in the same file and any that have the
// magic comment flagging them as auto-generated transitive dependencies
// that we added in a previous run.
for (final PubspecLine data in inputData) {
if (data is PubspecDependency && data.kind != DependencyKind.overridden && !data.isTransitive && !data.isDevDependency) {
yield data;
}
}
return inputData
.whereType<PubspecDependency>()
.where((PubspecDependency data) => data.kind != DependencyKind.overridden && !data.isTransitive && !data.isDevDependency);
}
/// This returns all regular dependencies and all dev dependencies.
Iterable<PubspecDependency> get allDependencies sync* {
for (final PubspecLine data in inputData) {
if (data is PubspecDependency && data.kind != DependencyKind.overridden && !data.isTransitive) {
yield data;
}
}
Iterable<PubspecDependency> get allDependencies {
return inputData
.whereType<PubspecDependency>()
.where((PubspecDependency data) => data.kind != DependencyKind.overridden && !data.isTransitive);
}
/// Take a dependency graph with explicit version numbers, and apply them to
@@ -1412,23 +1408,26 @@ class PubDependencyTree {
String package, {
@required Set<String> seen,
@required Set<String> exclude,
}) sync* {
List<String>/*?*/ result,
}) {
assert(seen != null);
assert(exclude != null);
result ??= <String>[];
if (!_dependencyTree.containsKey(package)) {
// We have no transitive dependencies extracted for flutter_sdk packages
// because they were omitted from pubspec.yaml used for 'pub upgrade' run.
return;
return result;
}
for (final String dependency in _dependencyTree[package]) {
if (!seen.contains(dependency)) {
if (!exclude.contains(dependency)) {
yield dependency;
result.add(dependency);
}
seen.add(dependency);
yield* getTransitiveDependenciesFor(dependency, seen: seen, exclude: exclude);
getTransitiveDependenciesFor(dependency, seen: seen, exclude: exclude, result: result);
}
}
return result;
}
/// The version that a particular package ended up with.

View File

@@ -635,9 +635,9 @@ abstract class Device {
@override
String toString() => name;
static Stream<String> descriptions(List<Device> devices) async* {
static Future<List<String>> descriptions(List<Device> devices) async {
if (devices.isEmpty) {
return;
return const <String>[];
}
// Extract device information
@@ -665,13 +665,14 @@ abstract class Device {
}
// Join columns into lines of text
for (final List<String> row in table) {
yield indices.map<String>((int i) => row[i].padRight(widths[i])).followedBy(<String>[row.last]).join(' • ');
}
return <String>[
for (final List<String> row in table)
indices.map<String>((int i) => row[i].padRight(widths[i])).followedBy(<String>[row.last]).join(' • '),
];
}
static Future<void> printDevices(List<Device> devices, Logger logger) async {
await descriptions(devices).forEach(logger.printStatus);
(await descriptions(devices)).forEach(logger.printStatus);
}
static List<String> devicesPlatformTypes(List<Device> devices) {

View File

@@ -520,7 +520,7 @@ class DeviceValidator extends DoctorValidator {
final List<Device> devices = await _deviceManager.getAllConnectedDevices();
List<ValidationMessage> installedMessages = <ValidationMessage>[];
if (devices.isNotEmpty) {
installedMessages = await Device.descriptions(devices)
installedMessages = (await Device.descriptions(devices))
.map<ValidationMessage>((String msg) => ValidationMessage(msg)).toList();
}

View File

@@ -1372,7 +1372,7 @@ abstract class FlutterCommand extends Command<void> {
final StringBuffer result = StringBuffer();
result.writeln(userMessages.flutterFoundButUnsupportedDevices);
result.writeAll(
await Device.descriptions(unsupportedDevices)
(await Device.descriptions(unsupportedDevices))
.map((String desc) => desc)
.toList(),
'\n',