Auto-format Framework (#160545)

This auto-formats all *.dart files in the repository outside of the
`engine` subdirectory and enforces that these files stay formatted with
a presubmit check.

**Reviewers:** Please carefully review all the commits except for the
one titled "formatted". The "formatted" commit was auto-generated by
running `dev/tools/format.sh -a -f`. The other commits were hand-crafted
to prepare the repo for the formatting change. I recommend reviewing the
commits one-by-one via the "Commits" tab and avoiding Github's "Files
changed" tab as it will likely slow down your browser because of the
size of this PR.

---------

Co-authored-by: Kate Lovett <katelovett@google.com>
Co-authored-by: LongCatIsLooong <31859944+LongCatIsLooong@users.noreply.github.com>
This commit is contained in:
Michael Goderbauer
2024-12-19 12:06:21 -08:00
committed by GitHub
parent 8e0993eda8
commit 5491c8c146
4411 changed files with 455108 additions and 415991 deletions

View File

@@ -29,10 +29,10 @@ class Adb {
}) async {
target ??= const AndroidDeviceTarget.onlyEmulatorOrDevice();
final String tool = adbPath ?? 'adb';
final Adb adb = Adb._(
<String>[tool, ...target._toAdbArgs()],
processManager ?? const LocalProcessManager(),
);
final Adb adb = Adb._(<String>[
tool,
...target._toAdbArgs(),
], processManager ?? const LocalProcessManager());
final (bool connected, String? error) = await adb.isDeviceConnected();
if (!connected) {
throw StateError('No device connected: $error');
@@ -41,12 +41,7 @@ class Adb {
}
Future<AdbStringResult> _runString(List<String> args) async {
final io.ProcessResult result = await _process.run(
<String>[
..._prefixArgs,
...args,
],
);
final io.ProcessResult result = await _process.run(<String>[..._prefixArgs, ...args]);
return AdbStringResult(
result.stdout as String,
exitCode: result.exitCode,
@@ -55,13 +50,10 @@ class Adb {
}
Future<AdbBinaryResult> _runBinary(List<String> args) async {
final io.ProcessResult result = await _process.run(
<String>[
..._prefixArgs,
...args,
],
stdoutEncoding: null,
);
final io.ProcessResult result = await _process.run(<String>[
..._prefixArgs,
...args,
], stdoutEncoding: null);
return AdbBinaryResult(
result.stdout as Uint8List,
exitCode: result.exitCode,
@@ -78,11 +70,7 @@ class Adb {
/// and an error message if the device is not connected. If the device is
/// connected, the error message is `null`.
Future<(bool connected, String? error)> isDeviceConnected() async {
final AdbStringResult result = await _runString(<String>[
'shell',
'echo',
'connected',
]);
final AdbStringResult result = await _runString(<String>['shell', 'echo', 'connected']);
if (result.exitCode != 0) {
return (false, result.stderr);
} else {
@@ -92,11 +80,7 @@ class Adb {
/// Takes a screenshot of the device.
Future<Uint8List> screencap() async {
final AdbBinaryResult result = await _runBinary(<String>[
'exec-out',
'screencap',
'-p',
]);
final AdbBinaryResult result = await _runBinary(<String>['exec-out', 'screencap', '-p']);
if (result.exitCode != 0) {
throw StateError('Failed to take screenshot: ${result.stderr}');
}
@@ -105,13 +89,7 @@ class Adb {
/// Taps on the screen at the given [x] and [y] coordinates.
Future<void> tap(int x, int y) async {
final AdbStringResult result = await _runString(<String>[
'shell',
'input',
'tap',
'$x',
'$y',
]);
final AdbStringResult result = await _runString(<String>['shell', 'input', 'tap', '$x', '$y']);
if (result.exitCode != 0) {
throw StateError('Failed to tap at $x, $y: ${result.stderr}');
}
@@ -145,10 +123,7 @@ class Adb {
}
/// Resume a backgrounded app (i.e. after [sendToHome]).
Future<void> resumeApp({
required String appName,
String activityName = '.MainActivity',
}) async {
Future<void> resumeApp({required String appName, String activityName = '.MainActivity'}) async {
final AdbStringResult result = await _runString(<String>[
'shell',
'am',
@@ -172,9 +147,7 @@ class Adb {
'confirmed',
]);
if (result.exitCode != 0) {
throw StateError(
'Failed to disable immersive mode confirmations: ${result.stderr}',
);
throw StateError('Failed to disable immersive mode confirmations: ${result.stderr}');
}
}
@@ -250,9 +223,7 @@ sealed class AndroidDeviceTarget {
/// ```dart
/// const AndroidDeviceTarget target = AndroidDeviceTarget.bySerial('emulator-5554');
/// ```
const factory AndroidDeviceTarget.bySerial(
String serialNumber,
) = _SerialDeviceTarget;
const factory AndroidDeviceTarget.bySerial(String serialNumber) = _SerialDeviceTarget;
/// Represents the only running emulator _or_ connected device.
///
@@ -314,5 +285,5 @@ enum AdbUserRotation {
reversePortrait,
/// Reverse landscape orientation, i.e., landscape upside down.
reverseLandscape;
reverseLandscape,
}

View File

@@ -44,10 +44,7 @@ final class AndroidNativeDriver implements NativeDriver {
String? adbPath,
io.Directory? tempDirectory,
}) async {
final Adb adb = await Adb.create(
adbPath: adbPath,
target: target,
);
final Adb adb = await Adb.create(adbPath: adbPath, target: target);
tempDirectory ??= io.Directory.systemTemp.createTempSync('native_driver.');
final AndroidNativeDriver nativeDriver = AndroidNativeDriver.forTesting(
adb: adb,

View File

@@ -19,19 +19,13 @@ final class NativeCommand extends Command {
}
/// Requests that the device be rotated to landscape mode.
static const NativeCommand rotateLandscape = NativeCommand(
'rotate_landscape',
);
static const NativeCommand rotateLandscape = NativeCommand('rotate_landscape');
/// Requests that the device reset its rotation to the default orientation.
static const NativeCommand rotateDefault = NativeCommand(
'rotate_default',
);
static const NativeCommand rotateDefault = NativeCommand('rotate_default');
/// Pings the device to ensure it is responsive.
static const NativeCommand ping = NativeCommand(
'ping',
);
static const NativeCommand ping = NativeCommand('ping');
/// The method to call on the plugin.
final String method;
@@ -88,10 +82,7 @@ final class ByNativeAccessibilityLabel extends NativeFinder {
@override
Map<String, String> toJson() {
return <String, String>{
'kind': 'byNativeAccessibilityLabel',
'label': label,
};
return <String, String>{'kind': 'byNativeAccessibilityLabel', 'label': label};
}
/// Deserializes this finder from the value generated by [serialize].
@@ -118,10 +109,7 @@ final class ByNativeIntegerId extends NativeFinder {
@override
Map<String, String> toJson() {
return <String, String>{
'kind': 'byNativeIntegerId',
'id': id.toString(),
};
return <String, String>{'kind': 'byNativeIntegerId', 'id': id.toString()};
}
/// Deserializes this finder from the value generated by [serialize].

View File

@@ -171,8 +171,7 @@ AsyncMatcher matchesGoldenFile(Object key, {int? version}) {
return switch (key) {
Uri() => _MatchesGoldenFile(key, version),
String() => _MatchesGoldenFile.forStringPath(key, version),
_ => throw ArgumentError(
'Unexpected type for golden file: ${key.runtimeType}'),
_ => throw ArgumentError('Unexpected type for golden file: ${key.runtimeType}'),
};
}
@@ -182,8 +181,7 @@ final class _MatchesGoldenFile extends AsyncMatcher {
const _MatchesGoldenFile(this.key, this.version);
/// Creates an instance of [MatchesGoldenFile] from a [String] path.
_MatchesGoldenFile.forStringPath(String path, this.version)
: key = Uri.parse(path);
_MatchesGoldenFile.forStringPath(String path, this.version) : key = Uri.parse(path);
/// The [key] to the golden image.
final Uri key;
@@ -201,9 +199,7 @@ final class _MatchesGoldenFile extends AsyncMatcher {
} else if (item is FutureOr<NativeScreenshot>) {
buffer = await (await item).readAsBytes();
} else {
throw ArgumentError(
'Unexpected type for golden file: ${item.runtimeType}',
);
throw ArgumentError('Unexpected type for golden file: ${item.runtimeType}');
}
if (autoUpdateGoldenFiles) {
@@ -211,10 +207,7 @@ final class _MatchesGoldenFile extends AsyncMatcher {
return null;
}
try {
final bool success = await goldenFileComparator.compare(
buffer,
testNameUri,
);
final bool success = await goldenFileComparator.compare(buffer, testNameUri);
return success ? null : 'does not match';
} on TestFailure catch (e) {
return e.message;