gpt4 book ai didi

objective-c - clang-format:停止分解长方法

转载 作者:太空狗 更新时间:2023-10-30 03:20:48 26 4
gpt4 key购买 nike

在尝试使用 Objective-C 为项目设置 .clang 格式文件时,我遇到了一个问题,即即使最大行宽为 0,较长的 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 格式文件,如果有人感兴趣的话。我主要是在尝试复制纽约时报的 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

最佳答案

我正在使用以下不会破坏长方法的配置

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

您可以使用命令获取 LLVM 设置

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

关于objective-c - clang-format:停止分解长方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30110479/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com