Skip to content

Commit 74cfc3d

Browse files
authored
Use curly_braces_in_flow_control_structures for non-flutter packages (#104629)
* Use `curly_braces_in_flow_control_structures` for `packages/flutter_driver` * Use `curly_braces_in_flow_control_structures` for `packages/flutter_goldens` * Use `curly_braces_in_flow_control_structures` for `packages/flutter_goldens_client` * Use `curly_braces_in_flow_control_structures` for `packages/flutter_localizations` * Use `curly_braces_in_flow_control_structures` for `packages/flutter_test` * Use `curly_braces_in_flow_control_structures` for `packages/flutter_web_plugins` * fix comments * Use `curly_braces_in_flow_control_structures` for `packages/integration_test` * fix indentation
1 parent a0248eb commit 74cfc3d

34 files changed

+478
-245
lines changed

packages/flutter_driver/lib/src/common/error.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,9 @@ class DriverError extends Error {
2121

2222
@override
2323
String toString() {
24-
if (originalError == null)
24+
if (originalError == null) {
2525
return 'DriverError: $message\n';
26+
}
2627
return '''
2728
DriverError: $message
2829
Original error: $originalError

packages/flutter_driver/lib/src/common/find.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,8 +205,9 @@ class ByValueKey extends SerializableFinder {
205205
ByValueKey(this.keyValue)
206206
: keyValueString = '$keyValue',
207207
keyValueType = '${keyValue.runtimeType}' {
208-
if (!_supportedKeyValueTypes.contains(keyValue.runtimeType))
208+
if (!_supportedKeyValueTypes.contains(keyValue.runtimeType)) {
209209
throw _createInvalidKeyValueTypeError('$keyValue.runtimeType');
210+
}
210211
}
211212

212213
/// The true value of the key.

packages/flutter_driver/lib/src/common/handler_factory.dart

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -260,8 +260,9 @@ mixin CommandHandlerFactory {
260260
'This feature was deprecated after v1.9.3.'
261261
)
262262
Future<Result> _waitUntilNoTransientCallbacks(Command command) async {
263-
if (SchedulerBinding.instance.transientCallbackCount != 0)
263+
if (SchedulerBinding.instance.transientCallbackCount != 0) {
264264
await _waitUntilFrame(() => SchedulerBinding.instance.transientCallbackCount == 0);
265+
}
265266
return Result.empty;
266267
}
267268

@@ -310,8 +311,9 @@ mixin CommandHandlerFactory {
310311
node = renderObject.debugSemantics;
311312
renderObject = renderObject.parent as RenderObject?;
312313
}
313-
if (node == null)
314+
if (node == null) {
314315
throw StateError('No semantics data found');
316+
}
315317
return GetSemanticsIdResult(node.id);
316318
}
317319

@@ -464,26 +466,30 @@ mixin CommandHandlerFactory {
464466

465467
/// Runs `finder` repeatedly until it finds one or more [Element]s.
466468
Future<Finder> waitForElement(Finder finder) async {
467-
if (_frameSync)
469+
if (_frameSync) {
468470
await _waitUntilFrame(() => SchedulerBinding.instance.transientCallbackCount == 0);
471+
}
469472

470473
await _waitUntilFrame(() => finder.evaluate().isNotEmpty);
471474

472-
if (_frameSync)
475+
if (_frameSync) {
473476
await _waitUntilFrame(() => SchedulerBinding.instance.transientCallbackCount == 0);
477+
}
474478

475479
return finder;
476480
}
477481

478482
/// Runs `finder` repeatedly until it finds zero [Element]s.
479483
Future<Finder> waitForAbsentElement(Finder finder) async {
480-
if (_frameSync)
484+
if (_frameSync) {
481485
await _waitUntilFrame(() => SchedulerBinding.instance.transientCallbackCount == 0);
486+
}
482487

483488
await _waitUntilFrame(() => finder.evaluate().isEmpty);
484489

485-
if (_frameSync)
490+
if (_frameSync) {
486491
await _waitUntilFrame(() => SchedulerBinding.instance.transientCallbackCount == 0);
492+
}
487493

488494
return finder;
489495
}

packages/flutter_driver/lib/src/common/message.dart

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@ abstract class Command {
1717

1818
static Duration? _parseTimeout(Map<String, String> json) {
1919
final String? timeout = json['timeout'];
20-
if (timeout == null)
20+
if (timeout == null) {
2121
return null;
22+
}
2223
return Duration(milliseconds: int.parse(timeout));
2324
}
2425

@@ -52,8 +53,9 @@ abstract class Command {
5253
final Map<String, String> result = <String, String>{
5354
'command': kind,
5455
};
55-
if (timeout != null)
56+
if (timeout != null) {
5657
result['timeout'] = '${timeout!.inMilliseconds}';
58+
}
5759
return result;
5860
}
5961
}

packages/flutter_driver/lib/src/common/wait.dart

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,9 @@ class NoTransientCallbacks extends SerializableWaitCondition {
9595
/// The [json] argument must not be null.
9696
factory NoTransientCallbacks.deserialize(Map<String, String> json) {
9797
assert(json != null);
98-
if (json['conditionName'] != 'NoTransientCallbacksCondition')
98+
if (json['conditionName'] != 'NoTransientCallbacksCondition') {
9999
throw SerializationException('Error occurred during deserializing the NoTransientCallbacksCondition JSON string: $json');
100+
}
100101
return const NoTransientCallbacks();
101102
}
102103

@@ -115,8 +116,9 @@ class NoPendingFrame extends SerializableWaitCondition {
115116
/// The [json] argument must not be null.
116117
factory NoPendingFrame.deserialize(Map<String, String> json) {
117118
assert(json != null);
118-
if (json['conditionName'] != 'NoPendingFrameCondition')
119+
if (json['conditionName'] != 'NoPendingFrameCondition') {
119120
throw SerializationException('Error occurred during deserializing the NoPendingFrameCondition JSON string: $json');
121+
}
120122
return const NoPendingFrame();
121123
}
122124

@@ -135,8 +137,9 @@ class FirstFrameRasterized extends SerializableWaitCondition {
135137
/// The [json] argument must not be null.
136138
factory FirstFrameRasterized.deserialize(Map<String, String> json) {
137139
assert(json != null);
138-
if (json['conditionName'] != 'FirstFrameRasterizedCondition')
140+
if (json['conditionName'] != 'FirstFrameRasterizedCondition') {
139141
throw SerializationException('Error occurred during deserializing the FirstFrameRasterizedCondition JSON string: $json');
142+
}
140143
return const FirstFrameRasterized();
141144
}
142145

@@ -158,8 +161,9 @@ class NoPendingPlatformMessages extends SerializableWaitCondition {
158161
/// The [json] argument must not be null.
159162
factory NoPendingPlatformMessages.deserialize(Map<String, String> json) {
160163
assert(json != null);
161-
if (json['conditionName'] != 'NoPendingPlatformMessagesCondition')
164+
if (json['conditionName'] != 'NoPendingPlatformMessagesCondition') {
162165
throw SerializationException('Error occurred during deserializing the NoPendingPlatformMessagesCondition JSON string: $json');
166+
}
163167
return const NoPendingPlatformMessages();
164168
}
165169

@@ -181,8 +185,9 @@ class CombinedCondition extends SerializableWaitCondition {
181185
/// The [jsonMap] argument must not be null.
182186
factory CombinedCondition.deserialize(Map<String, String> jsonMap) {
183187
assert(jsonMap != null);
184-
if (jsonMap['conditionName'] != 'CombinedCondition')
188+
if (jsonMap['conditionName'] != 'CombinedCondition') {
185189
throw SerializationException('Error occurred during deserializing the CombinedCondition JSON string: $jsonMap');
190+
}
186191
if (jsonMap['conditions'] == null) {
187192
return const CombinedCondition(<SerializableWaitCondition>[]);
188193
}

packages/flutter_driver/lib/src/driver/timeline_summary.dart

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -410,23 +410,26 @@ class TimelineSummary {
410410
}
411411

412412
double _averageInMillis(Iterable<Duration> durations) {
413-
if (durations.isEmpty)
413+
if (durations.isEmpty) {
414414
throw ArgumentError('durations is empty!');
415+
}
415416
final double total = durations.fold<double>(0.0, (double t, Duration duration) => t + duration.inMicroseconds.toDouble() / 1000.0);
416417
return total / durations.length;
417418
}
418419

419420
double _percentileInMillis(Iterable<Duration> durations, double percentile) {
420-
if (durations.isEmpty)
421+
if (durations.isEmpty) {
421422
throw ArgumentError('durations is empty!');
423+
}
422424
assert(percentile >= 0.0 && percentile <= 100.0);
423425
final List<double> doubles = durations.map<double>((Duration duration) => duration.inMicroseconds.toDouble() / 1000.0).toList();
424426
return findPercentile(doubles, percentile);
425427
}
426428

427429
double _maxInMillis(Iterable<Duration> durations) {
428-
if (durations.isEmpty)
430+
if (durations.isEmpty) {
429431
throw ArgumentError('durations is empty!');
432+
}
430433
return durations
431434
.map<double>((Duration duration) => duration.inMicroseconds.toDouble() / 1000.0)
432435
.reduce(math.max);

packages/flutter_driver/lib/src/driver/vmservice_driver.dart

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -321,14 +321,16 @@ class VMServiceFlutterDriver extends FlutterDriver {
321321
stackTrace,
322322
);
323323
}
324-
if ((response['isError'] as bool?) ?? false)
324+
if ((response['isError'] as bool?) ?? false) {
325325
throw DriverError('Error in Flutter application: ${response['response']}');
326+
}
326327
return response['response'] as Map<String, dynamic>;
327328
}
328329

329330
void _logCommunication(String message) {
330-
if (_printCommunication)
331+
if (_printCommunication) {
331332
_log(message);
333+
}
332334
if (_logCommunicationToFile) {
333335
assert(_logFilePathName != null);
334336
final f.File file = fs.file(_logFilePathName);
@@ -533,8 +535,9 @@ String _getWebSocketUrl(String url) {
533535
if (uri.pathSegments.isNotEmpty) uri.pathSegments.first,
534536
'ws',
535537
];
536-
if (uri.scheme == 'http')
538+
if (uri.scheme == 'http') {
537539
uri = uri.replace(scheme: 'ws', pathSegments: pathSegments);
540+
}
538541
return uri.toString();
539542
}
540543

packages/flutter_driver/lib/src/extension/extension.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,8 +377,9 @@ class FlutterDriverExtension with DeserializeFinderFactory, CreateFinderFactory,
377377
return _makeResponse(message, isError: true);
378378
} catch (error, stackTrace) {
379379
final String message = 'Uncaught extension error while executing $commandKind: $error\n$stackTrace';
380-
if (!_silenceErrors)
380+
if (!_silenceErrors) {
381381
_log(message);
382+
}
382383
return _makeResponse(message, isError: true);
383384
}
384385
}

packages/flutter_driver/lib/src/extension/wait_conditions.dart

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,9 @@ class _InternalNoTransientCallbacksCondition implements WaitCondition {
4343
/// The [condition] argument must not be null.
4444
factory _InternalNoTransientCallbacksCondition.deserialize(SerializableWaitCondition condition) {
4545
assert(condition != null);
46-
if (condition.conditionName != 'NoTransientCallbacksCondition')
46+
if (condition.conditionName != 'NoTransientCallbacksCondition') {
4747
throw SerializationException('Error occurred during deserializing from the given condition: ${condition.serialize()}');
48+
}
4849
return const _InternalNoTransientCallbacksCondition();
4950
}
5051

@@ -71,8 +72,9 @@ class _InternalNoPendingFrameCondition implements WaitCondition {
7172
/// The [condition] argument must not be null.
7273
factory _InternalNoPendingFrameCondition.deserialize(SerializableWaitCondition condition) {
7374
assert(condition != null);
74-
if (condition.conditionName != 'NoPendingFrameCondition')
75+
if (condition.conditionName != 'NoPendingFrameCondition') {
7576
throw SerializationException('Error occurred during deserializing from the given condition: ${condition.serialize()}');
77+
}
7678
return const _InternalNoPendingFrameCondition();
7779
}
7880

@@ -99,8 +101,9 @@ class _InternalFirstFrameRasterizedCondition implements WaitCondition {
99101
/// The [condition] argument must not be null.
100102
factory _InternalFirstFrameRasterizedCondition.deserialize(SerializableWaitCondition condition) {
101103
assert(condition != null);
102-
if (condition.conditionName != 'FirstFrameRasterizedCondition')
104+
if (condition.conditionName != 'FirstFrameRasterizedCondition') {
103105
throw SerializationException('Error occurred during deserializing from the given condition: ${condition.serialize()}');
106+
}
104107
return const _InternalFirstFrameRasterizedCondition();
105108
}
106109

@@ -125,8 +128,9 @@ class _InternalNoPendingPlatformMessagesCondition implements WaitCondition {
125128
/// The [condition] argument must not be null.
126129
factory _InternalNoPendingPlatformMessagesCondition.deserialize(SerializableWaitCondition condition) {
127130
assert(condition != null);
128-
if (condition.conditionName != 'NoPendingPlatformMessagesCondition')
131+
if (condition.conditionName != 'NoPendingPlatformMessagesCondition') {
129132
throw SerializationException('Error occurred during deserializing from the given condition: ${condition.serialize()}');
133+
}
130134
return const _InternalNoPendingPlatformMessagesCondition();
131135
}
132136

@@ -161,8 +165,9 @@ class _InternalCombinedCondition implements WaitCondition {
161165
/// The [condition] argument must not be null.
162166
factory _InternalCombinedCondition.deserialize(SerializableWaitCondition condition) {
163167
assert(condition != null);
164-
if (condition.conditionName != 'CombinedCondition')
168+
if (condition.conditionName != 'CombinedCondition') {
165169
throw SerializationException('Error occurred during deserializing from the given condition: ${condition.serialize()}');
170+
}
166171
final CombinedCondition combinedCondition = condition as CombinedCondition;
167172
final List<WaitCondition> conditions = combinedCondition.conditions.map(deserializeCondition).toList();
168173
return _InternalCombinedCondition(conditions);

packages/flutter_goldens/lib/flutter_goldens.dart

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -314,8 +314,9 @@ class FlutterPreSubmitFileComparator extends FlutterGoldenFileComparator {
314314
suffix: 'flutter_goldens_presubmit.',
315315
);
316316

317-
if (!baseDirectory.existsSync())
317+
if (!baseDirectory.existsSync()) {
318318
baseDirectory.createSync(recursive: true);
319+
}
319320

320321
goldens ??= SkiaGoldClient(baseDirectory);
321322

@@ -535,8 +536,9 @@ class FlutterLocalFileComparator extends FlutterGoldenFileComparator with LocalC
535536
goldenBytes,
536537
);
537538

538-
if (result.passed)
539+
if (result.passed) {
539540
return true;
541+
}
540542

541543
final String error = await generateFailureOutput(result, golden, basedir);
542544
throw FlutterError(error);

packages/flutter_goldens_client/lib/skia_client.dart

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,9 @@ class SkiaGoldClient {
8383
/// Used by the [FlutterPostSubmitFileComparator] and the
8484
/// [FlutterPreSubmitFileComparator].
8585
Future<void> auth() async {
86-
if (await clientIsAuthorized())
86+
if (await clientIsAuthorized()) {
8787
return;
88+
}
8889
final List<String> authCommand = <String>[
8990
_goldctl,
9091
'auth',
@@ -124,8 +125,9 @@ class SkiaGoldClient {
124125
/// [FlutterPostSubmitFileComparator].
125126
Future<void> imgtestInit() async {
126127
// This client has already been intialized
127-
if (_initialized)
128+
if (_initialized) {
128129
return;
130+
}
129131

130132
final File keys = workDirectory.childFile('keys.json');
131133
final File failures = workDirectory.childFile('failures.json');
@@ -234,8 +236,9 @@ class SkiaGoldClient {
234236
/// [FlutterPreSubmitFileComparator].
235237
Future<void> tryjobInit() async {
236238
// This client has already been initialized
237-
if (_tryjobInitialized)
239+
if (_tryjobInitialized) {
238240
return;
241+
}
239242

240243
final File keys = workDirectory.childFile('keys.json');
241244
final File failures = workDirectory.childFile('failures.json');
@@ -385,8 +388,9 @@ class SkiaGoldClient {
385388
final io.HttpClientResponse response = await request.close();
386389
rawResponse = await utf8.decodeStream(response);
387390
final dynamic jsonResponse = json.decode(rawResponse);
388-
if (jsonResponse is! Map<String, dynamic>)
391+
if (jsonResponse is! Map<String, dynamic>) {
389392
throw const FormatException('Skia gold expectations do not match expected format.');
393+
}
390394
expectation = jsonResponse['digest'] as String?;
391395
} on FormatException catch (error) {
392396
// Ideally we'd use something like package:test's printOnError, but best reliabilty

packages/flutter_localizations/lib/src/material_localizations.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -436,8 +436,9 @@ abstract class GlobalMaterialLocalizations implements MaterialLocalizations {
436436
@override
437437
TimeOfDayFormat timeOfDayFormat({ bool alwaysUse24HourFormat = false }) {
438438
assert(alwaysUse24HourFormat != null);
439-
if (alwaysUse24HourFormat)
439+
if (alwaysUse24HourFormat) {
440440
return _get24HourVersionOf(timeOfDayFormatRaw);
441+
}
441442
return timeOfDayFormatRaw;
442443
}
443444

packages/flutter_localizations/test/test_utils.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@ void encodeBundleTranslations(Map<String, dynamic> bundle) {
77
for (final String key in bundle.keys) {
88
// The ARB file resource "attributes" for foo are called @foo. Don't need
99
// to encode them.
10-
if (key.startsWith('@'))
10+
if (key.startsWith('@')) {
1111
continue;
12+
}
1213
final String translation = bundle[key] as String;
1314
// Rewrite the string as a series of unicode characters in JSON format.
1415
// Like "\u0012\u0123\u1234".

packages/flutter_localizations/test/widgets_test.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1428,8 +1428,9 @@ void main() {
14281428
Locale('de', 'DE'),
14291429
],
14301430
localeResolutionCallback: (Locale? locale, Iterable<Locale> supportedLocales) {
1431-
if (locale == null)
1431+
if (locale == null) {
14321432
return const Locale('und', 'US');
1433+
}
14331434
return const Locale('en', 'US');
14341435
},
14351436
buildContent: (BuildContext context) {

packages/flutter_test/lib/src/_goldens_io.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,11 +173,12 @@ mixin LocalComparisonOutput {
173173
/// Returns a [ComparisonResult] to describe the pixel differential of the
174174
/// [test] and [master] image bytes provided.
175175
Future<ComparisonResult> compareLists(List<int>? test, List<int>? master) async {
176-
if (identical(test, master))
176+
if (identical(test, master)) {
177177
return ComparisonResult(
178178
passed: true,
179179
diffPercent: 0.0,
180180
);
181+
}
181182

182183
if (test == null || master == null || test.isEmpty || master.isEmpty) {
183184
return ComparisonResult(

0 commit comments

Comments
 (0)