Skip to content

Commit

Permalink
Use curly_braces_in_flow_control_structures for foundation, `gest…
Browse files Browse the repository at this point in the history
…ures`, `painting`, `physics` (#104610)

* Use `curly_braces_in_flow_control_structures` for `foundation`

* Use `curly_braces_in_flow_control_structures` for `gestures`

* Use `curly_braces_in_flow_control_structures` for `painting`

* Use `curly_braces_in_flow_control_structures` for `physics`

* fix comments

* remove trailing space

* fix TODO style
  • Loading branch information
guidezpl authored May 25, 2022
1 parent 2b14e99 commit 9cc72df
Show file tree
Hide file tree
Showing 84 changed files with 1,227 additions and 620 deletions.
5 changes: 3 additions & 2 deletions packages/flutter/lib/src/foundation/_bitfield_io.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,11 @@ class BitField<T extends dynamic> implements bitfield.BitField<T> {
void operator []=(T index, bool value) {
final int intIndex = index.index as int;
assert(intIndex < _length);
if (value)
if (value) {
_bits = _bits | (1 << intIndex);
else
} else {
_bits = _bits & ~(1 << intIndex);
}
}

@override
Expand Down
6 changes: 4 additions & 2 deletions packages/flutter/lib/src/foundation/_platform_io.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,14 @@ platform.TargetPlatform get defaultTargetPlatform {
result = platform.TargetPlatform.windows;
}
assert(() {
if (Platform.environment.containsKey('FLUTTER_TEST'))
if (Platform.environment.containsKey('FLUTTER_TEST')) {
result = platform.TargetPlatform.android;
}
return true;
}());
if (platform.debugDefaultTargetPlatformOverride != null)
if (platform.debugDefaultTargetPlatformOverride != null) {
result = platform.debugDefaultTargetPlatformOverride;
}
if (result == null) {
throw FlutterError(
'Unknown platform.\n'
Expand Down
21 changes: 14 additions & 7 deletions packages/flutter/lib/src/foundation/assertions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -622,8 +622,9 @@ class FlutterErrorDetails with Diagnosticable {
longMessage = ' $exception';
}
longMessage = longMessage.trimRight();
if (longMessage.isEmpty)
if (longMessage.isEmpty) {
longMessage = ' <no message available>';
}
return longMessage;
}

Expand Down Expand Up @@ -690,8 +691,9 @@ class FlutterErrorDetails with Diagnosticable {
// strip out that header when we see it.
final String prefix = '${exception.runtimeType}: ';
String message = exceptionAsString();
if (message.startsWith(prefix))
if (message.startsWith(prefix)) {
message = message.substring(prefix.length);
}
properties.add(ErrorSummary(message));
}
}
Expand Down Expand Up @@ -1002,8 +1004,9 @@ class FlutterError extends Error with DiagnosticableTreeMixin implements Asserti
return true;
}());
final bool reportError = isInDebugMode || details.silent != true; // could be null
if (!reportError && !forceReport)
if (!reportError && !forceReport) {
return;
}
if (_errorCount == 0 || forceReport) {
// Diagnostics is only available in debug mode. In profile and release modes fallback to plain print.
if (isInDebugMode) {
Expand Down Expand Up @@ -1115,8 +1118,9 @@ class FlutterError extends Error with DiagnosticableTreeMixin implements Asserti
if (skipped == 1) {
result.add('(elided one frame from ${where.single})');
} else if (skipped > 1) {
if (where.length > 1)
if (where.length > 1) {
where[where.length - 1] = 'and ${where.last}';
}
if (where.length > 2) {
result.add('(elided $skipped frames from ${where.join(", ")})');
} else {
Expand Down Expand Up @@ -1190,8 +1194,9 @@ class FlutterError extends Error with DiagnosticableTreeMixin implements Asserti
///
/// The `label` argument, if present, will be printed before the stack.
void debugPrintStack({StackTrace? stackTrace, String? label, int? maxFrames}) {
if (label != null)
if (label != null) {
debugPrint(label);
}
if (stackTrace == null) {
stackTrace = StackTrace.current;
} else {
Expand All @@ -1208,8 +1213,9 @@ void debugPrintStack({StackTrace? stackTrace, String? label, int? maxFrames}) {
line.contains('dart:sdk_internal');
});
}
if (maxFrames != null)
if (maxFrames != null) {
lines = lines.take(maxFrames);
}
debugPrint(FlutterError.defaultStackFilter(lines).join('\n'));
}

Expand Down Expand Up @@ -1252,8 +1258,9 @@ class DiagnosticsStackTrace extends DiagnosticsBlock {
StackTrace? stack,
IterableFilter<String>? stackFilter,
) {
if (stack == null)
if (stack == null) {
return <DiagnosticsNode>[];
}
final IterableFilter<String> filter = stackFilter ?? FlutterError.defaultStackFilter;
final Iterable<String> frames = filter('${FlutterError.demangleStackTrace(stack)}'.trimRight().split('\n'));
return frames.map<DiagnosticsNode>(_createStackFrame).toList();
Expand Down
12 changes: 8 additions & 4 deletions packages/flutter/lib/src/foundation/basic_types.dart
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,9 @@ class CachingIterable<E> extends IterableBase<E> {
}

bool _fillNext() {
if (!_prefillIterator.moveNext())
if (!_prefillIterator.moveNext()) {
return false;
}
_results.add(_prefillIterator.current);
return true;
}
Expand All @@ -207,18 +208,21 @@ class _LazyListIterator<E> implements Iterator<E> {
@override
E get current {
assert(_index >= 0); // called "current" before "moveNext()"
if (_index < 0 || _index == _owner._results.length)
if (_index < 0 || _index == _owner._results.length) {
throw StateError('current can not be call after moveNext has returned false');
}
return _owner._results[_index];
}

@override
bool moveNext() {
if (_index >= _owner._results.length)
if (_index >= _owner._results.length) {
return false;
}
_index += 1;
if (_index == _owner._results.length)
if (_index == _owner._results.length) {
return _owner._fillNext();
}
return true;
}
}
Expand Down
3 changes: 2 additions & 1 deletion packages/flutter/lib/src/foundation/binding.dart
Original file line number Diff line number Diff line change
Expand Up @@ -827,8 +827,9 @@ abstract class BindingBase {
developer.registerExtension(methodName, (String method, Map<String, String> parameters) async {
assert(method == methodName);
assert(() {
if (debugInstrumentationEnabled)
if (debugInstrumentationEnabled) {
debugPrint('service extension method received: $method($parameters)');
}
return true;
}());

Expand Down
15 changes: 10 additions & 5 deletions packages/flutter/lib/src/foundation/change_notifier.dart
Original file line number Diff line number Diff line change
Expand Up @@ -225,20 +225,23 @@ class ChangeNotifier implements Listenable {
final List<VoidCallback?> newListeners = List<VoidCallback?>.filled(_count, null);

// Listeners before the index are at the same place.
for (int i = 0; i < index; i++)
for (int i = 0; i < index; i++) {
newListeners[i] = _listeners[i];
}

// Listeners after the index move towards the start of the list.
for (int i = index; i < _count; i++)
for (int i = index; i < _count; i++) {
newListeners[i] = _listeners[i + 1];
}

_listeners = newListeners;
} else {
// When there are more listeners than half the length of the list, we only
// shift our listeners, so that we avoid to reallocate memory for the
// whole list.
for (int i = index; i < _count; i++)
for (int i = index; i < _count; i++) {
_listeners[i] = _listeners[i + 1];
}
_listeners[_count] = null;
}
}
Expand Down Expand Up @@ -319,8 +322,9 @@ class ChangeNotifier implements Listenable {
@pragma('vm:notify-debugger-on-exception')
void notifyListeners() {
assert(debugAssertNotDisposed());
if (_count == 0)
if (_count == 0) {
return;
}

// To make sure that listeners removed during this iteration are not called,
// we set them to null, but we don't shrink the list right away.
Expand Down Expand Up @@ -439,8 +443,9 @@ class ValueNotifier<T> extends ChangeNotifier implements ValueListenable<T> {
T get value => _value;
T _value;
set value(T newValue) {
if (_value == newValue)
if (_value == newValue) {
return;
}
_value = newValue;
notifyListeners();
}
Expand Down
33 changes: 22 additions & 11 deletions packages/flutter/lib/src/foundation/collections.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,19 @@
/// * [listEquals], which does something similar for lists.
/// * [mapEquals], which does something similar for maps.
bool setEquals<T>(Set<T>? a, Set<T>? b) {
if (a == null)
if (a == null) {
return b == null;
if (b == null || a.length != b.length)
}
if (b == null || a.length != b.length) {
return false;
if (identical(a, b))
}
if (identical(a, b)) {
return true;
}
for (final T value in a) {
if (!b.contains(value))
if (!b.contains(value)) {
return false;
}
}
return true;
}
Expand All @@ -49,15 +53,19 @@ bool setEquals<T>(Set<T>? a, Set<T>? b) {
/// * [setEquals], which does something similar for sets.
/// * [mapEquals], which does something similar for maps.
bool listEquals<T>(List<T>? a, List<T>? b) {
if (a == null)
if (a == null) {
return b == null;
if (b == null || a.length != b.length)
}
if (b == null || a.length != b.length) {
return false;
if (identical(a, b))
}
if (identical(a, b)) {
return true;
}
for (int index = 0; index < a.length; index += 1) {
if (a[index] != b[index])
if (a[index] != b[index]) {
return false;
}
}
return true;
}
Expand All @@ -78,12 +86,15 @@ bool listEquals<T>(List<T>? a, List<T>? b) {
/// * [setEquals], which does something similar for sets.
/// * [listEquals], which does something similar for lists.
bool mapEquals<T, U>(Map<T, U>? a, Map<T, U>? b) {
if (a == null)
if (a == null) {
return b == null;
if (b == null || a.length != b.length)
}
if (b == null || a.length != b.length) {
return false;
if (identical(a, b))
}
if (identical(a, b)) {
return true;
}
for (final T key in a.keys) {
if (!b.containsKey(key) || b[key] != a[key]) {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,9 @@ Future<Uint8List> consolidateHttpClientResponseBytes(
final _OutputBuffer output = _OutputBuffer();
ByteConversionSink sink = output;
int? expectedContentLength = response.contentLength;
if (expectedContentLength == -1)
if (expectedContentLength == -1) {
expectedContentLength = null;
}
switch (response.compressionState) {
case HttpClientResponseCompressionState.compressed:
if (autoUncompress) {
Expand Down
3 changes: 2 additions & 1 deletion packages/flutter/lib/src/foundation/debug.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ bool debugAssertAllFoundationVarsUnset(String reason, { DebugPrintCallback debug
if (debugPrint != debugPrintOverride ||
debugDefaultTargetPlatformOverride != null ||
debugDoublePrecision != null ||
debugBrightnessOverride != null)
debugBrightnessOverride != null) {
throw FlutterError(reason);
}
return true;
}());
return true;
Expand Down
Loading

0 comments on commit 9cc72df

Please sign in to comment.