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

@@ -34,7 +34,9 @@ Future<bool> runTests({
final String s = files.length == 1 ? '' : 's';
if (numberShards > 1) {
final String ss = shardedFiles.length == 1 ? '' : 's';
print('${files.length} file$s specified. ${shardedFiles.length} test$ss in shard #$shardIndex ($numberShards shards total).');
print(
'${files.length} file$s specified. ${shardedFiles.length} test$ss in shard #$shardIndex ($numberShards shards total).',
);
} else {
print('${files.length} file$s specified.');
}
@@ -78,14 +80,21 @@ Future<bool> runTests({
bool success = true;
final Directory checkout = Directory.systemTemp.createTempSync('flutter_customer_testing.${path.basenameWithoutExtension(file.path)}.');
final Directory checkout = Directory.systemTemp.createTempSync(
'flutter_customer_testing.${path.basenameWithoutExtension(file.path)}.',
);
if (verbose) {
print('Created temporary directory: ${checkout.path}');
}
try {
assert(instructions.fetch.isNotEmpty);
for (final String fetchCommand in instructions.fetch) {
success = await shell(fetchCommand, checkout, verbose: verbose, silentFailure: skipOnFetchFailure);
success = await shell(
fetchCommand,
checkout,
verbose: verbose,
silentFailure: skipOnFetchFailure,
);
if (!success) {
if (skipOnFetchFailure) {
if (verbose) {
@@ -105,34 +114,38 @@ Future<bool> runTests({
if (verbose) {
print('Running setup command: $setupCommand');
}
success = await shell(
setupCommand,
customerRepo,
verbose: verbose,
);
success = await shell(setupCommand, customerRepo, verbose: verbose);
if (!success) {
failure('Setup command failed: $setupCommand');
break;
}
}
for (final Directory updateDirectory in instructions.update) {
final Directory resolvedUpdateDirectory = Directory(path.join(customerRepo.path, updateDirectory.path));
final Directory resolvedUpdateDirectory = Directory(
path.join(customerRepo.path, updateDirectory.path),
);
if (verbose) {
print('Updating code in ${resolvedUpdateDirectory.path}...');
}
if (!File(path.join(resolvedUpdateDirectory.path, 'pubspec.yaml')).existsSync()) {
failure('The directory ${updateDirectory.path}, which was specified as an update directory, does not contain a "pubspec.yaml" file.');
failure(
'The directory ${updateDirectory.path}, which was specified as an update directory, does not contain a "pubspec.yaml" file.',
);
success = false;
break;
}
success = await shell('flutter packages get', resolvedUpdateDirectory, verbose: verbose);
if (!success) {
failure('Could not run "flutter pub get" in ${updateDirectory.path}, which was specified as an update directory.');
failure(
'Could not run "flutter pub get" in ${updateDirectory.path}, which was specified as an update directory.',
);
break;
}
success = await shell('dart fix --apply', resolvedUpdateDirectory, verbose: verbose);
if (!success) {
failure('Could not run "dart fix" in ${updateDirectory.path}, which was specified as an update directory.');
failure(
'Could not run "dart fix" in ${updateDirectory.path}, which was specified as an update directory.',
);
break;
}
}
@@ -143,7 +156,9 @@ Future<bool> runTests({
if (instructions.iterations != null && instructions.iterations! < repeat) {
if (verbose) {
final String s = instructions.iterations == 1 ? '' : 's';
print('Limiting to ${instructions.iterations} round$s rather than $repeat rounds because of "iterations" directive.');
print(
'Limiting to ${instructions.iterations} round$s rather than $repeat rounds because of "iterations" directive.',
);
}
repeat = instructions.iterations!;
}
@@ -156,14 +171,18 @@ Future<bool> runTests({
testCount += 1;
success = await shell(testCommand, customerRepo, verbose: verbose);
if (!success) {
failure('One or more tests from ${path.basenameWithoutExtension(file.path)} failed.');
failure(
'One or more tests from ${path.basenameWithoutExtension(file.path)} failed.',
);
break;
}
}
}
stopwatch.stop();
// Always print test runtime for debugging.
print('Tests finished in ${(stopwatch.elapsed.inSeconds / repeat).toStringAsFixed(2)} seconds per iteration.');
print(
'Tests finished in ${(stopwatch.elapsed.inSeconds / repeat).toStringAsFixed(2)} seconds per iteration.',
);
}
}
} finally {
@@ -195,20 +214,40 @@ Future<bool> runTests({
final RegExp _spaces = RegExp(r' +');
Future<bool> shell(String command, Directory directory, { bool verbose = false, bool silentFailure = false, void Function()? failedCallback }) async {
Future<bool> shell(
String command,
Directory directory, {
bool verbose = false,
bool silentFailure = false,
void Function()? failedCallback,
}) async {
if (verbose) {
print('>> $command');
}
Process process;
if (Platform.isWindows) {
process = await Process.start('CMD.EXE', <String>['/S', '/C', command], workingDirectory: directory.path);
process = await Process.start('CMD.EXE', <String>[
'/S',
'/C',
command,
], workingDirectory: directory.path);
} else {
final List<String> segments = command.trim().split(_spaces);
process = await Process.start(segments.first, segments.skip(1).toList(), workingDirectory: directory.path);
process = await Process.start(
segments.first,
segments.skip(1).toList(),
workingDirectory: directory.path,
);
}
final List<String> output = <String>[];
utf8.decoder.bind(process.stdout).transform(const LineSplitter()).listen(verbose ? printLog : output.add);
utf8.decoder.bind(process.stderr).transform(const LineSplitter()).listen(verbose ? printLog : output.add);
utf8.decoder
.bind(process.stdout)
.transform(const LineSplitter())
.listen(verbose ? printLog : output.add);
utf8.decoder
.bind(process.stderr)
.transform(const LineSplitter())
.listen(verbose ? printLog : output.add);
final bool success = await process.exitCode == 0;
if (success || silentFailure) {
return success;