I know people have different opinions on how to format method calls in Objective-C, i.e.
[self presentViewController:scanViewController
animated:YES
completion:nil];
vs
[self presentViewController:scanViewController animated:YES completion:nil];
What options in my .clang-format file do I use to control this indenting? (If I don't want it, colons to line up, etc)
Also, is it just me or is this formatter ignorant of blocks? Notice how the if statement for the success block is not indented, nor is the NSLog function in the failure block.
[self.client getPath:path
parameters:parameters
success:^(AFHTTPRequestOperation *operation, id responseObject) {
if ([from_id isEqualToString:self.from_id]) {
self.image.image = [UIImage imageWithData:responseObject];
}
}
failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(error.description);
}];
Clang-Format is a widely-used C++ code formatter. As it provides an option to define code style options in YAML-formatted files — named . clang-format or _clang-format — these files often become a part of your project where you keep all code style rules.
Standalone Tool clang-format is located in clang/tools/clang-format and can be used to format C/C++/Java/JavaScript/JSON/Objective-C/Protobuf/C# code.
clang-format supports two ways to provide custom style options: directly specify style configuration in the -style= command line option or use -style=file and put style configuration in the . clang-format or _clang-format file in the project directory.
To automatically format a file according to Electron C++ code style, run clang-format -i path/to/electron/file.cc . It should work on macOS/Linux/Windows. The workflow to format your changed code: Make codes changes in Electron repository.
I looked into the clang-format source code where the formatting of objective-c method expressions is done and found it here: http://llvm.org/svn/llvm-project/cfe/trunk/lib/Format/ContinuationIndenter.cpp
The code:
// If this '[' opens an ObjC call, determine whether all parameters fit
// into one line and put one per line if they don't.
if (Current.Type == TT_ObjCMethodExpr &&
getLengthToMatchingParen(Current) + State.Column >
getColumnLimit(State))
BreakBeforeParameter = true;
As you can see the behavior is only controlled by the configuration option ColumnLimit. You could set it to 0 to suppress the line breaks. Unfortunately this has, of course, impact on the complete formatting.
Regarding the problem with the missing indention within blocks: I could not reproduce that with the latest Visual Studio Plugin (SVN r203967). Have you perhaps fiddled with ContinuationIndentWidth?
My variable ColumnLimit is zero. Method calls are formatted like this:
[self presentViewController:scanViewController animated:YES completion:nil];
I would like to format them as follows without changing the ColumnLimit variable:
[self presentViewController:scanViewController
animated:YES
completion:nil];
It seems that there is no clang configuration option to achieve this. However, I found a solution that works for me:
If I add // and a line break right after the first parameter (scanViewController here), formatting the code using clang produces the desired result:
[self presentViewController:scanViewController //
animated:YES
completion:nil];
This means that the clang formatting puts all parameters on separate lines and aligns the colons.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With