Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit d0871d0

Browse files
sherginfacebook-github-bot
authored andcommittedMar 9, 2020
Clang format for all React Native files
Summary: Buckle up, this enables clang-format prettifier for all files in React Native opensource repo. Changelog: [Internal] Clang-format codemod. Reviewed By: mdvacca Differential Revision: D20331210 fbshipit-source-id: 8da0f94700be0c35bfd399e0c48f1706de04f5b1
1 parent a426c8d commit d0871d0

File tree

198 files changed

+5601
-5284
lines changed

Some content is hidden

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

198 files changed

+5601
-5284
lines changed
 

‎React/Base/RCTAssert.h

+38-35
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,25 @@ RCT_EXTERN BOOL RCTIsMainQueue(void);
2020
* assert handler through `RCTSetAssertFunction`.
2121
*/
2222
#ifndef NS_BLOCK_ASSERTIONS
23-
#define RCTAssert(condition, ...) do { \
24-
if ((condition) == 0) { \
25-
_RCTAssertFormat(#condition, __FILE__, __LINE__, __func__, __VA_ARGS__); \
26-
if (RCT_NSASSERT) { \
27-
[[NSAssertionHandler currentHandler] handleFailureInFunction:(NSString * _Nonnull)@(__func__) \
28-
file:(NSString * _Nonnull)@(__FILE__) lineNumber:__LINE__ description:__VA_ARGS__]; \
29-
} \
30-
} \
31-
} while (false)
23+
#define RCTAssert(condition, ...) \
24+
do { \
25+
if ((condition) == 0) { \
26+
_RCTAssertFormat(#condition, __FILE__, __LINE__, __func__, __VA_ARGS__); \
27+
if (RCT_NSASSERT) { \
28+
[[NSAssertionHandler currentHandler] handleFailureInFunction:(NSString * _Nonnull) @(__func__) \
29+
file:(NSString * _Nonnull) @(__FILE__) \
30+
lineNumber:__LINE__ \
31+
description:__VA_ARGS__]; \
32+
} \
33+
} \
34+
} while (false)
3235
#else
33-
#define RCTAssert(condition, ...) do {} while (false)
36+
#define RCTAssert(condition, ...) \
37+
do { \
38+
} while (false)
3439
#endif
35-
RCT_EXTERN void _RCTAssertFormat(
36-
const char *, const char *, int, const char *, NSString *, ...
37-
) NS_FORMAT_FUNCTION(5,6);
40+
RCT_EXTERN void _RCTAssertFormat(const char *, const char *, int, const char *, NSString *, ...)
41+
NS_FORMAT_FUNCTION(5, 6);
3842

3943
/**
4044
* Report a fatal condition when executing. These calls will _NOT_ be compiled out
@@ -68,11 +72,12 @@ RCT_EXTERN NSString *const RCTFatalExceptionName;
6872
/**
6973
* A block signature to be used for custom assertion handling.
7074
*/
71-
typedef void (^RCTAssertFunction)(NSString *condition,
72-
NSString *fileName,
73-
NSNumber *lineNumber,
74-
NSString *function,
75-
NSString *message);
75+
typedef void (^RCTAssertFunction)(
76+
NSString *condition,
77+
NSString *fileName,
78+
NSNumber *lineNumber,
79+
NSString *function,
80+
NSString *message);
7681

7782
typedef void (^RCTFatalHandler)(NSError *error);
7883
typedef void (^RCTFatalExceptionHandler)(NSException *exception);
@@ -85,14 +90,12 @@ typedef void (^RCTFatalExceptionHandler)(NSException *exception);
8590
/**
8691
* Convenience macro for asserting that we're running on main queue.
8792
*/
88-
#define RCTAssertMainQueue() RCTAssert(RCTIsMainQueue(), \
89-
@"This function must be called on the main queue")
93+
#define RCTAssertMainQueue() RCTAssert(RCTIsMainQueue(), @"This function must be called on the main queue")
9094

9195
/**
9296
* Convenience macro for asserting that we're running off the main queue.
9397
*/
94-
#define RCTAssertNotMainQueue() RCTAssert(!RCTIsMainQueue(), \
95-
@"This function must not be called on the main queue")
98+
#define RCTAssertNotMainQueue() RCTAssert(!RCTIsMainQueue(), @"This function must not be called on the main queue")
9699

