Skip to content

Commit 8e0993e

Browse files
authored
Auto-format Dart code in engine (flutter#160576)
This auto-formats all *.dart files in the `engine` subdirectory and enforces that these files stay formatted with a presubmit check.
1 parent ba01bab commit 8e0993e

File tree

721 files changed

+68404
-68049
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

721 files changed

+68404
-68049
lines changed

engine/src/flutter/ci/bin/format.dart

Lines changed: 225 additions & 200 deletions
Large diffs are not rendered by default.

engine/src/flutter/ci/test/format_test.dart

Lines changed: 69 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -20,28 +20,32 @@ class FileContentPair {
2020
}
2121

2222
final FileContentPair ccContentPair = FileContentPair(
23-
'int main(){return 0;}\n', 'int main() {\n return 0;\n}\n');
24-
final FileContentPair hContentPair =
25-
FileContentPair('int\nmain\n()\n;\n', 'int main();\n');
23+
'int main(){return 0;}\n',
24+
'int main() {\n return 0;\n}\n',
25+
);
26+
final FileContentPair hContentPair = FileContentPair('int\nmain\n()\n;\n', 'int main();\n');
2627
final FileContentPair dartContentPair = FileContentPair(
27-
'enum \n\nfoo {\n entry1,\n entry2,\n}', 'enum foo { entry1, entry2 }\n');
28+
'enum \n\nfoo {\n entry1,\n entry2,\n}',
29+
'enum foo { entry1, entry2 }\n',
30+
);
2831
final FileContentPair gnContentPair = FileContentPair(
29-
'test\n(){testvar=true}\n', 'test() {\n testvar = true\n}\n');
32+
'test\n(){testvar=true}\n',
33+
'test() {\n testvar = true\n}\n',
34+
);
3035
final FileContentPair javaContentPair = FileContentPair(
31-
'class Test{public static void main(String args[]){System.out.println("Test");}}\n',
32-
'class Test {\n public static void main(String args[]) {\n System.out.println("Test");\n }\n}\n');
36+
'class Test{public static void main(String args[]){System.out.println("Test");}}\n',
37+
'class Test {\n public static void main(String args[]) {\n System.out.println("Test");\n }\n}\n',
38+
);
3339
final FileContentPair pythonContentPair = FileContentPair(
34-
"if __name__=='__main__':\n sys.exit(\nMain(sys.argv)\n)\n",
35-
"if __name__ == '__main__':\n sys.exit(Main(sys.argv))\n");
40+
"if __name__=='__main__':\n sys.exit(\nMain(sys.argv)\n)\n",
41+
"if __name__ == '__main__':\n sys.exit(Main(sys.argv))\n",
42+
);
3643
final FileContentPair whitespaceContentPair = FileContentPair(
37-
'int main() {\n return 0; \n}\n', 'int main() {\n return 0;\n}\n');
44+
'int main() {\n return 0; \n}\n',
45+
'int main() {\n return 0;\n}\n',
46+
);
3847
final FileContentPair headerContentPair = FileContentPair(
39-
<String>[
40-
'#ifndef FOO_H_',
41-
'#define FOO_H_',
42-
'',
43-
'#endif // FOO_H_',
44-
].join('\n'),
48+
<String>['#ifndef FOO_H_', '#define FOO_H_', '', '#endif // FOO_H_'].join('\n'),
4549
<String>[
4650
'#ifndef FLUTTER_FORMAT_TEST_H_',
4751
'#define FLUTTER_FORMAT_TEST_H_',
@@ -118,55 +122,37 @@ class TestFileFixture {
118122
case target.FormatCheck.clang:
119123
return FileContentPair(
120124
content,
121-
path.extension(file.path) == '.cc'
122-
? ccContentPair.formatted
123-
: hContentPair.formatted,
125+
path.extension(file.path) == '.cc' ? ccContentPair.formatted : hContentPair.formatted,
124126
);
125127
case target.FormatCheck.dart:
126-
return FileContentPair(
127-
content,
128-
dartContentPair.formatted,
129-
);
128+
return FileContentPair(content, dartContentPair.formatted);
130129
case target.FormatCheck.gn:
131-
return FileContentPair(
132-
content,
133-
gnContentPair.formatted,
134-
);
130+
return FileContentPair(content, gnContentPair.formatted);
135131
case target.FormatCheck.java:
136-
return FileContentPair(
137-
content,
138-
javaContentPair.formatted,
139-
);
132+
return FileContentPair(content, javaContentPair.formatted);
140133
case target.FormatCheck.python:
141-
return FileContentPair(
142-
content,
143-
pythonContentPair.formatted,
144-
);
134+
return FileContentPair(content, pythonContentPair.formatted);
145135
case target.FormatCheck.whitespace:
146-
return FileContentPair(
147-
content,
148-
whitespaceContentPair.formatted,
149-
);
136+
return FileContentPair(content, whitespaceContentPair.formatted);
150137
case target.FormatCheck.header:
151-
return FileContentPair(
152-
content,
153-
headerContentPair.formatted,
154-
);
138+
return FileContentPair(content, headerContentPair.formatted);
155139
}
156140
});
157141
}
158142
}
159143

