From 1039bb218a699816685567cf7740295dbd022299 Mon Sep 17 00:00:00 2001 From: Michael Rebello Date: Fri, 7 Jun 2019 14:01:54 -0700 Subject: [PATCH 1/4] remove .clang-format symlink Signed-off-by: Michael Rebello --- .clang-format | 1 - 1 file changed, 1 deletion(-) delete mode 120000 .clang-format diff --git a/.clang-format b/.clang-format deleted file mode 120000 index 30fec7da9d..0000000000 --- a/.clang-format +++ /dev/null @@ -1 +0,0 @@ -envoy/.clang-format \ No newline at end of file From e6277b177c6b4f9277357baedbbfd9dc9fb3d0c4 Mon Sep 17 00:00:00 2001 From: Michael Rebello Date: Fri, 7 Jun 2019 14:11:27 -0700 Subject: [PATCH 2/4] add .clang-format file Signed-off-by: Michael Rebello --- .clang-format | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 .clang-format diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000000..2e4ab5b447 --- /dev/null +++ b/.clang-format @@ -0,0 +1,28 @@ +--- +Language: Cpp +AccessModifierOffset: -2 +ColumnLimit: 100 +DerivePointerAlignment: false +PointerAlignment: Left +SortIncludes: false +... + +--- +Language: ObjC +AccessModifierOffset: -2 +ColumnLimit: 100 +DerivePointerAlignment: false +IndentWidth: 2 +ObjCBlockIndentWidth: 2 +ObjCSpaceAfterProperty: true +ObjCSpaceBeforeProtocolList: true +PointerAlignment: Left +SortIncludes: false +... + +--- +Language: Proto +ColumnLimit: 100 +SpacesInContainerLiterals: false +AllowShortFunctionsOnASingleLine: false +... From 9c968b0d52a3c54ee33c6324a72a006cdf9573c9 Mon Sep 17 00:00:00 2001 From: Michael Rebello Date: Fri, 7 Jun 2019 14:11:32 -0700 Subject: [PATCH 3/4] run the formatter Signed-off-by: Michael Rebello --- .../objective-c/hello_world/AppDelegate.h | 4 +- .../objective-c/hello_world/ViewController.h | 4 +- .../objective-c/hello_world/ViewController.mm | 135 ++++++++++-------- tools/check_format.sh | 2 +- 4 files changed, 79 insertions(+), 66 deletions(-) diff --git a/examples/objective-c/hello_world/AppDelegate.h b/examples/objective-c/hello_world/AppDelegate.h index e1fe1bf304..0eb7c9e802 100644 --- a/examples/objective-c/hello_world/AppDelegate.h +++ b/examples/objective-c/hello_world/AppDelegate.h @@ -1,8 +1,10 @@ #import #import +// NOLINT(namespace-envoy) + @interface AppDelegate : UIResponder -@property (strong, nonatomic) UIWindow *window; +@property (strong, nonatomic) UIWindow* window; @end diff --git a/examples/objective-c/hello_world/ViewController.h b/examples/objective-c/hello_world/ViewController.h index 922e5721e8..be08213772 100644 --- a/examples/objective-c/hello_world/ViewController.h +++ b/examples/objective-c/hello_world/ViewController.h @@ -1,4 +1,6 @@ #import -@interface ViewController: UITableViewController +// NOLINT(namespace-envoy) + +@interface ViewController : UITableViewController @end diff --git a/examples/objective-c/hello_world/ViewController.mm b/examples/objective-c/hello_world/ViewController.mm index b4027ecf06..4dacc054bc 100644 --- a/examples/objective-c/hello_world/ViewController.mm +++ b/examples/objective-c/hello_world/ViewController.mm @@ -3,14 +3,14 @@ #pragma mark - Constants -NSString *_CELL_ID = @"cell-id"; -NSString *_ENDPOINT = @"http://0.0.0.0:9001/api.lyft.com/static/demo/hello_world.txt"; +NSString* _CELL_ID = @"cell-id"; +NSString* _ENDPOINT = @"http://0.0.0.0:9001/api.lyft.com/static/demo/hello_world.txt"; #pragma mark - ResponseValue -@interface ResponseValue: NSObject -@property (nonatomic, strong) NSString *body; -@property (nonatomic, strong) NSString *serverHeader; +@interface ResponseValue : NSObject +@property (nonatomic, strong) NSString* body; +@property (nonatomic, strong) NSString* serverHeader; @end @implementation ResponseValue @@ -19,8 +19,8 @@ @implementation ResponseValue #pragma mark - ViewController @interface ViewController () -@property (nonatomic, strong) NSMutableArray *responses; -@property (nonatomic, weak) NSTimer *requestTimer; +@property (nonatomic, strong) NSMutableArray* responses; +@property (nonatomic, weak) NSTimer* requestTimer; @end @implementation ViewController @@ -28,86 +28,95 @@ @implementation ViewController #pragma mark - Lifecycle - (instancetype)init { - self = [super init]; - if (self) { - self.responses = [NSMutableArray new]; - self.tableView.allowsSelection = FALSE; - } - return self; + self = [super init]; + if (self) { + self.responses = [NSMutableArray new]; + self.tableView.allowsSelection = FALSE; + } + return self; } - (void)dealloc { - [self.requestTimer invalidate]; - self.requestTimer = nil; + [self.requestTimer invalidate]; + self.requestTimer = nil; } - (void)viewDidLoad { - [super viewDidLoad]; - [self startRequests]; + [super viewDidLoad]; + [self startRequests]; } #pragma mark - Requests - (void)startRequests { - // Note that the first delay will give Envoy time to start up. - self.requestTimer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(performRequest) userInfo:nil repeats:true]; + // Note that the first delay will give Envoy time to start up. + self.requestTimer = [NSTimer scheduledTimerWithTimeInterval:1.0 + target:self + selector:@selector(performRequest) + userInfo:nil + repeats:true]; } - (void)performRequest { - NSURLSession *session = [NSURLSession sharedSession]; - NSURL *url = [NSURL URLWithString:_ENDPOINT]; - NSURLRequest *request = [NSURLRequest requestWithURL:url]; - NSLog(@"Starting request to '%@'", url.path); - - __weak ViewController *weakSelf = self; - NSURLSessionDataTask *task = [session dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) { - if (error == nil && [(NSHTTPURLResponse *)response statusCode] == 200) { - [weakSelf handleResponse:(NSHTTPURLResponse *)response data:data]; - } else { - NSLog(@"Received error: %@", error); - } - }]; - [task resume]; + NSURLSession* session = [NSURLSession sharedSession]; + NSURL* url = [NSURL URLWithString:_ENDPOINT]; + NSURLRequest* request = [NSURLRequest requestWithURL:url]; + NSLog(@"Starting request to '%@'", url.path); + + __weak ViewController* weakSelf = self; + NSURLSessionDataTask* task = + [session dataTaskWithRequest:request + completionHandler:^(NSData* data, NSURLResponse* response, NSError* error) { + if (error == nil && [(NSHTTPURLResponse*)response statusCode] == 200) { + [weakSelf handleResponse:(NSHTTPURLResponse*)response data:data]; + } else { + NSLog(@"Received error: %@", error); + } + }]; + [task resume]; } -- (void)handleResponse:(NSHTTPURLResponse *)response data:(NSData *)data { - NSString *body = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; - if (body == nil || response == nil) { - NSLog(@"Failed to deserialize response string"); - return; - } - - ResponseValue *value = [ResponseValue new]; - value.body = body; - value.serverHeader = [[response allHeaderFields] valueForKey:@"Server"]; - - NSLog(@"Response:\n%ld bytes\n%@\n%@", data.length, body, [response allHeaderFields]); - dispatch_async(dispatch_get_main_queue(), ^{ - [self.responses addObject:value]; - [self.tableView reloadData]; - }); +- (void)handleResponse:(NSHTTPURLResponse*)response data:(NSData*)data { + NSString* body = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; + if (body == nil || response == nil) { + NSLog(@"Failed to deserialize response string"); + return; + } + + ResponseValue* value = [ResponseValue new]; + value.body = body; + value.serverHeader = [[response allHeaderFields] valueForKey:@"Server"]; + + NSLog(@"Response:\n%ld bytes\n%@\n%@", data.length, body, [response allHeaderFields]); + dispatch_async(dispatch_get_main_queue(), ^{ + [self.responses addObject:value]; + [self.tableView reloadData]; + }); } #pragma mark - UITableView -- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { - return 1; +- (NSInteger)numberOfSectionsInTableView:(UITableView*)tableView { + return 1; } -- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { - return self.responses.count; +- (NSInteger)tableView:(UITableView*)tableView numberOfRowsInSection:(NSInteger)section { + return self.responses.count; } -- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { - UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:_CELL_ID]; - if (cell == nil) { - cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:_CELL_ID]; - } - - ResponseValue *response = self.responses[indexPath.row]; - cell.textLabel.text = [NSString stringWithFormat:@"Response: %@", response.body]; - cell.detailTextLabel.text = [NSString stringWithFormat:@"'Server' header: %@", response.serverHeader]; - return cell; +- (UITableViewCell*)tableView:(UITableView*)tableView + cellForRowAtIndexPath:(NSIndexPath*)indexPath { + UITableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:_CELL_ID]; + if (cell == nil) { + cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle + reuseIdentifier:_CELL_ID]; + } + + ResponseValue* response = self.responses[indexPath.row]; + cell.textLabel.text = [NSString stringWithFormat:@"Response: %@", response.body]; + cell.detailTextLabel.text = + [NSString stringWithFormat:@"'Server' header: %@", response.serverHeader]; + return cell; } @end diff --git a/tools/check_format.sh b/tools/check_format.sh index 5fe4ca2723..b624abc87c 100755 --- a/tools/check_format.sh +++ b/tools/check_format.sh @@ -16,6 +16,6 @@ fi # TODO(mattklein123): We don't need envoy_package() in various files. Somehow fix in upstream # checker. envoy/tools/check_format.py \ - --add-excluded-prefixes ./envoy/ ./envoy_build_config/extensions_build_config.bzl ./WORKSPACE ./examples/objective-c/ \ + --add-excluded-prefixes ./envoy/ ./envoy_build_config/extensions_build_config.bzl ./WORKSPACE ./dist/Envoy.framework/ \ --skip_envoy_build_rule_check "$ENVOY_FORMAT_ACTION" envoy/tools/format_python_tools.sh check From db9927affafb07f4adf07f226ac0817a5334c553 Mon Sep 17 00:00:00 2001 From: Michael Rebello Date: Fri, 7 Jun 2019 14:34:43 -0700 Subject: [PATCH 4/4] CR - Add TODO Signed-off-by: Michael Rebello --- tools/check_format.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tools/check_format.sh b/tools/check_format.sh index b624abc87c..cd195d4994 100755 --- a/tools/check_format.sh +++ b/tools/check_format.sh @@ -12,7 +12,8 @@ fi # TODO(mattklein123): WORKSPACE is excluded due to warning about @bazel_tools reference. Fix here # or in the upstream checker. -# TODO(mattklein123): Objective-C is excluded because the clang-format setup is not correct. Fix. +# TODO(mattklein123): Add support upstream for whitelisting paths that don't need to have +# NOLINT(namespace-envoy), such as Objective-C. # TODO(mattklein123): We don't need envoy_package() in various files. Somehow fix in upstream # checker. envoy/tools/check_format.py \