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

@@ -9,9 +9,7 @@ import 'package:flutter/rendering.dart';
import 'package:flutter/widgets.dart';
class TestWidget extends LeafRenderObjectWidget {
const TestWidget({
super.key,
});
const TestWidget({super.key});
@override
RenderObject createRenderObject(BuildContext context) => RenderTest();
@@ -42,7 +40,6 @@ class RenderTest extends RenderBox {
}
}
Future<void> main() async {
// This section introduces strings that we can search for in dev/bots/test.dart
// as a sanity check:

View File

@@ -24,7 +24,9 @@ void initTimelineTests() {
if (info.serverUri == null) {
fail('This test _must_ be run with --enable-vmservice.');
}
_vmService = await vmServiceConnectUri('ws://localhost:${info.serverUri!.port}${info.serverUri!.path}ws');
_vmService = await vmServiceConnectUri(
'ws://localhost:${info.serverUri!.port}${info.serverUri!.path}ws',
);
await _vmService.setVMTimelineFlags(<String>['Dart']);
isolateId = developer.Service.getIsolateId(isolate.Isolate.current)!;
});
@@ -38,8 +40,9 @@ Future<List<TimelineEvent>> fetchTimelineEvents() async {
Future<List<TimelineEvent>> fetchInterestingEvents(Set<String> interestingLabels) async {
return (await fetchTimelineEvents()).where((TimelineEvent event) {
return interestingLabels.contains(event.json!['name'])
&& event.json!['ph'] == 'B'; // "Begin" mark of events, vs E which is for the "End" mark of events.
return interestingLabels.contains(event.json!['name']) &&
event.json!['ph'] ==
'B'; // "Begin" mark of events, vs E which is for the "End" mark of events.
}).toList();
}
@@ -68,7 +71,9 @@ class ZoneIgnoringTestBinding extends WidgetsFlutterBinding {
}
@override
bool debugCheckZone(String entryPoint) { return true; }
bool debugCheckZone(String entryPoint) {
return true;
}
static ZoneIgnoringTestBinding get instance => BindingBase.checkInstance(_instance);
static ZoneIgnoringTestBinding? _instance;

View File

@@ -32,10 +32,6 @@ void main() {
test('Image cache tracing', () async {
final TimelineFlags flags = await vmService.getVMTimelineFlags();
expect(flags.recordedStreams, containsAll(<String>[
'Dart',
'Embedder',
'GC',
]));
expect(flags.recordedStreams, containsAll(<String>['Dart', 'Embedder', 'GC']));
}, skip: isBrowser); // [intended] uses dart:isolate and io.
}

View File

@@ -16,66 +16,42 @@ void main() {
test('Image cache tracing', () async {
final TestImageStreamCompleter completer1 = TestImageStreamCompleter();
final TestImageStreamCompleter completer2 = TestImageStreamCompleter();
PaintingBinding.instance.imageCache.putIfAbsent(
'Test',
() => completer1,
);
PaintingBinding.instance.imageCache.putIfAbsent('Test', () => completer1);
PaintingBinding.instance.imageCache.clear();
completer2.testSetImage(ImageInfo(image: await createTestImage()));
PaintingBinding.instance.imageCache.putIfAbsent(
'Test2',
() => completer2,
);
PaintingBinding.instance.imageCache.putIfAbsent('Test2', () => completer2);
PaintingBinding.instance.imageCache.evict('Test2');
_expectTimelineEvents(
await fetchTimelineEvents(),
<Map<String, dynamic>>[
<String, dynamic>{
'name': 'ImageCache.putIfAbsent',
'args': <String, dynamic>{
'key': 'Test',
'isolateId': isolateId,
'parentId': null,
},
_expectTimelineEvents(await fetchTimelineEvents(), <Map<String, dynamic>>[
<String, dynamic>{
'name': 'ImageCache.putIfAbsent',
'args': <String, dynamic>{'key': 'Test', 'isolateId': isolateId, 'parentId': null},
},
<String, dynamic>{
'name': 'listener',
'args': <String, dynamic>{'isolateId': isolateId, 'parentId': null},
},
<String, dynamic>{
'name': 'ImageCache.clear',
'args': <String, dynamic>{
'pendingImages': 1,
'keepAliveImages': 0,
'liveImages': 1,
'currentSizeInBytes': 0,
'isolateId': isolateId,
'parentId': null,
},
<String, dynamic>{
'name': 'listener',
'args': <String, dynamic>{
'isolateId': isolateId,
'parentId': null,
},
},
<String, dynamic>{
'name': 'ImageCache.clear',
'args': <String, dynamic>{
'pendingImages': 1,
'keepAliveImages': 0,
'liveImages': 1,
'currentSizeInBytes': 0,
'isolateId': isolateId,
'parentId': null,
},
},
<String, dynamic>{
'name': 'ImageCache.putIfAbsent',
'args': <String, dynamic>{
'key': 'Test2',
'isolateId': isolateId,
'parentId': null,
},
},
<String, dynamic>{
'name': 'ImageCache.evict',
'args': <String, dynamic>{
'sizeInBytes': 4,
'isolateId': isolateId,
'parentId': null,
},
},
],
);
},
<String, dynamic>{
'name': 'ImageCache.putIfAbsent',
'args': <String, dynamic>{'key': 'Test2', 'isolateId': isolateId, 'parentId': null},
},
<String, dynamic>{
'name': 'ImageCache.evict',
'args': <String, dynamic>{'sizeInBytes': 4, 'isolateId': isolateId, 'parentId': null},
},
]);
}, skip: isBrowser); // [intended] uses dart:isolate and io.
}

View File

@@ -18,14 +18,15 @@ void main() {
late VmService vmService;
late LiveTestWidgetsFlutterBinding binding;
setUpAll(() async {
final developer.ServiceProtocolInfo info =
await developer.Service.getInfo();
final developer.ServiceProtocolInfo info = await developer.Service.getInfo();
if (info.serverUri == null) {
fail('This test _must_ be run with --enable-vmservice.');
}
vmService = await vmServiceConnectUri('ws://localhost:${info.serverUri!.port}${info.serverUri!.path}ws');
vmService = await vmServiceConnectUri(
'ws://localhost:${info.serverUri!.port}${info.serverUri!.path}ws',
);
await vmService.streamListen(EventStreams.kExtension);
// Initialize bindings
@@ -44,8 +45,7 @@ void main() {
test('Image painting events - deduplicates across frames', () async {
final Completer<Event> completer = Completer<Event>();
vmService
.onExtensionEvent
vmService.onExtensionEvent
.firstWhere((Event event) => event.extensionKind == 'Flutter.ImageSizesForFrame')
.then(completer.complete);
@@ -74,14 +74,15 @@ void main() {
expect(event.extensionKind, 'Flutter.ImageSizesForFrame');
expect(
jsonEncode(event.extensionData!.data),
contains('"test.png":{"source":"test.png","displaySize":{"width":600.0,"height":300.0},"imageSize":{"width":300.0,"height":300.0},"displaySizeInBytes":960000,"decodedSizeInBytes":480000}'),
contains(
'"test.png":{"source":"test.png","displaySize":{"width":600.0,"height":300.0},"imageSize":{"width":300.0,"height":300.0},"displaySizeInBytes":960000,"decodedSizeInBytes":480000}',
),
);
}, skip: isBrowser); // [intended] uses dart:isolate and io.
test('Image painting events - deduplicates across frames', () async {
final Completer<Event> completer = Completer<Event>();
vmService
.onExtensionEvent
vmService.onExtensionEvent
.firstWhere((Event event) => event.extensionKind == 'Flutter.ImageSizesForFrame')
.then(completer.complete);
@@ -106,7 +107,9 @@ void main() {
expect(event.extensionKind, 'Flutter.ImageSizesForFrame');
expect(
jsonEncode(event.extensionData!.data),
contains('"test.png":{"source":"test.png","displaySize":{"width":900.0,"height":900.0},"imageSize":{"width":300.0,"height":300.0},"displaySizeInBytes":4320000,"decodedSizeInBytes":480000}'),
contains(
'"test.png":{"source":"test.png","displaySize":{"width":900.0,"height":900.0},"imageSize":{"width":300.0,"height":300.0},"displaySizeInBytes":4320000,"decodedSizeInBytes":480000}',
),
);
}, skip: isBrowser); // [intended] uses dart:isolate and io.
}

View File

@@ -21,7 +21,9 @@ void main() {
test('Children of MultiChildRenderObjectElement show up in tracing', () async {
// We don't have expectations around the first frame because there's a race around
// the warm-up frame that we don't want to get involved in here.
await runFrame(() { runApp(const TestRoot()); });
await runFrame(() {
runApp(const TestRoot());
});
await SchedulerBinding.instance.endOfFrame;
await fetchInterestingEvents(interestingLabels);
@@ -30,10 +32,14 @@ void main() {
await runFrame(() {
TestRoot.state.showRow();
});
expect(
await fetchInterestingEventNames(interestingLabels),
<String>['TestRoot', 'Row', 'TestChildWidget', 'Container', 'TestChildWidget', 'Container'],
);
expect(await fetchInterestingEventNames(interestingLabels), <String>[
'TestRoot',
'Row',
'TestChildWidget',
'Container',
'TestChildWidget',
'Container',
]);
debugProfileBuildsEnabled = false;
}, skip: isBrowser); // [intended] uses dart:isolate and io.
@@ -65,13 +71,8 @@ class TestRootState extends State<TestRoot> {
@override
Widget build(BuildContext context) {
return _showRow
? const Row(
children: <Widget>[
TestChildWidget(),
TestChildWidget(),
],
)
: Container();
? const Row(children: <Widget>[TestChildWidget(), TestChildWidget()])
: Container();
}
}

View File

@@ -12,7 +12,9 @@ void main() {
ZoneIgnoringTestBinding.ensureInitialized();
initTimelineTests();
test('Widgets with updated keys produce well formed timelines', () async {
await runFrame(() { runApp(const TestRoot()); });
await runFrame(() {
runApp(const TestRoot());
});
await SchedulerBinding.instance.endOfFrame;
debugProfileBuildsEnabled = true;
@@ -65,13 +67,6 @@ class TestRootState extends State<TestRoot> {
@override
Widget build(BuildContext context) {
return Center(
key: _localKey,
child: SizedBox(
key: _globalKey,
width: 100,
height: 100,
),
);
return Center(key: _localKey, child: SizedBox(key: _globalKey, width: 100, height: 100));
}
}

View File

@@ -22,7 +22,7 @@ final Set<String> interestingLabels = <String>{
};
class TestRoot extends StatefulWidget {
const TestRoot({ super.key });
const TestRoot({super.key});
static late final TestRootState state;
@@ -63,37 +63,56 @@ void main() {
test('Timeline', () async {
// We don't have expectations around the first frame because there's a race around
// the warm-up frame that we don't want to get involved in here.
await runFrame(() { runApp(const TestRoot()); });
await runFrame(() {
runApp(const TestRoot());
});
await SchedulerBinding.instance.endOfFrame;
await fetchInterestingEvents(interestingLabels);
// The next few cases build the exact same tree so should have no effect.
debugProfileBuildsEnabled = true;
await runFrame(() { TestRoot.state.rebuild(); });
expect(
await fetchInterestingEventNames(interestingLabels),
<String>['BUILD', 'LAYOUT', 'UPDATING COMPOSITING BITS', 'PAINT', 'COMPOSITING', 'FINALIZE TREE'],
);
await runFrame(() {
TestRoot.state.rebuild();
});
expect(await fetchInterestingEventNames(interestingLabels), <String>[
'BUILD',
'LAYOUT',
'UPDATING COMPOSITING BITS',
'PAINT',
'COMPOSITING',
'FINALIZE TREE',
]);
debugProfileBuildsEnabled = false;
debugProfileLayoutsEnabled = true;
await runFrame(() { TestRoot.state.rebuild(); });
expect(
await fetchInterestingEventNames(interestingLabels),
<String>['BUILD', 'LAYOUT', 'UPDATING COMPOSITING BITS', 'PAINT', 'COMPOSITING', 'FINALIZE TREE'],
);
await runFrame(() {
TestRoot.state.rebuild();
});
expect(await fetchInterestingEventNames(interestingLabels), <String>[
'BUILD',
'LAYOUT',
'UPDATING COMPOSITING BITS',
'PAINT',
'COMPOSITING',
'FINALIZE TREE',
]);
debugProfileLayoutsEnabled = false;
debugProfilePaintsEnabled = true;
await runFrame(() { TestRoot.state.rebuild(); });
expect(
await fetchInterestingEventNames(interestingLabels),
<String>['BUILD', 'LAYOUT', 'UPDATING COMPOSITING BITS', 'PAINT', 'COMPOSITING', 'FINALIZE TREE'],
);
await runFrame(() {
TestRoot.state.rebuild();
});
expect(await fetchInterestingEventNames(interestingLabels), <String>[
'BUILD',
'LAYOUT',
'UPDATING COMPOSITING BITS',
'PAINT',
'COMPOSITING',
'FINALIZE TREE',
]);
debugProfilePaintsEnabled = false;
// Now we replace the widgets each time to cause a rebuild.
List<TimelineEvent> events;
@@ -101,39 +120,79 @@ void main() {
debugProfileBuildsEnabled = true;
debugEnhanceBuildTimelineArguments = true;
await runFrame(() { TestRoot.state.updateWidget(Placeholder(key: UniqueKey(), color: const Color(0xFFFFFFFF))); });
await runFrame(() {
TestRoot.state.updateWidget(Placeholder(key: UniqueKey(), color: const Color(0xFFFFFFFF)));
});
events = await fetchInterestingEvents(interestingLabels);
expect(
events.map<String>(eventToName),
<String>['BUILD', 'Placeholder', 'CustomPaint', 'LAYOUT', 'UPDATING COMPOSITING BITS', 'PAINT', 'COMPOSITING', 'FINALIZE TREE'],
);
args = (events.where((TimelineEvent event) => event.json!['name'] == '$Placeholder').single.json!['args'] as Map<String, Object?>).cast<String, String>();
expect(events.map<String>(eventToName), <String>[
'BUILD',
'Placeholder',
'CustomPaint',
'LAYOUT',
'UPDATING COMPOSITING BITS',
'PAINT',
'COMPOSITING',
'FINALIZE TREE',
]);
args =
(events
.where((TimelineEvent event) => event.json!['name'] == '$Placeholder')
.single
.json!['args']
as Map<String, Object?>)
.cast<String, String>();
expect(args['color'], '${const Color(0xffffffff)}');
debugProfileBuildsEnabled = false;
debugEnhanceBuildTimelineArguments = false;
debugProfileBuildsEnabledUserWidgets = true;
debugEnhanceBuildTimelineArguments = true;
await runFrame(() { TestRoot.state.updateWidget(Placeholder(key: UniqueKey(), color: const Color(0xFFFFFFFF))); });
await runFrame(() {
TestRoot.state.updateWidget(Placeholder(key: UniqueKey(), color: const Color(0xFFFFFFFF)));
});
events = await fetchInterestingEvents(interestingLabels);
expect(
events.map<String>(eventToName),
<String>['BUILD', 'Placeholder', 'LAYOUT', 'UPDATING COMPOSITING BITS', 'PAINT', 'COMPOSITING', 'FINALIZE TREE'],
);
args = (events.where((TimelineEvent event) => event.json!['name'] == '$Placeholder').single.json!['args'] as Map<String, Object?>).cast<String, String>();
expect(events.map<String>(eventToName), <String>[
'BUILD',
'Placeholder',
'LAYOUT',
'UPDATING COMPOSITING BITS',
'PAINT',
'COMPOSITING',
'FINALIZE TREE',
]);
args =
(events
.where((TimelineEvent event) => event.json!['name'] == '$Placeholder')
.single
.json!['args']
as Map<String, Object?>)
.cast<String, String>();
expect(args['color'], '${const Color(0xffffffff)}');
debugProfileBuildsEnabledUserWidgets = false;
debugEnhanceBuildTimelineArguments = false;
debugProfileLayoutsEnabled = true;
debugEnhanceLayoutTimelineArguments = true;
await runFrame(() { TestRoot.state.updateWidget(Placeholder(key: UniqueKey())); });
await runFrame(() {
TestRoot.state.updateWidget(Placeholder(key: UniqueKey()));
});
events = await fetchInterestingEvents(interestingLabels);
expect(
events.map<String>(eventToName),
<String>['BUILD', 'LAYOUT', 'RenderCustomPaint', 'UPDATING COMPOSITING BITS', 'PAINT', 'COMPOSITING', 'FINALIZE TREE'],
);
args = (events.where((TimelineEvent event) => event.json!['name'] == '$RenderCustomPaint').single.json!['args'] as Map<String, Object?>).cast<String, String>();
expect(events.map<String>(eventToName), <String>[
'BUILD',
'LAYOUT',
'RenderCustomPaint',
'UPDATING COMPOSITING BITS',
'PAINT',
'COMPOSITING',
'FINALIZE TREE',
]);
args =
(events
.where((TimelineEvent event) => event.json!['name'] == '$RenderCustomPaint')
.single
.json!['args']
as Map<String, Object?>)
.cast<String, String>();
expect(args['creator'], startsWith('CustomPaint'));
expect(args['creator'], contains('Placeholder'));
expect(args['painter'], startsWith('_PlaceholderPainter#'));
@@ -142,18 +201,30 @@ void main() {
debugProfilePaintsEnabled = true;
debugEnhancePaintTimelineArguments = true;
await runFrame(() { TestRoot.state.updateWidget(Placeholder(key: UniqueKey())); });
await runFrame(() {
TestRoot.state.updateWidget(Placeholder(key: UniqueKey()));
});
events = await fetchInterestingEvents(interestingLabels);
expect(
events.map<String>(eventToName),
<String>['BUILD', 'LAYOUT', 'UPDATING COMPOSITING BITS', 'PAINT', 'RenderCustomPaint', 'COMPOSITING', 'FINALIZE TREE'],
);
args = (events.where((TimelineEvent event) => event.json!['name'] == '$RenderCustomPaint').single.json!['args'] as Map<String, Object?>).cast<String, String>();
expect(events.map<String>(eventToName), <String>[
'BUILD',
'LAYOUT',
'UPDATING COMPOSITING BITS',
'PAINT',
'RenderCustomPaint',
'COMPOSITING',
'FINALIZE TREE',
]);
args =
(events
.where((TimelineEvent event) => event.json!['name'] == '$RenderCustomPaint')
.single
.json!['args']
as Map<String, Object?>)
.cast<String, String>();
expect(args['creator'], startsWith('CustomPaint'));
expect(args['creator'], contains('Placeholder'));
expect(args['painter'], startsWith('_PlaceholderPainter#'));
debugProfilePaintsEnabled = false;
debugEnhancePaintTimelineArguments = false;
}, skip: isBrowser); // [intended] uses dart:isolate and io.
}