160144
void main() {
161-
final String formatterPath =
162-
'${repoDir.path}/ci/format.${io.Platform.isWindows ? 'bat' : 'sh'}';
145+
final String formatterPath = '${repoDir.path}/ci/format.${io.Platform.isWindows ? 'bat' : 'sh'}';
163146

164147
test('Can fix C++ formatting errors', () {
165148
final TestFileFixture fixture = TestFileFixture(target.FormatCheck.clang);
166149
try {
167150
fixture.gitAdd();
168-
io.Process.runSync(formatterPath, <String>['--check', 'clang', '--fix'],
169-
workingDirectory: repoDir.path);
151+
io.Process.runSync(formatterPath, <String>[
152+
'--check',
153+
'clang',
154+
'--fix',
155+
], workingDirectory: repoDir.path);
170156

171157
final Iterable<FileContentPair> files = fixture.getFileContents();
172158
for (final FileContentPair pair in files) {
@@ -181,8 +167,11 @@ void main() {
181167
final TestFileFixture fixture = TestFileFixture(target.FormatCheck.dart);
182168
try {
183169
fixture.gitAdd();
184-
io.Process.runSync(formatterPath, <String>['--check', 'dart', '--fix'],
185-
workingDirectory: repoDir.path);
170+
io.Process.runSync(formatterPath, <String>[
171+
'--check',
172+
'dart',
173+
'--fix',
174+
], workingDirectory: repoDir.path);
186175

187176
final Iterable<FileContentPair> files = fixture.getFileContents();
188177
for (final FileContentPair pair in files) {
@@ -201,10 +190,11 @@ void main() {
201190

202191
try {
203192
fixture.gitAdd();
204-
final io.ProcessResult result = io.Process.runSync(
205-
formatterPath, <String>['--check', 'dart', '--fix'],
206-
workingDirectory: repoDir.path,
207-
);
193+
final io.ProcessResult result = io.Process.runSync(formatterPath, <String>[
194+
'--check',
195+
'dart',
196+
'--fix',
197+
], workingDirectory: repoDir.path);
208198
expect(result.stdout, contains('format_test2.dart produced the following error'));
209199
expect(result.exitCode, isNot(0));
210200
} finally {
@@ -216,8 +206,11 @@ void main() {
216206
final TestFileFixture fixture = TestFileFixture(target.FormatCheck.gn);
217207
try {
218208
fixture.gitAdd();
219-
io.Process.runSync(formatterPath, <String>['--check', 'gn', '--fix'],
220-
workingDirectory: repoDir.path);
209+
io.Process.runSync(formatterPath, <String>[
210+
'--check',
211+
'gn',
212+
'--fix',
213+
], workingDirectory: repoDir.path);
221214

222215
final Iterable<FileContentPair> files = fixture.getFileContents();
223216
for (final FileContentPair pair in files) {
@@ -232,8 +225,11 @@ void main() {
232225
final TestFileFixture fixture = TestFileFixture(target.FormatCheck.java);
233226
try {
234227
fixture.gitAdd();
235-
io.Process.runSync(formatterPath, <String>['--check', 'java', '--fix'],
236-
workingDirectory: repoDir.path);
228+
io.Process.runSync(formatterPath, <String>[
229+
'--check',
230+
'java',
231+
'--fix',
232+
], workingDirectory: repoDir.path);
237233

238234
final Iterable<FileContentPair> files = fixture.getFileContents();
239235
for (final FileContentPair pair in files) {
@@ -248,8 +244,11 @@ void main() {
248244
final TestFileFixture fixture = TestFileFixture(target.FormatCheck.python);
249245
try {
250246
fixture.gitAdd();
251-
io.Process.runSync(formatterPath, <String>['--check', 'python', '--fix'],
252-
workingDirectory: repoDir.path);
247+
io.Process.runSync(formatterPath, <String>[
248+
'--check',
249+
'python',
250+
'--fix',
251+
], workingDirectory: repoDir.path);
253252

254253
final Iterable<FileContentPair> files = fixture.getFileContents();
255254
for (final FileContentPair pair in files) {
@@ -261,13 +260,14 @@ void main() {
261260
});
262261

263262
test('Can fix whitespace formatting errors', () {
264-
final TestFileFixture fixture =
265-
TestFileFixture(target.FormatCheck.whitespace);
263+
final TestFileFixture fixture = TestFileFixture(target.FormatCheck.whitespace);
266264
try {
267265
fixture.gitAdd();
268-
io.Process.runSync(
269-
formatterPath, <String>['--check', 'whitespace', '--fix'],
270-
workingDirectory: repoDir.path);
266+
io.Process.runSync(formatterPath, <String>[
267+
'--check',
268+
'whitespace',
269+
'--fix',
270+
], workingDirectory: repoDir.path);
271271

272272
final Iterable<FileContentPair> files = fixture.getFileContents();
273273
for (final FileContentPair pair in files) {
@@ -282,11 +282,11 @@ void main() {
282282
final TestFileFixture fixture = TestFileFixture(target.FormatCheck.header);
283283
try {
284284
fixture.gitAdd();
285-
io.Process.runSync(
286-
formatterPath,
287-
<String>['--check', 'header', '--fix'],
288-
workingDirectory: repoDir.path,
289-
);
285+
io.Process.runSync(formatterPath, <String>[
286+
'--check',
287+
'header',
288+
'--fix',
289+
], workingDirectory: repoDir.path);
290290
final Iterable<FileContentPair> files = fixture.getFileContents();
291291
for (final FileContentPair pair in files) {
292292
expect(pair.original, equals(pair.formatted));

engine/src/flutter/examples/glfw/main.dart

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44

55
import 'package:flutter_gpu/gpu.dart' as gpu;
66
import 'package:flutter/material.dart';
7-
import 'package:flutter/foundation.dart'
8-
show debugDefaultTargetPlatformOverride;
7+
import 'package:flutter/foundation.dart' show debugDefaultTargetPlatformOverride;
98

109
void main() {
1110
// Ensure Flutter GPU symbols are available by forcing the GPU context to instantiate.
@@ -14,8 +13,9 @@ void main() {
1413
gpu.gpuContext; // Force the context to instantiate.
1514
} catch (e) {
1615
// If impeller is not enabled, make sure the exception isn't about symbols missing.
17-
assert(e.toString().contains(
18-
'Flutter GPU requires the Impeller rendering backend to be enabled.'));
16+
assert(
17+
e.toString().contains('Flutter GPU requires the Impeller rendering backend to be enabled.'),
18+
);
1919
}
2020

2121
// This is a hack to make Flutter think you are running on Google Fuchsia,
@@ -113,13 +113,8 @@ class _MyHomePageState extends State<MyHomePage> {
113113
// horizontal).
114114
mainAxisAlignment: MainAxisAlignment.center,
115115
children: <Widget>[
116-
Text(
117-
'You have pushed the button this many times:',
118-
),
119-
Text(
120-
'$_counter',
121-
style: Theme.of(context).textTheme.headlineMedium,
122-
),
116+
Text('You have pushed the button this many times:'),
117+
Text('$_counter', style: Theme.of(context).textTheme.headlineMedium),
123118
],
124119
),
125120
),

engine/src/flutter/examples/glfw_drm/main.dart

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,9 @@
33
// found in the LICENSE file.
44

55
import 'package:flutter/material.dart';
6-
import 'package:flutter/foundation.dart'
7-
show debugDefaultTargetPlatformOverride;
6+
import 'package:flutter/foundation.dart' show debugDefaultTargetPlatformOverride;
87
import 'package:flutter_spinkit/flutter_spinkit.dart';
98

10-
119
void main() {
1210
// This is a hack to make Flutter think you are running on Google Fuchsia,
1311
// otherwise you will get an error about running from an unsupported platform.
@@ -71,9 +69,7 @@ class _MyHomePageState extends State<MyHomePage> {
7169
body: Center(
7270
// Center is a layout widget. It takes a single child and positions it
7371
// in the middle of the parent.
74-
child: RepaintBoundary(
75-
child: SpinKitRotatingCircle(color: Colors.blue, size: 50.0),
76-
),
72+
child: RepaintBoundary(child: SpinKitRotatingCircle(color: Colors.blue, size: 50.0)),
7773
),
7874
);
7975
}

engine/src/flutter/flutter_frontend_server/test/to_string_test.dart

Lines changed: 32 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,8 @@ void main() {
1515
if (buildDir == null) {
1616
fail('No build directory found. Set FLUTTER_BUILD_DIRECTORY');
1717
}
18-
final frontendServer = path.join(
19-
buildDir,
20-
'gen',
21-
'frontend_server_aot.dart.snapshot',
22-
);
23-
final sdkRoot = path.join(
24-
buildDir,
25-
'flutter_patched_sdk',
26-
);
18+
final frontendServer = path.join(buildDir, 'gen', 'frontend_server_aot.dart.snapshot');
19+
final sdkRoot = path.join(buildDir, 'flutter_patched_sdk');
2720

2821
final String dart = io.Platform.resolvedExecutable;
2922
final String dartaotruntime = path.join(
@@ -35,11 +28,7 @@ void main() {
3528
final basePath = path.join(engineDir, 'flutter_frontend_server');
3629
final fixtures = path.join(basePath, 'test', 'fixtures');
3730
final mainDart = path.join(fixtures, 'lib', 'main.dart');
38-
final packageConfig = path.join(
39-
fixtures,
40-
'.dart_tool',
41-
'package_config.json',
42-
);
31+
final packageConfig = path.join(fixtures, '.dart_tool', 'package_config.json');
4332
final regularDill = path.join(fixtures, 'toString.dill');
4433
final transformedDill = path.join(fixtures, 'toStringTransformed.dill');
4534

@@ -50,23 +39,26 @@ void main() {
5039
}
5140

5241
test('Without flag', () {
53-
checkProcessResult(io.Process.runSync(dartaotruntime, <String>[
54-
frontendServer,
55-
'--sdk-root=$sdkRoot',
56-
'--target=flutter',
57-
'--packages=$packageConfig',
58-
'--output-dill=$regularDill',
59-
mainDart,
60-
]));
42+
checkProcessResult(
43+
io.Process.runSync(dartaotruntime, <String>[
44+
frontendServer,
45+
'--sdk-root=$sdkRoot',
46+
'--target=flutter',
47+
'--packages=$packageConfig',
48+
'--output-dill=$regularDill',
49+
mainDart,
50+
]),
51+
);
6152
final runResult = io.Process.runSync(dart, <String>[regularDill]);
6253
checkProcessResult(runResult);
6354
var paintString =
64-
'"Paint.toString":"Paint(Color(alpha: 1.0000, red: 1.0000, green: 1.0000, blue: 1.0000, colorSpace: ColorSpace.sRGB))"';
55+
'"Paint.toString":"Paint(Color(alpha: 1.0000, red: 1.0000, green: 1.0000, blue: 1.0000, colorSpace: ColorSpace.sRGB))"';
6556
if (buildDir.contains('release')) {
6657
paintString = '"Paint.toString":"Instance of \'Paint\'"';
6758
}
6859

69-
final String expectedStdout = '{$paintString,'
60+
final String expectedStdout =
61+
'{$paintString,'
7062
'"Brightness.toString":"Brightness.dark",'
7163
'"Foo.toString":"I am a Foo",'
7264
'"Keep.toString":"I am a Keep"}';
@@ -75,22 +67,25 @@ void main() {
7567
});
7668

7769
test('With flag', () {
78-
checkProcessResult(io.Process.runSync(dartaotruntime, <String>[
79-
frontendServer,
80-
'--sdk-root=$sdkRoot',
81-
'--target=flutter',
82-
'--packages=$packageConfig',
83-
'--output-dill=$transformedDill',
84-
'--delete-tostring-package-uri',
85-
'dart:ui',
86-
'--delete-tostring-package-uri',
87-
'package:flutter_frontend_fixtures',
88-
mainDart,
89-
]));
70+
checkProcessResult(
71+
io.Process.runSync(dartaotruntime, <String>[
72+
frontendServer,
73+
'--sdk-root=$sdkRoot',
74+
'--target=flutter',
75+
'--packages=$packageConfig',
76+
'--output-dill=$transformedDill',
77+
'--delete-tostring-package-uri',
78+
'dart:ui',
79+
'--delete-tostring-package-uri',
80+
'package:flutter_frontend_fixtures',
81+
mainDart,
82+
]),
83+
);
9084
final runResult = io.Process.runSync(dart, <String>[transformedDill]);
9185
checkProcessResult(runResult);
9286

93-
const expectedStdout = '{"Paint.toString":"Instance of \'Paint\'",'
87+
const expectedStdout =
88+
'{"Paint.toString":"Instance of \'Paint\'",'
9489
'"Brightness.toString":"Brightness.dark",'
9590
'"Foo.toString":"Instance of \'Foo\'",'
9691
'"Keep.toString":"I am a Keep"}';

0 commit comments

Comments
 (0)