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

@@ -7,7 +7,7 @@ import 'dart:js_interop';
import 'package:flutter/foundation.dart';
import 'package:web/web.dart' as web;
Future<void> main() async {
Future<void> main() async {
bool executedAssert = false;
assert(() {
executedAssert = true;
@@ -21,12 +21,8 @@ Future<void> main() async {
output.write('--- TEST FAILED ---');
}
await web.window.fetch(
'/test-result'.toJS,
web.RequestInit(
method: 'POST',
body: '$output'.toJS,
)
).toDart;
await web.window
.fetch('/test-result'.toJS, web.RequestInit(method: 'POST', body: '$output'.toJS))
.toDart;
print(output);
}

View File

@@ -17,7 +17,7 @@ import 'package:web/web.dart' as web;
// framework's ability to parse stack traces in all build modes.
Future<void> main() async {
final StringBuffer errorMessage = StringBuffer();
debugPrint = (String? message, { int? wrapWidth }) {
debugPrint = (String? message, {int? wrapWidth}) {
errorMessage.writeln(message);
};
@@ -29,19 +29,15 @@ Future<void> main() async {
final StringBuffer output = StringBuffer();
if (_errorMessageFormattedCorrectly(errorMessage.toString())) {
output.writeln('--- TEST SUCCEEDED ---');
} else {
} else {
output.writeln('--- UNEXPECTED ERROR MESSAGE FORMAT ---');
output.writeln(errorMessage);
output.writeln('--- TEST FAILED ---');
}
await web.window.fetch(
'/test-result'.toJS,
web.RequestInit(
method: 'POST',
body: '$output'.toJS,
)
).toDart;
await web.window
.fetch('/test-result'.toJS, web.RequestInit(method: 'POST', body: '$output'.toJS))
.toDart;
print(output);
}

View File

@@ -5,7 +5,5 @@
import 'package:flutter/widgets.dart';
void main() {
runApp(const Center(
child: Text('Hello, World', textDirection: TextDirection.ltr),
));
runApp(const Center(child: Text('Hello, World', textDirection: TextDirection.ltr)));
}

View File

@@ -5,16 +5,19 @@
import 'package:flutter/material.dart';
Future<void> main() async {
runApp(const Directionality(
textDirection: TextDirection.ltr,
child: Scaffold(
body: Center(
child: Column(
children: <Widget>[
Icon(Icons.ac_unit),
Text('Hello, World', textDirection: TextDirection.ltr),
],
runApp(
const Directionality(
textDirection: TextDirection.ltr,
child: Scaffold(
body: Center(
child: Column(
children: <Widget>[
Icon(Icons.ac_unit),
Text('Hello, World', textDirection: TextDirection.ltr),
],
),
),
),
)));
),
);
}

View File

@@ -17,12 +17,13 @@ void main() async {
} else {
output = '--- TEST SUCCEEDED ---';
}
await web.window.fetch(
'/test-result'.toJS,
web.RequestInit(
method: 'POST',
body: output.toJS,
)
).toDart;
await web.window
.fetch(
'/test-result'.toJS,
web.RequestInit(
method: 'POST',
body: output.toJS,
))
.toDart;
print(output);
}

View File

@@ -12,19 +12,20 @@ import 'package:web/web.dart' as web;
/// Expected sequence of method calls.
const List<String> callChain = <String>['baz', 'bar', 'foo'];
final List<StackFrame> expectedProfileStackFrames = callChain.map<StackFrame>((String method) {
return StackFrame(
number: -1,
packageScheme: '<unknown>',
package: '<unknown>',
packagePath: '<unknown>',
line: -1,
column: -1,
className: 'Object',
method: method,
source: '',
);
}).toList();
final List<StackFrame> expectedProfileStackFrames =
callChain.map<StackFrame>((String method) {
return StackFrame(
number: -1,
packageScheme: '<unknown>',
package: '<unknown>',
packagePath: '<unknown>',
line: -1,
column: -1,
className: 'Object',
method: method,
source: '',
);
}).toList();
// TODO(yjbanov): fix these stack traces when https://github.com/flutter/flutter/issues/50753 is fixed.
const List<StackFrame> expectedDebugStackFrames = <StackFrame>[
@@ -33,7 +34,7 @@ const List<StackFrame> expectedDebugStackFrames = <StackFrame>[
packageScheme: 'package',
package: 'packages',
packagePath: 'web_integration/stack_trace.dart',
line: 122,
line: 119,
column: 3,
className: '<unknown>',
method: 'baz',
@@ -44,7 +45,7 @@ const List<StackFrame> expectedDebugStackFrames = <StackFrame>[
packageScheme: 'package',
package: 'packages',
packagePath: 'web_integration/stack_trace.dart',
line: 117,
line: 114,
column: 3,
className: '<unknown>',
method: 'bar',
@@ -55,7 +56,7 @@ const List<StackFrame> expectedDebugStackFrames = <StackFrame>[
packageScheme: 'package',
package: 'packages',
packagePath: 'web_integration/stack_trace.dart',
line: 112,
line: 109,
column: 3,
className: '<unknown>',
method: 'foo',
@@ -76,7 +77,7 @@ void main() async {
if (parsedFrames.isEmpty) {
throw Exception(
'Failed to parse stack trace. Got empty list of stack frames.\n'
'Stack trace:\n$expectedStackTrace'
'Stack trace:\n$expectedStackTrace',
);
}
@@ -97,13 +98,9 @@ void main() async {
output.writeln(unexpectedStackTrace);
output.writeln('--- TEST FAILED ---');
}
await web.window.fetch(
'/test-result'.toJS,
web.RequestInit(
method: 'POST',
body: '$output'.toJS,
)
).toDart;
await web.window
.fetch('/test-result'.toJS, web.RequestInit(method: 'POST', body: '$output'.toJS))
.toDart;
print(output);
}
@@ -122,18 +119,23 @@ void baz() {
throw Exception('Test error message');
}
void _checkStackFrameContents(List<StackFrame> parsedFrames, List<StackFrame> expectedFrames, dynamic stackTrace) {
void _checkStackFrameContents(
List<StackFrame> parsedFrames,
List<StackFrame> expectedFrames,
dynamic stackTrace,
) {
// Filter out stack frames outside this library so this test is less brittle.
final List<StackFrame> actual = parsedFrames
.where((StackFrame frame) => callChain.contains(frame.method))
.toList();
final bool stackFramesAsExpected = ListEquality<StackFrame>(StackFrameEquality()).equals(actual, expectedFrames);
final List<StackFrame> actual =
parsedFrames.where((StackFrame frame) => callChain.contains(frame.method)).toList();
final bool stackFramesAsExpected = ListEquality<StackFrame>(
StackFrameEquality(),
).equals(actual, expectedFrames);
if (!stackFramesAsExpected) {
throw Exception(
'Stack frames parsed incorrectly:\n'
'Expected:\n${expectedFrames.join('\n')}\n'
'Actual:\n${actual.join('\n')}\n'
'Stack trace:\n$stackTrace'
'Stack trace:\n$stackTrace',
);
}
}
@@ -144,18 +146,27 @@ class StackFrameEquality implements Equality<StackFrame> {
@override
bool equals(StackFrame e1, StackFrame e2) {
return e1.number == e2.number &&
e1.packageScheme == e2.packageScheme &&
e1.package == e2.package &&
e1.packagePath == e2.packagePath &&
e1.line == e2.line &&
e1.column == e2.column &&
e1.className == e2.className &&
e1.method == e2.method;
e1.packageScheme == e2.packageScheme &&
e1.package == e2.package &&
e1.packagePath == e2.packagePath &&
e1.line == e2.line &&
e1.column == e2.column &&
e1.className == e2.className &&
e1.method == e2.method;
}
@override
int hash(StackFrame e) {
return Object.hash(e.number, e.packageScheme, e.package, e.packagePath, e.line, e.column, e.className, e.method);
return Object.hash(
e.number,
e.packageScheme,
e.package,
e.packagePath,
e.line,
e.column,
e.className,
e.method,
);
}
@override

View File

@@ -8,20 +8,16 @@ import 'package:web/web.dart' as web;
Future<void> main() async {
final StringBuffer output = StringBuffer();
const String combined = String.fromEnvironment('test.valueA') +
String.fromEnvironment('test.valueB');
const String combined =
String.fromEnvironment('test.valueA') + String.fromEnvironment('test.valueB');
if (combined == 'Example,AValue') {
output.write('--- TEST SUCCEEDED ---');
} else {
output.write('--- TEST FAILED ---');
}
await web.window.fetch(
'/test-result'.toJS,
web.RequestInit(
method: 'POST',
body: '$output'.toJS,
)
).toDart;
await web.window
.fetch('/test-result'.toJS, web.RequestInit(method: 'POST', body: '$output'.toJS))
.toDart;
print(output);
}

View File

@@ -9,12 +9,8 @@ import 'package:web/web.dart' as web;
// Attempt to load a file that is hosted in the applications's `web/` directory.
Future<void> main() async {
try {
final web.Response response = await web.window.fetch(
'/example'.toJS,
web.RequestInit(
method: 'GET',
),
).toDart;
final web.Response response =
await web.window.fetch('/example'.toJS, web.RequestInit(method: 'GET')).toDart;
final String body = (await response.text().toDart).toDart;
if (body == 'This is an Example') {
print('--- TEST SUCCEEDED ---');

View File

@@ -21,12 +21,13 @@ Future<bool> testFetchResources() async {
return false;
}
try {
final web.Response response = await web.window.fetch(
'https://www.gstatic.com/flutter-canvaskit/$engineVersion/canvaskit.js'.toJS,
web.RequestInit(
method: 'GET',
),
).toDart;
final web.Response response =
await web.window
.fetch(
'https://www.gstatic.com/flutter-canvaskit/$engineVersion/canvaskit.js'.toJS,
web.RequestInit(method: 'GET'),
)
.toDart;
if (!response.ok) {
return false;
}
@@ -35,12 +36,13 @@ Future<bool> testFetchResources() async {
return false;
}
try {
final web.Response response = await web.window.fetch(
'https://www.gstatic.com/flutter-canvaskit/$engineVersion/canvaskit.wasm'.toJS,
web.RequestInit(
method: 'GET',
)
).toDart;
final web.Response response =
await web.window
.fetch(
'https://www.gstatic.com/flutter-canvaskit/$engineVersion/canvaskit.wasm'.toJS,
web.RequestInit(method: 'GET'),
)
.toDart;
if (!response.ok) {
return false;
}

View File

@@ -3,12 +3,14 @@
// found in the LICENSE file.
import 'package:web_integration/a.dart'
if (dart.library.io) 'package:web_integration/b.dart' as message1;
if (dart.library.io) 'package:web_integration/b.dart'
as message1;
import 'package:web_integration/c.dart'
if (dart.library.js_interop) 'package:web_integration/d.dart' as message2;
if (dart.library.js_interop) 'package:web_integration/d.dart'
as message2;
void main() {
if (message1.message == 'a' && message2.message == 'd') {
if (message1.message == 'a' && message2.message == 'd') {
print('--- TEST SUCCEEDED ---');
} else {
print('--- TEST FAILED ---');