97100
/**
98101
* These methods get and set the current assert function called by the RCTAssert
@@ -133,7 +136,8 @@ RCT_EXTERN NSString *RCTCurrentThreadName(void);
133136
/**
134137
* Helper to get generate exception message from NSError
135138
*/
136-
RCT_EXTERN NSString *RCTFormatError(NSString *message, NSArray<NSDictionary<NSString *, id> *> *stacktrace, NSUInteger maxMessageLength);
139+
RCT_EXTERN NSString *
140+
RCTFormatError(NSString *message, NSArray<NSDictionary<NSString *, id> *> *stacktrace, NSUInteger maxMessageLength);
137141

138142
/**
139143
* Formats a JS stack trace for logging.
@@ -145,20 +149,19 @@ RCT_EXTERN NSString *RCTFormatStackTrace(NSArray<NSDictionary<NSString *, id> *>
145149
*/
146150
#if DEBUG
147151

148-
#define RCTAssertThread(thread, format...) \
149-
_Pragma("clang diagnostic push") \
150-
_Pragma("clang diagnostic ignored \"-Wdeprecated-declarations\"") \
151-
RCTAssert( \
152-
[(id)thread isKindOfClass:[NSString class]] ? \
153-
[RCTCurrentThreadName() isEqualToString:(NSString *)thread] : \
154-
[(id)thread isKindOfClass:[NSThread class]] ? \
155-
[NSThread currentThread] == (NSThread *)thread : \
156-
dispatch_get_current_queue() == (dispatch_queue_t)thread, \
157-
format); \
158-
_Pragma("clang diagnostic pop")
152+
#define RCTAssertThread(thread, format...) \
153+
_Pragma("clang diagnostic push") _Pragma("clang diagnostic ignored \"-Wdeprecated-declarations\"") RCTAssert( \
154+
[(id)thread isKindOfClass:[NSString class]] \
155+
? [RCTCurrentThreadName() isEqualToString:(NSString *)thread] \
156+
: [(id)thread isKindOfClass:[NSThread class]] ? [NSThread currentThread] == (NSThread *)thread \
157+
: dispatch_get_current_queue() == (dispatch_queue_t)thread, \
158+
format); \
159+
_Pragma("clang diagnostic pop")
159160

160161
#else
161162

162-
#define RCTAssertThread(thread, format...) do { } while (0)
163+
#define RCTAssertThread(thread, format...) \
164+
do { \
165+
} while (0)
163166

164167
#endif

‎React/Base/RCTAssert.m

+36-29
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,12 @@
2323
NSException *_RCTNotImplementedException(SEL, Class);
2424
NSException *_RCTNotImplementedException(SEL cmd, Class cls)
2525
{
26-
NSString *msg = [NSString stringWithFormat:@"%s is not implemented "
27-
"for the class %@", sel_getName(cmd), cls];
28-
return [NSException exceptionWithName:@"RCTNotDesignatedInitializerException"
29-
reason:msg userInfo:nil];
26+
NSString *msg = [NSString stringWithFormat:
27+
@"%s is not implemented "
28+
"for the class %@",
29+
sel_getName(cmd),
30+
cls];
31+
return [NSException exceptionWithName:@"RCTNotDesignatedInitializerException" reason:msg userInfo:nil];
3032
}
3133

3234
void RCTSetAssertFunction(RCTAssertFunction assertFunction)
@@ -43,15 +45,11 @@ void RCTAddAssertFunction(RCTAssertFunction assertFunction)
4345
{
4446
RCTAssertFunction existing = RCTCurrentAssertFunction;
4547
if (existing) {
46-
RCTCurrentAssertFunction = ^(NSString *condition,
47-
NSString *fileName,
48-
NSNumber *lineNumber,
49-
NSString *function,
50-
NSString *message) {
51-
52-
existing(condition, fileName, lineNumber, function, message);
53-
assertFunction(condition, fileName, lineNumber, function, message);
54-
};
48+
RCTCurrentAssertFunction =
49+
^(NSString *condition, NSString *fileName, NSNumber *lineNumber, NSString *function, NSString *message) {
50+
existing(condition, fileName, lineNumber, function, message);
51+
assertFunction(condition, fileName, lineNumber, function, message);
52+
};
5553
} else {
5654
RCTCurrentAssertFunction = assertFunction;
5755
}
@@ -101,11 +99,12 @@ void RCTPerformBlockWithAssertFunction(void (^block)(void), RCTAssertFunction as
10199
}
102100

103101
void _RCTAssertFormat(
104-
const char *condition,
105-
const char *fileName,
106-
int lineNumber,
107-
const char *function,
108-
NSString *format, ...)
102+
const char *condition,
103+
const char *fileName,
104+
int lineNumber,
105+
const char *function,
106+
NSString *format,
107+
...)
109108
{
110109
RCTAssertFunction assertFunction = RCTGetLocalAssertFunction();
111110
if (assertFunction) {
@@ -143,9 +142,10 @@ void RCTFatal(NSError *error)
143142
// name: RCTFatalException: <underlying error description>
144143
// reason: <underlying error description plus JS stack trace, truncated to 175 characters>
145144
// userInfo: <underlying error userinfo, plus untruncated description plus JS stack trace>
146-
@throw [[NSException alloc] initWithName:name reason:message userInfo:userInfo];
145+
@throw [[NSException alloc] initWithName:name reason:message userInfo:userInfo];
147146
#if DEBUG
148-
} @catch (NSException *e) {}
147+
} @catch (NSException *e) {
148+
}
149149
#endif
150150
}
151151
}
@@ -160,34 +160,40 @@ RCTFatalHandler RCTGetFatalHandler(void)
160160
return RCTCurrentFatalHandler;
161161
}
162162

