Подтвердить что ты не робот

Clang-format: прекратите ломать длинные методы вверх

При попытке настроить файл .clang-формата для проекта с использованием Objective-C, я столкнулся с проблемой, когда даже при максимальной ширине линии длинными методами Objective-C вырезаются на несколько строк. Например, это:

AFHTTPRequestOperation *returnOperation = [self POST:endpoint parameters:nil constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
        [formData appendPartWithFormData:[[secureStore valueForKey:storeKey] dataUsingEncoding:NSUTF8StringEncoding] name:tokenKey];
        if ([provider isEqualToString:kTwitterKey]) {
            [formData appendPartWithFormData:[[secureStore twitterSecretToken] dataUsingEncoding:NSUTF8StringEncoding] name:kTwitterSecretKey];
            [formData appendPartWithFormData:[email dataUsingEncoding:NSUTF8StringEncoding] name:kEmailKey];
        }
        [formData appendPartWithFormData:[[secureStore token] dataUsingEncoding:NSUTF8StringEncoding] name:tokenKey];
    } success:^(AFHTTPRequestOperation *operation, NSDictionary *response) {
        [secureStore setToken:response[kTokenKey]];
        if (completionHandler) {
            completionHandler(nil, response);
        }
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        if (completionHandler) {
            completionHandler(error, nil);
        }
    }];

превращается в это:

AFHTTPRequestOperation *returnOperation = [self POST:endpoint
        parameters:nil
        constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
          [formData appendPartWithFormData:[[secureStore valueForKey:storeKey] dataUsingEncoding:NSUTF8StringEncoding] name:tokenKey];
          if ([provider isEqualToString:kTwitterKey]) {
              [formData appendPartWithFormData:[[secureStore twitterSecretToken] dataUsingEncoding:NSUTF8StringEncoding] name:kTwitterSecretKey];
              [formData appendPartWithFormData:[email dataUsingEncoding:NSUTF8StringEncoding] name:kEmailKey];
          }
          [formData appendPartWithFormData:[[secureStore token] dataUsingEncoding:NSUTF8StringEncoding] name:kTokenKey];
        }
        success:^(AFHTTPRequestOperation *operation, NSDictionary *response) {
          [secureStore setToken:response[kTokenKey]];
          if (completionHandler) {
              completionHandler(nil, response);
          }
        }
        failure:^(AFHTTPRequestOperation *operation, NSError *error) {
          if (completionHandler) {
              completionHandler(error, nil);
          }
        }];

Я хотел бы оставить расщепление методов на несколько строк разработчику, но, тем не менее, для проверки правильности размещения фигур, тем не менее, требуется проверка форматирования. Также будут оценены предложения о том, как исправить этот странный внутренний отступ.

Изменить: Вот мой файл .clang-format, если кому-то интересно. Я пытаюсь воспроизвести стили New York Times Objective-C, в основном.

---
Language: Cpp
AccessModifierOffset: -2
AlignAfterOpenBracket: false
AlignEscapedNewlinesLeft: false
AlignOperands: false
AlignTrailingComments: true
AllowAllParametersOfDeclarationOnNextLine: false
AllowShortBlocksOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: false
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: false
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: false
BinPackArguments: true
BinPackParameters: true
BreakBeforeBinaryOperators: false
BreakBeforeBraces: Stroustrup
BreakBeforeTernaryOperators: false
BreakConstructorInitializersBeforeComma: false
ColumnLimit: 0
CommentPragmas: '^ IWYU pragma:'
ConstructorInitializerAllOnOneLineOrOnePerLine: false
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: true
DerivePointerAlignment: false
ExperimentalAutoDetectBinPacking: false
IndentCaseLabels: true
IndentWrappedFunctionNames: false
IndentWidth: 4
KeepEmptyLinesAtTheStartOfBlocks: false
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
ObjCBlockIndentWidth: 4
ObjCSpaceAfterProperty: true
ObjCSpaceBeforeProtocolList: false
PenaltyBreakBeforeFirstCallParameter: 0
PenaltyBreakComment: 0
PenaltyBreakFirstLessLess: 0
PenaltyBreakString: 0
PenaltyExcessCharacter: 0
PenaltyReturnTypeOnItsOwnLine: 0
PointerAlignment: Right
SpaceAfterCStyleCast: false
SpaceBeforeAssignmentOperators: true
SpaceBeforeParens: ControlStatements
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1
SpacesInAngles: false
SpacesInContainerLiterals: true
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard: Cpp11
TabWidth: 8
UseTab: Never
4b9b3361

Ответ 1

Я использую следующую конфигурацию, которая не разрушит длинный метод

BasedOnStyle: LLVM
IndentWidth: 4
AllowShortIfStatementsOnASingleLine: true
IndentCaseLabels: false
ColumnLimit: 0

И вы можете установить LLVM с помощью команды

clang-format -style=llvm -dump-config > .clang-format