8

I am using ClangFormat.

I wish to update the style of my ReactiveCocoa code from this

   [[self.myService indexCase] subscribeNext:^(id response) {
        DDLogDebug(@"response : %@", response);
    }
        error:^(NSError *error) {
            [self.dataManager sendError:error];
        }];

to this

  [[self.myService indexCase]
     subscribeNext:^(id response) {
        DDLogDebug(@"response : %@", response);
     } error:^(NSError *error) {
            [self.dataManager sendError:error];
        }];

What ClangFormat attributes should I be looking at to achieve this?


My Current .clang-format file:

BasedOnStyle: WebKit
AlignTrailingComments: true
AllowShortFunctionsOnASingleLine: false
AllowShortIfStatementsOnASingleLine: true
BreakBeforeBraces: Linux
ColumnLimit: 120
IndentCaseLabels: true
IndentWidth: 4
KeepEmptyLinesAtTheStartOfBlocks: false
MaxEmptyLinesToKeep: 2
ObjCSpaceAfterProperty: true
ObjCSpaceBeforeProtocolList: true
PointerBindsToType: false
SpacesBeforeTrailingComments: 1
TabWidth: 4
UseTab: Never
Ríomhaire
  • 3,084
  • 4
  • 25
  • 40

2 Answers2

0

Add this:

AllowAllParametersOfDeclarationOnNextLine True

or

BinPackParameters True
winux
  • 452
  • 4
  • 12
  • That's strange because I'm using this both on XCode. "subscribeNext" is a parameter in Cocoa. What IDE are you using? and on what OS? It might have conflicted with your other settings. Try removing the others one at a time. until you get what you want. – winux Jul 18 '16 at 08:13
0

I put // before the first operator to achieve this. clang-format detects it as a comment and automatically starts on the next line for the rest of the statement. You don't need to put it on each line, usually the first is enough but sometimes not (it also depends on other settings in your .clang-format file).

So it looks a bit like:

[[self.myService indexCase] //
    subscribeNext:^(id response) {
        DDLogDebug(@"response : %@", response);
    } error:^(NSError *error) {
        [self.dataManager sendError:error];
    }];

I use this trick to make clang-format break the code where I want. It's a bit hacky, might even seem ugly to some, but I consider the benefits of increased readability more valuable than occasional empty comment statements so it doesn't hurt my eyes much.

akaralar
  • 1,103
  • 1
  • 10
  • 29