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

@@ -18,7 +18,9 @@ import 'utils.dart';
/// If `expectNonZeroExit` is false and the process exits with a non-zero exit
/// code fails the test immediately by exiting the test process with exit code
/// 1.
Stream<String> runAndGetStdout(String executable, List<String> arguments, {
Stream<String> runAndGetStdout(
String executable,
List<String> arguments, {
String? workingDirectory,
Map<String, String>? environment,
bool expectNonZeroExit = false,
@@ -82,7 +84,9 @@ class CommandResult {
///
/// `outputMode` controls where the standard output from the command process
/// goes. See [OutputMode].
Future<Command> startCommand(String executable, List<String> arguments, {
Future<Command> startCommand(
String executable,
List<String> arguments, {
String? workingDirectory,
Map<String, String>? environment,
OutputMode outputMode = OutputMode.print,
@@ -90,12 +94,15 @@ Future<Command> startCommand(String executable, List<String> arguments, {
void Function(String, io.Process)? outputListener,
}) async {
final String relativeWorkingDir = path.relative(workingDirectory ?? io.Directory.current.path);
final String commandDescription = '${path.relative(executable, from: workingDirectory)} ${arguments.join(' ')}';
final String commandDescription =
'${path.relative(executable, from: workingDirectory)} ${arguments.join(' ')}';
print('RUNNING: cd $cyan$relativeWorkingDir$reset; $green$commandDescription$reset');
final Stopwatch time = Stopwatch()..start();
print('workingDirectory: $workingDirectory, executable: $executable, arguments: $arguments');
final io.Process process = await io.Process.start(executable, arguments,
final io.Process process = await io.Process.start(
executable,
arguments,
workingDirectory: workingDirectory,
environment: environment,
);
@@ -103,36 +110,36 @@ Future<Command> startCommand(String executable, List<String> arguments, {
process,
time,
process.stdout
.transform<String>(const Utf8Decoder())
.transform(const LineSplitter())
.where((String line) => removeLine == null || !removeLine(line))
.map<String>((String line) {
final String formattedLine = '$line\n';
if (outputListener != null) {
outputListener(formattedLine, process);
}
switch (outputMode) {
case OutputMode.print:
print(line);
case OutputMode.capture:
break;
}
return line;
})
.join('\n'),
.transform<String>(const Utf8Decoder())
.transform(const LineSplitter())
.where((String line) => removeLine == null || !removeLine(line))
.map<String>((String line) {
final String formattedLine = '$line\n';
if (outputListener != null) {
outputListener(formattedLine, process);
}
switch (outputMode) {
case OutputMode.print:
print(line);
case OutputMode.capture:
break;
}
return line;
})
.join('\n'),
process.stderr
.transform<String>(const Utf8Decoder())
.transform(const LineSplitter())
.map<String>((String line) {
switch (outputMode) {
case OutputMode.print:
print(line);
case OutputMode.capture:
break;
}
return line;
})
.join('\n'),
.transform<String>(const Utf8Decoder())
.transform(const LineSplitter())
.map<String>((String line) {
switch (outputMode) {
case OutputMode.print:
print(line);
case OutputMode.capture:
break;
}
return line;
})
.join('\n'),
);
}
@@ -150,7 +157,9 @@ Future<Command> startCommand(String executable, List<String> arguments, {
///
/// `outputMode` controls where the standard output from the command process
/// goes. See [OutputMode].
Future<CommandResult> runCommand(String executable, List<String> arguments, {
Future<CommandResult> runCommand(
String executable,
List<String> arguments, {
String? workingDirectory,
Map<String, String>? environment,
bool expectNonZeroExit = false,
@@ -160,7 +169,8 @@ Future<CommandResult> runCommand(String executable, List<String> arguments, {
bool Function(String)? removeLine,
void Function(String, io.Process)? outputListener,
}) async {
final String commandDescription = '${path.relative(executable, from: workingDirectory)} ${arguments.join(' ')}';
final String commandDescription =
'${path.relative(executable, from: workingDirectory)} ${arguments.join(' ')}';
final String relativeWorkingDir = workingDirectory ?? path.relative(io.Directory.current.path);
if (dryRun) {
printProgress(_prettyPrintRunCommand(executable, arguments, workingDirectory));
@@ -172,7 +182,9 @@ Future<CommandResult> runCommand(String executable, List<String> arguments, {
);
}
final Command command = await startCommand(executable, arguments,
final Command command = await startCommand(
executable,
arguments,
workingDirectory: workingDirectory,
environment: environment,
outputMode: outputMode,
@@ -187,7 +199,8 @@ Future<CommandResult> runCommand(String executable, List<String> arguments, {
await command._savedStderr,
);
if ((result.exitCode == 0) == expectNonZeroExit || (expectedExitCode != null && result.exitCode != expectedExitCode)) {
if ((result.exitCode == 0) == expectNonZeroExit ||
(expectedExitCode != null && result.exitCode != expectedExitCode)) {
// Print the output when we get unexpected results (unless output was
// printed already).
switch (outputMode) {
@@ -199,8 +212,7 @@ Future<CommandResult> runCommand(String executable, List<String> arguments, {
}
final String allOutput = '${result.flattenedStdout}\n${result.flattenedStderr}';
foundError(<String>[
if (failureMessage != null)
failureMessage,
if (failureMessage != null) failureMessage,
'${bold}Command: $green$commandDescription$reset',
if (failureMessage == null)
'$bold${red}Command exited with exit code ${result.exitCode} but expected ${expectNonZeroExit ? (expectedExitCode ?? 'non-zero') : 'zero'} exit code.$reset',
@@ -209,12 +221,16 @@ Future<CommandResult> runCommand(String executable, List<String> arguments, {
'${bold}stdout and stderr output:\n$allOutput',
]);
} else {
print('ELAPSED TIME: ${prettyPrintDuration(result.elapsedTime)} for $green$commandDescription$reset in $cyan$relativeWorkingDir$reset');
print(
'ELAPSED TIME: ${prettyPrintDuration(result.elapsedTime)} for $green$commandDescription$reset in $cyan$relativeWorkingDir$reset',
);
}
return result;
}
final String _flutterRoot = path.dirname(path.dirname(path.dirname(path.fromUri(io.Platform.script))));
final String _flutterRoot = path.dirname(
path.dirname(path.dirname(path.fromUri(io.Platform.script))),
);
String _prettyPrintRunCommand(String executable, List<String> arguments, String? workingDirectory) {
final StringBuffer output = StringBuffer();