例如,我有以下代码:
[self.service loadDataForId:@"id"
successBlock:^(NSDictionary *dictionary) {
NSLog(@"%@", dictionary);
}
errorBlock:^(NSError *error) {
NSLog(@"%@", error);
}];
当我在其上应用clang格式时,它变成:
[self.service loadDataForId:@"id"
successBlock:^(NSDictionary *dictionary) {
NSLog(@"%@", dictionary);
}
errorBlock:^(NSError *error) {
NSLog(@"%@", error);
}];
如您所见,代码未与冒号对齐。
如果我的代码没有errorBlock,则clang格式可以正常工作
[self.service loadDataForId:@"id"
successBlock:^(NSDictionary *dictionary) {
NSLog(@"%@", dictionary);
}
errorBlock:nil];
我使用的是clang格式的版本8.0.0(tags / google / stable / 2019-01-18)。如果我使用预定义的样式(LLVM,Google,Chromium,Mozilla,WebKit),那么我会遇到同样的问题
如何正确设置clang格式?我的以下设置文件:
---
Language: ObjC
AccessModifierOffset: 0
ConstructorInitializerIndentWidth: 4
ObjCBlockIndentWidth: 4
ContinuationIndentWidth: 4
AlignEscapedNewlinesLeft: false
AlignTrailingComments: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
AllowShortFunctionsOnASingleLine: false
AlwaysBreakTemplateDeclarations: false
AlwaysBreakBeforeMultilineStrings: false
BreakBeforeBinaryOperators: All
BreakBeforeTernaryOperators: true
BreakConstructorInitializersBeforeComma: false
BinPackParameters: true
ColumnLimit: 0
IndentWidth: 4
ConstructorInitializerAllOnOneLineOrOnePerLine: false
DerivePointerBinding: false
ExperimentalAutoDetectBinPacking: false
IndentCaseLabels: true
MaxEmptyLinesToKeep: 1
NamespaceIndentation: All
ObjCSpaceAfterProperty: true
ObjCSpaceBeforeProtocolList: false
PenaltyBreakBeforeFirstCallParameter: 19
PenaltyBreakComment: 300
PenaltyBreakString: 1000
PenaltyBreakFirstLessLess: 120
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 60
PointerBindsToType: false
SpacesBeforeTrailingComments: 1
Cpp11BracedListStyle: true
Standard: Cpp11
TabWidth: 4
UseTab: Never
IndentFunctionDeclarationAfterType: true
SpacesInParentheses: false
SpacesInAngles: false
SpaceInEmptyParentheses: false
SpacesInCStyleCastParentheses: false
SpacesInContainerLiterals: false
SpaceBeforeAssignmentOperators: true
CommentPragmas: '^ IWYU pragma:'
SpaceBeforeParens: ControlStatements
AlignOperands: true
BinPackArguments: false
BinPackParameters: false
AlignAfterOpenBracket: Align
ObjCBinPackProtocolList: Never
AllowShortBlocksOnASingleLine: false
BreakBeforeBraces: Custom
BraceWrapping:
AfterEnum: false
AfterStruct: false
SplitEmptyFunction: false
AfterClass: false
AfterControlStatement: false
AfterFunction: false
AfterNamespace: false
AfterObjCDeclaration: false
BeforeCatch: false
AfterExternBlock: false
AfterUnion: false
AfterStruct: false
BeforeElse: false
SplitEmptyFunction: true
SplitEmptyRecord: true
SplitEmptyNamespace: true
IncludeBlocks: Merge
IncludeCategories:
- Regex: '^<.*\.h>'
Priority: -1
- Regex: '^<.*'
Priority: 2
- Regex: '.*'
Priority: 3