163-
NSString *RCTFormatError(NSString *message, NSArray<NSDictionary<NSString *, id> *> *stackTrace, NSUInteger maxMessageLength)
163+
NSString *
164+
RCTFormatError(NSString *message, NSArray<NSDictionary<NSString *, id> *> *stackTrace, NSUInteger maxMessageLength)
164165
{
165166
if (maxMessageLength > 0 && message.length > maxMessageLength) {
166167
message = [[message substringToIndex:maxMessageLength] stringByAppendingString:@"..."];
167168
}
168169

169170
NSString *prettyStack = RCTFormatStackTrace(stackTrace);
170171

171-
return [NSString stringWithFormat:@"%@%@%@", message, prettyStack ? @", stack:\n" : @"", prettyStack ? prettyStack : @""];
172+
return [NSString
173+
stringWithFormat:@"%@%@%@", message, prettyStack ? @", stack:\n" : @"", prettyStack ? prettyStack : @""];
172174
}
173175

174-
NSString *RCTFormatStackTrace(NSArray<NSDictionary<NSString *, id> *> *stackTrace) {
176+
NSString *RCTFormatStackTrace(NSArray<NSDictionary<NSString *, id> *> *stackTrace)
177+
{
175178
if (stackTrace) {
176179
NSMutableString *prettyStack = [NSMutableString string];
177180

178-
NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"\\b((?:seg-\\d+(?:_\\d+)?|\\d+)\\.js)"
179-
options:NSRegularExpressionCaseInsensitive
180-
error:NULL];
181+
NSRegularExpression *regex =
182+
[NSRegularExpression regularExpressionWithPattern:@"\\b((?:seg-\\d+(?:_\\d+)?|\\d+)\\.js)"
183+
options:NSRegularExpressionCaseInsensitive
184+
error:NULL];
181185
for (NSDictionary<NSString *, id> *frame in stackTrace) {
182186
NSString *fileName = [frame[@"file"] lastPathComponent];
183-
NSTextCheckingResult *match = fileName != nil ? [regex firstMatchInString:fileName options:0 range:NSMakeRange(0, fileName.length)] : nil;
187+
NSTextCheckingResult *match =
188+
fileName != nil ? [regex firstMatchInString:fileName options:0 range:NSMakeRange(0, fileName.length)] : nil;
184189
if (match) {
185190
fileName = [NSString stringWithFormat:@"%@:", [fileName substringWithRange:match.range]];
186191
} else {
187192
fileName = @"";
188193
}
189194

190-
[prettyStack appendFormat:@"%@@%@%@:%@\n", frame[@"methodName"], fileName, frame[@"lineNumber"], frame[@"column"]];
195+
[prettyStack
196+
appendFormat:@"%@@%@%@:%@\n", frame[@"methodName"], fileName, frame[@"lineNumber"], frame[@"column"]];
191197
}
192198

193199
return prettyStack;
@@ -208,7 +214,8 @@ void RCTFatalException(NSException *exception)
208214
#endif
209215
@throw exception;
210216
#if DEBUG
211-
} @catch (NSException *e) {}
217+
} @catch (NSException *e) {
218+
}
212219
#endif
213220
}
214221
}

0 commit comments

Comments
 (0)
Please sign in to comment.