Skip to content

Commit f322450

Browse files
authored
Use lints prefer_final_locals, prefer_final_in_for_each. (#4191)
1 parent d5e9892 commit f322450

File tree

172 files changed

+1893
-1795
lines changed

Some content is hidden

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

172 files changed

+1893
-1795
lines changed

_benchmark/lib/config.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class Config {
3636
allowFailures: argResults['allow-failures'] as bool,
3737
buildRepoPath: argResults['build-repo-path'] as String?,
3838
dependencyOverridePaths: {
39-
for (var s in argResults['dependency-override-path'] as List<String>)
39+
for (final s in argResults['dependency-override-path'] as List<String>)
4040
s.split('=')[0]: s.split('=')[1],
4141
},
4242
generator: Generator.values.singleWhere(

_test/lib/app.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ import 'package:web/web.dart';
77
void startApp({String? text}) {
88
text ??= 'Hello World!';
99
// ignore: deprecated_member_use
10-
var component = HTMLDivElement()..text = text;
10+
final component = HTMLDivElement()..text = text;
1111
document.body!.append(component);
1212
}

_test/pkgs/provides_builder/lib/builders.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class _SomePostProcessBuilder extends PostProcessBuilder {
4949

5050
@override
5151
Future<void> build(PostProcessBuildStep buildStep) async {
52-
var content = defaultContent ?? await buildStep.readInputAsString();
52+
final content = defaultContent ?? await buildStep.readInputAsString();
5353
await buildStep.writeAsString(
5454
buildStep.inputId.changeExtension('.txt.post'),
5555
content,

_test/test/build_integration_test.dart

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,30 +22,30 @@ void main() {
2222

2323
group('PostProcessBuilder', () {
2424
test('creates expected outputs', () async {
25-
var generated = await readGeneratedFileAsString(
25+
final generated = await readGeneratedFileAsString(
2626
'_test/lib/hello.txt.post',
2727
);
28-
var original = await File('lib/hello.txt').readAsString();
28+
final original = await File('lib/hello.txt').readAsString();
2929
expect(generated, equals(original));
3030
});
3131

3232
test('can be configured with build.yaml', () async {
3333
await runBuild(trailingArgs: ['--config', 'post_process']);
34-
var generated = await readGeneratedFileAsString(
34+
final generated = await readGeneratedFileAsString(
3535
'_test/lib/hello.txt.post',
3636
);
3737
expect(generated, equals('goodbye'));
3838
});
3939

4040
test('can be configured with --define', () async {
41-
var content = 'cool';
41+
final content = 'cool';
4242
await runBuild(
4343
trailingArgs: [
4444
'--define',
4545
'provides_builder:some_post_process_builder=default_content=$content',
4646
],
4747
);
48-
var generated = await readGeneratedFileAsString(
48+
final generated = await readGeneratedFileAsString(
4949
'_test/lib/hello.txt.post',
5050
);
5151
expect(generated, equals(content));
@@ -57,14 +57,16 @@ void main() {
5757
await replaceAllInFile('lib/hello.txt', 'hello', 'goodbye');
5858
result = await runBuild();
5959
expect(result.stdout, contains('wrote 1 output'));
60-
var content = await readGeneratedFileAsString('_test/lib/hello.txt.post');
60+
final content = await readGeneratedFileAsString(
61+
'_test/lib/hello.txt.post',
62+
);
6163
expect(content, contains('goodbye'));
6264
});
6365
});
6466

6567
group('experiments', () {
6668
test('can serve a single app with experiments enabled', () async {
67-
var result = await runBuild(
69+
final result = await runBuild(
6870
trailingArgs: ['--enable-experiment=fake-experiment'],
6971
);
7072

@@ -126,10 +128,10 @@ void main() {
126128
});
127129

128130
test('Re-snapshots if there is no asset graph', () async {
129-
var assetGraph = assetGraphPathFor(scriptKernelLocation);
131+
final assetGraph = assetGraphPathFor(scriptKernelLocation);
130132
await File(assetGraph).delete();
131133

132-
var nextBuild = await runBuild();
134+
final nextBuild = await runBuild();
133135
expect(
134136
(nextBuild.stdout as String).split('\n'),
135137
containsAllInOrder([

_test/test/common/utils.dart

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ Future<void> _startServer(
8686
.transform(const LineSplitter())
8787
.asBroadcastStream();
8888

89-
var stdErrLines =
89+
final stdErrLines =
9090
proc.stderr
9191
.transform(utf8.decoder)
9292
.transform(const LineSplitter())
@@ -106,7 +106,7 @@ Future<void> stopServer({bool? cleanUp}) async {
106106
final process = _process;
107107
if (process != null) {
108108
expect(process.kill(), true);
109-
var exitCode = process.exitCode;
109+
final exitCode = process.exitCode;
110110
_process = null;
111111
await exitCode;
112112
}
@@ -120,7 +120,7 @@ Future<void> stopServer({bool? cleanUp}) async {
120120
/// Checks whether the current git client is "clean" (no pending changes) for
121121
/// this package directory.
122122
bool _gitIsClean() {
123-
var gitStatus =
123+
final gitStatus =
124124
Process.runSync('git', ['status', '.', '--porcelain']).stdout as String;
125125
return gitStatus.isEmpty;
126126
}
@@ -131,7 +131,7 @@ bool _gitIsClean() {
131131
/// This also calls `addTearDown` with a method that will reset the current git
132132
/// state for this directory after running the test.
133133
void ensureCleanGitClient() {
134-
var gitWasClean = _gitIsClean();
134+
final gitWasClean = _gitIsClean();
135135
expect(
136136
gitWasClean,
137137
isTrue,
@@ -194,7 +194,7 @@ Future<TestProcess> _runTests(
194194
}) async {
195195
usePrecompiled ??= true;
196196
if (usePrecompiled) {
197-
var args =
197+
final args =
198198
scriptArgs.toList()
199199
..add('test')
200200
..add('--verbose')
@@ -203,7 +203,7 @@ Future<TestProcess> _runTests(
203203
..addAll([...?testArgs, '-p', 'chrome', '-r', 'expanded']);
204204
return TestProcess.start(executable, args);
205205
} else {
206-
var args = ['run', 'test', '--pub-serve', '8081', ...?testArgs];
206+
final args = ['run', 'test', '--pub-serve', '8081', ...?testArgs];
207207
return TestProcess.start('dart', args);
208208
}
209209
}
@@ -215,7 +215,7 @@ Future<void> expectTestsFail({
215215
}) async {
216216
// Skip on Windows due to Chrome test flakiness, see
217217
// https://github.com/dart-lang/build/issues/4123.
218-
var result = await runTests(
218+
final result = await runTests(
219219
usePrecompiled: usePrecompiled,
220220
buildArgs: buildArgs,
221221
testArgs: testArgs,
@@ -233,12 +233,12 @@ Future<void> expectTestsPass({
233233
// Skip on Windows due to Chrome test flakiness, see
234234
// https://github.com/dart-lang/build/issues/4123.
235235
if (Platform.isWindows) return;
236-
var result = await runTests(
236+
final result = await runTests(
237237
usePrecompiled: usePrecompiled,
238238
buildArgs: buildArgs,
239239
testArgs: testArgs,
240240
);
241-
var allLines = await result.stdout.rest.toList();
241+
final allLines = await result.stdout.rest.toList();
242242
expect(allLines, contains(contains('All tests passed!')));
243243
if (expectedNumRan != null) {
244244
expect(allLines, contains(contains('+$expectedNumRan')));
@@ -248,27 +248,27 @@ Future<void> expectTestsPass({
248248
}
249249

250250
Future<void> createFile(String path, String contents) async {
251-
var file = File(path);
251+
final file = File(path);
252252
expect(await file.exists(), isFalse);
253253
await file.create(recursive: true);
254254
await file.writeAsString(contents);
255255
}
256256

257257
Future<void> deleteFile(String path) async {
258-
var file = File(path);
258+
final file = File(path);
259259
expect(await file.exists(), isTrue);
260260
await file.delete();
261261
}
262262

263263
Future<String> readGeneratedFileAsString(String path) async {
264-
var file = File(p.join(_generatedDir.path, path));
264+
final file = File(p.join(_generatedDir.path, path));
265265
expect(await file.exists(), isTrue);
266266
return file.readAsString();
267267
}
268268

269269
Future<void> replaceAllInFile(String path, Pattern from, String replace) async {
270-
var file = File(path);
270+
final file = File(path);
271271
expect(await file.exists(), isTrue);
272-
var content = await file.readAsString();
272+
final content = await file.readAsString();
273273
await file.writeAsString(content.replaceAll(from, replace));
274274
}

_test/test/dart2js_integration_test.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const _outputDir = 'dart2js_test';
1818
void main() {
1919
group('Can run tests using dart2js', () {
2020
tearDown(() async {
21-
var dir = Directory(_outputDir);
21+
final dir = Directory(_outputDir);
2222
if (await dir.exists()) {
2323
await dir.delete(recursive: true);
2424
}
@@ -81,20 +81,20 @@ void main() {
8181
}
8282

8383
Future<void> _expectWasCompiledWithDart2JS({bool minified = false}) async {
84-
var jsFile = File(
84+
final jsFile = File(
8585
'$_outputDir/test/hello_world_deferred_test.dart.browser_test.dart.js',
8686
);
8787
expect(await jsFile.exists(), isTrue);
8888
// sanity check that it was indeed compiled with dart2js
89-
var content = await jsFile.readAsString();
89+
final content = await jsFile.readAsString();
9090
if (minified) {
9191
expect(content, isNot(startsWith('//')));
9292
expect(content, contains('typeof dartMainRunner==="function"'));
9393
} else {
9494
expect(content, startsWith('// Generated by dart2js'));
9595
}
9696

97-
var jsDeferredPartFile = File(
97+
final jsDeferredPartFile = File(
9898
'$_outputDir/test/hello_world_deferred_test.dart.browser_test.dart.js'
9999
'_1.part.js',
100100
);

_test/test/exception_handling_test.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@ import 'common/utils.dart';
1111

1212
void main() {
1313
test('Exceptions from the isolate are handled properly', () async {
14-
var asyncResult = runBuild(trailingArgs: ['--config', 'throws']);
14+
final asyncResult = runBuild(trailingArgs: ['--config', 'throws']);
1515
expect(
1616
asyncResult,
1717
completes,
1818
reason:
1919
'Wrapper script should not hang if the isolate has an unhandled '
2020
'error.',
2121
);
22-
var result = await asyncResult;
22+
final result = await asyncResult;
2323
expect(
2424
result.stdout,
2525
contains('Throwing on purpose cause you asked for it!'),

_test/test/generated_script_integration_test.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ void main() {
1717
});
1818

1919
test('Generates a build script matching the golden', () {
20-
var generatedScript =
20+
final generatedScript =
2121
File('.dart_tool/build/entrypoint/build.dart').readAsStringSync();
22-
var expected = File(
22+
final expected = File(
2323
'test/goldens/generated_build_script.dart',
2424
).readAsStringSync().replaceAll('\r', '');
2525
expect(generatedScript, expected);

_test/test/help_test.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,13 @@ void main() {
6363
}
6464

6565
Future<void> _testHelpCommand(List<String> args, {String? checkContent}) async {
66-
var asyncResult = runCommand(args);
66+
final asyncResult = runCommand(args);
6767
expect(
6868
asyncResult,
6969
completes,
7070
reason: 'should not cause the auto build script to hang',
7171
);
72-
var result = await asyncResult;
72+
final result = await asyncResult;
7373
expect(
7474
result.exitCode,
7575
equals(0),

0 commit comments

Comments
 (0)