iOS 项目接入 Githooks

可以直接查看 github项目,利用git子模块的方式引入到工程中. https://github.com/square/spacecommander

以下是对.clang-format 文件的注释.

# Custom options in the special build of clang-format (these are not standard options)
IndentNestedBlocks: false
AllowNewlineBeforeBlockParameter: false

Language: Cpp
# BasedOnStyle: Google

#类的访问修饰关键字(private,public,protected···)缩进
AccessModifierOffset: -1

#构造函数初始化的缩进值
ConstructorInitializerIndentWidth: 4

#引入头文件排序
SortIncludes: false

#在未封闭(括号的开始和结束不在同一行)的括号中的代码是否对齐
AlignAfterOpenBracket: true

#在(),[],{}中代码不少于一行且换行情况下。如果true则,第二行起代码会尽量向左对齐,否则向最右边对齐。
AlignEscapedNewlinesLeft: true

#如果为true,水平对齐二元和三元表达式的操作数。
AlignOperands: false

#如果为true,对齐各行尾部注释
AlignTrailingComments: true

#如果为true,函数申明多个参数时,允许换行
AllowAllParametersOfDeclarationOnNextLine: false

#如果true,较短的代码片段允许格式化为一行
AllowShortBlocksOnASingleLine: false

#是否允许短switch的case 语句在一行写完
AllowShortCaseLabelsOnASingleLine: false

#是否允许短的方法实现在一行写完
AllowShortFunctionsOnASingleLine: false

#是否允许短if else语句在一行写完
AllowShortIfStatementsOnASingleLine: true

#是否允许短的循环在一行写完
AllowShortLoopsOnASingleLine: true

#定义函数返回类型之后换行
AlwaysBreakAfterDefinitionReturnType: false

#定义模板之后换行
AlwaysBreakTemplateDeclarations: false

#多行字符串之前换行
AlwaysBreakBeforeMultilineStrings: false

#二元操作符之前换行
BreakBeforeBinaryOperators: None

#三元操作符之前换行
BreakBeforeTernaryOperators: false

#在构造函数初始化时按逗号断行,并以冒号对齐
BreakConstructorInitializersBeforeComma: false

#如果false,函数调用时的参数要么是全部占同一行,要么一个参数占一行。
BinPackArguments: true
#如果false,函数的定义或声明的参数要么是全部占同一行,要么一个参数占一行
BinPackParameters: true

#一行代码长度的限制,0为无限制
ColumnLimit: 0
#如果true,构造函数的初始化无法适应于一行以内,那么每个参数占一行
ConstructorInitializerAllOnOneLineOrOnePerLine: true

#如果true,将用使用PointerAlignment的值为指针类型进行格式化
DerivePointerAlignment: false

#如果true,clang-format检测方法的定义和调用是否被格式化为一个参数占据一行
ExperimentalAutoDetectBinPacking: false

#case语句的位置总是在switch语句后缩进一级
IndentCaseLabels: true

#若方法定义或者声明在类型之后换行,自动缩进(true)
IndentWrappedFunctionNames: false

IndentFunctionDeclarationAfterType: false

#持续空行的最大数量
MaxEmptyLinesToKeep: 2

#如果true,在一块代码前的空行将会被保留
KeepEmptyLinesAtTheStartOfBlocks: false

#NameSpace 缩进: None(所有namespace均不缩进);Inner(只在内部namespcae缩进);All(所有namespace均缩进)
NamespaceIndentation: Inner

#OC的block缩进
ObjCBlockIndentWidth: 4

#OC的property与()之间后是否空格,如果true,那么@property(readonly) 代替 @property (readonly).
ObjCSpaceAfterProperty: true

# 前是否空格
ObjCSpaceBeforeProtocolList: true

PenaltyBreakBeforeFirstCallParameter: 10000
PenaltyBreakComment: 300
PenaltyBreakString: 1000
PenaltyBreakFirstLessLess: 120
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 200

#指针在类型那边还是在变量名那边还是在中间
PointerAlignment: Right

#单行注释前的空格数
SpacesBeforeTrailingComments: 1

#如果true,将大括号的列表格式化为最适合C++11的格式。
Cpp11BracedListStyle: true

#LanguageStandard 参考英文文档
Standard: Auto

#缩进的列数
IndentWidth: 4

#制表位列数
TabWidth: 8

#是否使用tab进行缩进
UseTab: Never

#括号的断行模式 (此处为自定义,更多选项可参考官方英文文档)
BreakBeforeBraces: Custom
BraceWrapping:
AfterClass: true
AfterControlStatement: false
AfterEnum: false
AfterFunction: false
AfterNamespace: true
AfterObjCDeclaration: true
AfterStruct: false
AfterUnion: false
BeforeCatch: false
BeforeElse: false
IndentBraces: false

#如果true,在非空的括号中插入空格
SpacesInParentheses: false

#如果true,[]中间插入空格
SpacesInSquareBrackets: false

#如果true,在<>中间插入空格
SpacesInAngles: false

#如果true 空括号中加空格
SpaceInEmptyParentheses: false

#c-style 强制转换中类型前后是否空格 true -> ( int32 )x, false -> (int32)x
SpacesInCStyleCastParentheses: false

#c-style 强制转换类型括号后是否空格 true -> (int32) x, false -> (int32)x
SpaceAfterCStyleCast: false

# true -> [ 1, 2, 3 ] , {a : 1, b : 2, c : 3}; false -> [1, 2, 3], {a: 1, b: 2, c: 3}
SpacesInContainerLiterals: false

# 赋值操作符 = 两侧是否空格 a = 3 vs a=3
SpaceBeforeAssignmentOperators: true

#在续行(\ 下一行)时的缩进长度
ContinuationIndentWidth: 4

CommentPragmas: '^ IWYU pragma:'
ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH ]

#是否在括号前加上空格,此处只是在控制语句之前添加(if/while/for...)
SpaceBeforeParens: ControlStatements

#禁用当前format文件
DisableFormat: false
...

其中 SortIncludes 这个值被设置为true之后,会导致格式化代码之后提交代码任然会提示错误的问题, 可以先设置true,代码全局格式化之后,再改回false.

以上clang-format文件是相对比较符合团队风格的代码风格.也需要在开发中, 不断调整该配置.

参考文档: http://clang.llvm.org/docs/ClangFormatStyleOptions.html

你可能感兴趣的:(iOS 项目接入 Githooks)