ClangFormat style for ReactiveCocoa
Asked Answered
L

2

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
Lucie answered 7/7, 2016 at 12:27 Comment(1)
I was looking into something similar about a year ago, but it seemed impossible, so I gave up :(Mabe
D
0

Add this:

AllowAllParametersOfDeclarationOnNextLine True

or

BinPackParameters True
Ditty answered 18/7, 2016 at 4:34 Comment(1)
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.Ditty
D
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.

Dissect answered 27/7, 2016 at 12:34 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.