Skip to content

Commit 4120857

Browse files
authored
Fix 'google-readability-braces-around-statements' analyzer warning in macOS and iOS (flutter#29723)
1 parent 99b7a88 commit 4120857

24 files changed

+266
-145
lines changed

flow/display_list_canvas_unittests.cc

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1287,14 +1287,18 @@ class CanvasCompareTester {
12871287
const uint32_t* test_row = test_pixels.addr32(0, y);
12881288
for (int x = 0; x < width; x++) {
12891289
if (bounds && test_row[x] != untouched) {
1290-
if (minX > x)
1290+
if (minX > x) {
12911291
minX = x;
1292-
if (minY > y)
1292+
}
1293+
if (minY > y) {
12931294
minY = y;
1294-
if (maxX <= x)
1295+
}
1296+
if (maxX <= x) {
12951297
maxX = x + 1;
1296-
if (maxY <= y)
1298+
}
1299+
if (maxY <= y) {
12971300
maxY = y + 1;
1301+
}
12981302
if (!i_bounds.contains(x, y)) {
12991303
pixels_oob++;
13001304
}

flow/display_list_unittests.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -859,8 +859,9 @@ static sk_sp<DisplayList> Build(size_t g_index, size_t v_index) {
859859
for (size_t i = 0; i < allGroups.size(); i++) {
860860
DisplayListInvocationGroup& group = allGroups[i];
861861
size_t j = (i == g_index ? v_index : 0);
862-
if (j >= group.variants.size())
862+
if (j >= group.variants.size()) {
863863
continue;
864+
}
864865
DisplayListInvocation& invocation = group.variants[j];
865866
op_count += invocation.op_count();
866867
byte_count += invocation.raw_byte_count();

fml/platform/darwin/string_range_sanitization.mm

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@ NSRange RangeForCharacterAtIndex(NSString* text, NSUInteger index) {
1010
if (text == nil || index > text.length) {
1111
return NSMakeRange(NSNotFound, 0);
1212
}
13-
if (index < text.length)
13+
if (index < text.length) {
1414
return [text rangeOfComposedCharacterSequenceAtIndex:index];
15+
}
1516
return NSMakeRange(index, 0);
1617
}
1718

lib/ui/window/window.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,9 @@ void Window::DispatchPointerDataPacket(const PointerDataPacket& packet) {
3939
void Window::DispatchKeyDataPacket(const KeyDataPacket& packet,
4040
uint64_t response_id) {
4141
std::shared_ptr<tonic::DartState> dart_state = library_.dart_state().lock();
42-
if (!dart_state)
42+
if (!dart_state) {
4343
return;
44+
}
4445
tonic::DartState::Scope scope(dart_state);
4546

4647
const std::vector<uint8_t>& buffer = packet.data();

runtime/dart_snapshot.cc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,10 +250,12 @@ const uint8_t* DartSnapshot::GetInstructionsMapping() const {
250250
}
251251

252252
bool DartSnapshot::IsDontNeedSafe() const {
253-
if (data_ && !data_->IsDontNeedSafe())
253+
if (data_ && !data_->IsDontNeedSafe()) {
254254
return false;
255-
if (instructions_ && !instructions_->IsDontNeedSafe())
255+
}
256+
if (instructions_ && !instructions_->IsDontNeedSafe()) {
256257
return false;
258+
}
257259
return true;
258260
}
259261

shell/common/platform_view.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,9 @@ void PlatformView::UpdateSemantics(SemanticsNodeUpdates update,
113113

114114
void PlatformView::HandlePlatformMessage(
115115
std::unique_ptr<PlatformMessage> message) {
116-
if (auto response = message->response())
116+
if (auto response = message->response()) {
117117
response->CompleteEmpty();
118+
}
118119
}
119120

120121
void PlatformView::OnPreEngineRestart() const {}

shell/common/rasterizer.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,8 +272,9 @@ sk_sp<SkImage> Rasterizer::DoMakeRasterSnapshot(
272272
snapshot_surface = surface_.get();
273273
} else if (snapshot_surface_producer_) {
274274
pbuffer_surface = snapshot_surface_producer_->CreateSnapshotSurface();
275-
if (pbuffer_surface && pbuffer_surface->GetContext())
275+
if (pbuffer_surface && pbuffer_surface->GetContext()) {
276276
snapshot_surface = pbuffer_surface.get();
277+
}
277278
}
278279

279280
if (!snapshot_surface) {

shell/common/shell.cc

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1212,15 +1212,18 @@ void Shell::HandleEngineSkiaMessage(std::unique_ptr<PlatformMessage> message) {
12121212
rapidjson::Document document;
12131213
document.Parse(reinterpret_cast<const char*>(data.GetMapping()),
12141214
data.GetSize());
1215-
if (document.HasParseError() || !document.IsObject())
1215+
if (document.HasParseError() || !document.IsObject()) {
12161216
return;
1217+
}
12171218
auto root = document.GetObject();
12181219
auto method = root.FindMember("method");
1219-
if (method->value != "Skia.setResourceCacheMaxBytes")
1220+
if (method->value != "Skia.setResourceCacheMaxBytes") {
12201221
return;
1222+
}
12211223
auto args = root.FindMember("args");
1222-
if (args == root.MemberEnd() || !args->value.IsInt())
1224+
if (args == root.MemberEnd() || !args->value.IsInt()) {
12231225
return;
1226+
}
12241227

12251228
task_runners_.GetRasterTaskRunner()->PostTask(
12261229
[rasterizer = rasterizer_->GetWeakPtr(), max_bytes = args->value.GetInt(),

shell/common/vsync_waiter_fallback.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@ static fml::TimePoint SnapToNextTick(fml::TimePoint value,
1717
fml::TimePoint tick_phase,
1818
fml::TimeDelta tick_interval) {
1919
fml::TimeDelta offset = (tick_phase - value) % tick_interval;
20-
if (offset != fml::TimeDelta::Zero())
20+
if (offset != fml::TimeDelta::Zero()) {
2121
offset = offset + tick_interval;
22+
}
2223
return value + offset;
2324
}
2425

shell/platform/darwin/common/framework/Source/FlutterChannels.mm

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,9 @@ - (void)sendMessage:(id)message {
6161

6262
- (void)sendMessage:(id)message reply:(FlutterReply)callback {
6363
FlutterBinaryReply reply = ^(NSData* data) {
64-
if (callback)
64+
if (callback) {
6565
callback([_codec decode:data]);
66+
}
6667
};
6768
[_messenger sendOnChannel:_name message:[_codec encode:message] binaryReply:reply];
6869
}
@@ -118,10 +119,12 @@ - (void)dealloc {
118119
}
119120

120121
- (BOOL)isEqual:(id)object {
121-
if (self == object)
122+
if (self == object) {
122123
return YES;
123-
if (![object isKindOfClass:[FlutterError class]])
124+
}
125+
if (![object isKindOfClass:[FlutterError class]]) {
124126
return NO;
127+
}
125128
FlutterError* other = (FlutterError*)object;
126129
return [self.code isEqual:other.code] &&
127130
((!self.message && !other.message) || [self.message isEqual:other.message]) &&
@@ -154,10 +157,12 @@ - (void)dealloc {
154157
}
155158

156159
- (BOOL)isEqual:(id)object {
157-
if (self == object)
160+
if (self == object) {
158161
return YES;
159-
if (![object isKindOfClass:[FlutterMethodCall class]])
162+
}
163+
if (![object isKindOfClass:[FlutterMethodCall class]]) {
160164
return NO;
165+
}
161166
FlutterMethodCall* other = (FlutterMethodCall*)object;
162167
return [self.method isEqual:[other method]] &&
163168
((!self.arguments && !other.arguments) || [self.arguments isEqual:other.arguments]);
@@ -242,12 +247,13 @@ - (void)setMethodCallHandler:(FlutterMethodCallHandler)handler {
242247
FlutterBinaryMessageHandler messageHandler = ^(NSData* message, FlutterBinaryReply callback) {
243248
FlutterMethodCall* call = [codec decodeMethodCall:message];
244249
handler(call, ^(id result) {
245-
if (result == FlutterMethodNotImplemented)
250+
if (result == FlutterMethodNotImplemented) {
246251
callback(nil);
247-
else if ([result isKindOfClass:[FlutterError class]])
252+
} else if ([result isKindOfClass:[FlutterError class]]) {
248253
callback([codec encodeErrorEnvelope:(FlutterError*)result]);
249-
else
254+
} else {
250255
callback([codec encodeSuccessEnvelope:result]);
256+
}
251257
});
252258
};
253259
_connection = [_messenger setMessageHandlerOnChannel:_name binaryMessageHandler:messageHandler];
@@ -309,23 +315,26 @@ static void SetStreamHandlerMessageHandlerOnChannel(NSObject<FlutterStreamHandle
309315
if ([call.method isEqual:@"listen"]) {
310316
if (currentSink) {
311317
FlutterError* error = [handler onCancelWithArguments:nil];
312-
if (error)
318+
if (error) {
313319
NSLog(@"Failed to cancel existing stream: %@. %@ (%@)", error.code, error.message,
314320
error.details);
321+
}
315322
}
316323
currentSink = ^(id event) {
317-
if (event == FlutterEndOfEventStream)
324+
if (event == FlutterEndOfEventStream) {
318325
[messenger sendOnChannel:name message:nil];
319-
else if ([event isKindOfClass:[FlutterError class]])
326+
} else if ([event isKindOfClass:[FlutterError class]]) {
320327
[messenger sendOnChannel:name message:[codec encodeErrorEnvelope:(FlutterError*)event]];
321-
else
328+
} else {
322329
[messenger sendOnChannel:name message:[codec encodeSuccessEnvelope:event]];
330+
}
323331
};
324332
FlutterError* error = [handler onListenWithArguments:call.arguments eventSink:currentSink];
325-
if (error)
333+
if (error) {
326334
callback([codec encodeErrorEnvelope:error]);
327-
else
335+
} else {
328336
callback([codec encodeSuccessEnvelope:nil]);
337+
}
329338
} else if ([call.method isEqual:@"cancel"]) {
330339
if (!currentSink) {
331340
callback(
@@ -336,10 +345,11 @@ static void SetStreamHandlerMessageHandlerOnChannel(NSObject<FlutterStreamHandle
336345
}
337346
currentSink = nil;
338347
FlutterError* error = [handler onCancelWithArguments:call.arguments];
339-
if (error)
348+
if (error) {
340349
callback([codec encodeErrorEnvelope:error]);
341-
else
350+
} else {
342351
callback([codec encodeSuccessEnvelope:nil]);
352+
}
343353
} else {
344354
callback(nil);
345355
}

shell/platform/darwin/common/framework/Source/FlutterCodecs.mm

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,19 @@ + (instancetype)sharedInstance {
3535
}
3636

3737
- (NSData*)encode:(id)message {
38-
if (message == nil)
38+
if (message == nil) {
3939
return nil;
40+
}
4041
NSAssert([message isKindOfClass:[NSString class]], @"");
4142
NSString* stringMessage = message;
4243
const char* utf8 = stringMessage.UTF8String;
4344
return [NSData dataWithBytes:utf8 length:strlen(utf8)];
4445
}
4546

4647
- (NSString*)decode:(NSData*)message {
47-
if (message == nil)
48+
if (message == nil) {
4849
return nil;
50+
}
4951
return [[[NSString alloc] initWithData:message encoding:NSUTF8StringEncoding] autorelease];
5052
}
5153
@end
@@ -60,8 +62,9 @@ + (instancetype)sharedInstance {
6062
}
6163

6264
- (NSData*)encode:(id)message {
63-
if (message == nil)
65+
if (message == nil) {
6466
return nil;
67+
}
6568
NSData* encoding;
6669
if ([message isKindOfClass:[NSArray class]] || [message isKindOfClass:[NSDictionary class]]) {
6770
encoding = [NSJSONSerialization dataWithJSONObject:message options:0 error:nil];
@@ -78,8 +81,9 @@ - (NSData*)encode:(id)message {
7881
}
7982

8083
- (id)decode:(NSData*)message {
81-
if ([message length] == 0)
84+
if ([message length] == 0) {
8285
return nil;
86+
}
8387
BOOL isSimpleValue = NO;
8488
id decoded = nil;
8589
if (0 < message.length) {
@@ -143,8 +147,9 @@ - (FlutterMethodCall*)decodeMethodCall:(NSData*)message {
143147

144148
- (id)decodeEnvelope:(NSData*)envelope {
145149
NSArray* array = [[FlutterJSONMessageCodec sharedInstance] decode:envelope];
146-
if (array.count == 1)
150+
if (array.count == 1) {
147151
return [self unwrapNil:array[0]];
152+
}
148153
NSAssert(array.count == 3, @"Invalid JSON envelope");
149154
id code = array[0];
150155
id message = [self unwrapNil:array[1]];

shell/platform/darwin/common/framework/Source/FlutterStandardCodec.mm

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,19 @@ - (void)dealloc {
3636
}
3737

3838
- (NSData*)encode:(id)message {
39-
if (message == nil)
39+
if (message == nil) {
4040
return nil;
41+
}
4142
NSMutableData* data = [NSMutableData dataWithCapacity:32];
4243
FlutterStandardWriter* writer = [_readerWriter writerWithData:data];
4344
[writer writeValue:message];
4445
return data;
4546
}
4647

4748
- (id)decode:(NSData*)message {
48-
if ([message length] == 0)
49+
if ([message length] == 0) {
4950
return nil;
51+
}
5052
FlutterStandardReader* reader = [_readerWriter readerWithData:message];
5153
id value = [reader readValue];
5254
NSAssert(![reader hasMore], @"Corrupted standard message");
@@ -193,10 +195,12 @@ - (void)dealloc {
193195
}
194196

195197
- (BOOL)isEqual:(id)object {
196-
if (self == object)
198+
if (self == object) {
197199
return YES;
198-
if (![object isKindOfClass:[FlutterStandardTypedData class]])
200+
}
201+
if (![object isKindOfClass:[FlutterStandardTypedData class]]) {
199202
return NO;
203+
}
200204
FlutterStandardTypedData* other = (FlutterStandardTypedData*)object;
201205
return self.type == other.type && self.elementCount == other.elementCount &&
202206
[self.data isEqual:other.data];

shell/platform/darwin/common/framework/Source/flutter_standard_codec_unittest.mm

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,28 @@
99
void checkEncodeDecode(id value, NSData* expectedEncoding) {
1010
FlutterStandardMessageCodec* codec = [FlutterStandardMessageCodec sharedInstance];
1111
NSData* encoded = [codec encode:value];
12-
if (expectedEncoding == nil)
12+
if (expectedEncoding == nil) {
1313
ASSERT_TRUE(encoded == nil);
14-
else
14+
} else {
1515
ASSERT_TRUE([encoded isEqual:expectedEncoding]);
16+
}
1617
id decoded = [codec decode:encoded];
17-
if (value == nil || value == [NSNull null])
18+
if (value == nil || value == [NSNull null]) {
1819
ASSERT_TRUE(decoded == nil);
19-
else
20+
} else {
2021
ASSERT_TRUE([value isEqual:decoded]);
22+
}
2123
}
2224

2325
void checkEncodeDecode(id value) {
2426
FlutterStandardMessageCodec* codec = [FlutterStandardMessageCodec sharedInstance];
2527
NSData* encoded = [codec encode:value];
2628
id decoded = [codec decode:encoded];
27-
if (value == nil || value == [NSNull null])
29+
if (value == nil || value == [NSNull null]) {
2830
ASSERT_TRUE(decoded == nil);
29-
else
31+
} else {
3032
ASSERT_TRUE([value isEqual:decoded]);
33+
}
3134
}
3235

3336
TEST(FlutterStandardCodec, CanDecodeZeroLength) {

shell/platform/darwin/ios/framework/Source/FlutterPlatformPlugin.mm

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -136,19 +136,21 @@ - (void)setSystemChromePreferredOrientations:(NSArray*)orientations {
136136
mask |= UIInterfaceOrientationMaskAll;
137137
} else {
138138
for (NSString* orientation in orientations) {
139-
if ([orientation isEqualToString:@"DeviceOrientation.portraitUp"])
139+
if ([orientation isEqualToString:@"DeviceOrientation.portraitUp"]) {
140140
mask |= UIInterfaceOrientationMaskPortrait;
141-
else if ([orientation isEqualToString:@"DeviceOrientation.portraitDown"])
141+
} else if ([orientation isEqualToString:@"DeviceOrientation.portraitDown"]) {
142142
mask |= UIInterfaceOrientationMaskPortraitUpsideDown;
143-
else if ([orientation isEqualToString:@"DeviceOrientation.landscapeLeft"])
143+
} else if ([orientation isEqualToString:@"DeviceOrientation.landscapeLeft"]) {
144144
mask |= UIInterfaceOrientationMaskLandscapeLeft;
145-
else if ([orientation isEqualToString:@"DeviceOrientation.landscapeRight"])
145+
} else if ([orientation isEqualToString:@"DeviceOrientation.landscapeRight"]) {
146146
mask |= UIInterfaceOrientationMaskLandscapeRight;
147+
}
147148
}
148149
}
149150

150-
if (!mask)
151+
if (!mask) {
151152
return;
153+
}
152154
[[NSNotificationCenter defaultCenter]
153155
postNotificationName:@(kOrientationUpdateNotificationName)
154156
object:nil
@@ -205,8 +207,9 @@ - (void)restoreSystemChromeSystemUIOverlays {
205207

206208
- (void)setSystemChromeSystemUIOverlayStyle:(NSDictionary*)message {
207209
NSString* brightness = message[@"statusBarBrightness"];
208-
if (brightness == (id)[NSNull null])
210+
if (brightness == (id)[NSNull null]) {
209211
return;
212+
}
210213

211214
UIStatusBarStyle statusBarStyle;
212215
if ([brightness isEqualToString:@"Brightness.dark"]) {

0 commit comments

Comments
 (0)