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

@@ -67,29 +67,27 @@ String getChannelName({
final RegExp gitBranchRegexp = RegExp(r'^## (?<branch>.*)');
final ProcessResult gitResult = processManager.runSync(
<String>['git', 'status', '-b', '--porcelain'],
// Use the FLUTTER_ROOT, if defined.
workingDirectory: platform.environment['FLUTTER_ROOT']?.trim() ??
filesystem.currentDirectory.path,
// Adding extra debugging output to help debug why git status inexplicably fails
// (random non-zero error code) about 2% of the time.
environment: <String, String>{'GIT_TRACE': '2', 'GIT_TRACE_SETUP': '2'});
<String>['git', 'status', '-b', '--porcelain'],
// Use the FLUTTER_ROOT, if defined.
workingDirectory:
platform.environment['FLUTTER_ROOT']?.trim() ?? filesystem.currentDirectory.path,
// Adding extra debugging output to help debug why git status inexplicably fails
// (random non-zero error code) about 2% of the time.
environment: <String, String>{'GIT_TRACE': '2', 'GIT_TRACE_SETUP': '2'},
);
if (gitResult.exitCode != 0) {
throw GitStatusFailed(gitResult);
}
final RegExpMatch? gitBranchMatch = gitBranchRegexp
.firstMatch((gitResult.stdout as String).trim().split('\n').first);
final RegExpMatch? gitBranchMatch = gitBranchRegexp.firstMatch(
(gitResult.stdout as String).trim().split('\n').first,
);
return gitBranchMatch == null
? '<unknown>'
: gitBranchMatch.namedGroup('branch')!.split('...').first;
}
const List<String> sampleTypes = <String>[
'snippet',
'sample',
'dartpad',
];
const List<String> sampleTypes = <String>['snippet', 'sample', 'dartpad'];
// This is a hack to workaround the fact that git status inexplicably fails
// (with random non-zero error code) about 2% of the time.
@@ -104,8 +102,7 @@ String getChannelNameWithRetries({
return getChannelName(platform: platform, processManager: processManager);
} on GitStatusFailed catch (e) {
retryCount += 1;
stderr.write(
'git status failed, retrying ($retryCount)\nError report:\n$e');
stderr.write('git status failed, retrying ($retryCount)\nError report:\n$e');
}
}
@@ -123,18 +120,16 @@ void main(List<String> argList) {
defaultsTo: 'dartpad',
allowed: sampleTypes,
allowedHelp: <String, String>{
'dartpad':
'Produce a code sample application for using in Dartpad.',
'sample':
'Produce a code sample application.',
'snippet':
'Produce a nicely formatted piece of sample code.',
'dartpad': 'Produce a code sample application for using in Dartpad.',
'sample': 'Produce a code sample application.',
'snippet': 'Produce a nicely formatted piece of sample code.',
},
help: 'The type of snippet to produce.',
);
parser.addOption(
_kOutputOption,
help: 'The output name for the generated sample application. Overrides '
help:
'The output name for the generated sample application. Overrides '
'the naming generated by the --$_kPackageOption/--$_kLibraryOption/--$_kElementOption '
'arguments. Metadata will be written alongside in a .json file. '
'The basename of this argument is used as the ID. If this is a '
@@ -194,8 +189,9 @@ void main(List<String> argList) {
if (args[_kInputOption] == null) {
stderr.writeln(parser.usage);
errorExit(
'The --$_kInputOption option must be specified, either on the command '
'line, or in the INPUT environment variable.');
'The --$_kInputOption option must be specified, either on the command '
'line, or in the INPUT environment variable.',
);
return;
}
@@ -221,8 +217,7 @@ void main(List<String> argList) {
if (outputPath.isAbsolute) {
output = outputPath;
} else {
output =
filesystem.file(path.join(outputDirectory.path, outputPath.path));
output = filesystem.file(path.join(outputDirectory.path, outputPath.path));
}
} else {
final List<String> idParts = <String>[];
@@ -239,9 +234,11 @@ void main(List<String> argList) {
idParts.add(serial);
}
if (idParts.isEmpty) {
errorExit('Unable to determine ID. At least one of --$_kPackageOption, '
'--$_kLibraryOption, --$_kElementOption, -$_kSerialOption, or the environment variables '
'PACKAGE_NAME, LIBRARY_NAME, ELEMENT_NAME, or INVOCATION_INDEX must be non-empty.');
errorExit(
'Unable to determine ID. At least one of --$_kPackageOption, '
'--$_kLibraryOption, --$_kElementOption, -$_kSerialOption, or the environment variables '
'PACKAGE_NAME, LIBRARY_NAME, ELEMENT_NAME, or INVOCATION_INDEX must be non-empty.',
);
return;
}
id = idParts.join('.');
@@ -249,9 +246,8 @@ void main(List<String> argList) {
}
output.parent.createSync(recursive: true);
final int? sourceLine = environment['SOURCE_LINE'] != null
? int.tryParse(environment['SOURCE_LINE']!)
: null;
final int? sourceLine =
environment['SOURCE_LINE'] != null ? int.tryParse(environment['SOURCE_LINE']!) : null;
final String sourcePath = environment['SOURCE_PATH'] ?? 'unknown.dart';
final SnippetDartdocParser sampleParser = SnippetDartdocParser(filesystem);
final SourceElement element = sampleParser.parseFromDartdocToolFile(
@@ -262,8 +258,7 @@ void main(List<String> argList) {
type: sampleType,
);
final Map<String, Object?> metadata = <String, Object?>{
'channel': getChannelNameWithRetries(
platform: platform, processManager: processManager),
'channel': getChannelNameWithRetries(platform: platform, processManager: processManager),
'serial': serial,
'id': id,
'package': packageName,
@@ -273,11 +268,7 @@ void main(List<String> argList) {
for (final CodeSample sample in element.samples) {
sample.metadata.addAll(metadata);
snippetGenerator.generateCode(
sample,
output: output,
formatOutput: formatOutput,
);
snippetGenerator.generateCode(sample, output: output, formatOutput: formatOutput);
print(snippetGenerator.generateHtml(sample));
}