我是靠谱客的博主 俭朴大神,最近开发中收集的这篇文章主要介绍代码格式化程序(clang-format,astyle,uncrustify)将下面的代码保存为_clang-format或者.clang-format放到被格式化的文件夹下即可Astyle的格式化参数Uncrustify的格式化,觉得挺不错的,现在分享给大家,希望可以做个参考。
概述
将下面的代码保存为_clang-format或者.clang-format放到被格式化的文件夹下即可
- 风格1
最多间隔3行
变量对齐,运算符对齐,行尾注释对齐(连续多行有注释,"//“)
函数短”return“放在一行
”include“按组整理,进行排序(include之间必须连续多行)
---
IndentWidth: 2
# BasedOnStyle: LLVM
---
Language: Cpp
AccessModifierOffset: 0
AlignAfterOpenBracket: Align
AlignConsecutiveAssignments: true
AlignConsecutiveDeclarations: true
AlignEscapedNewlines: Right
AlignOperands: true
AlignTrailingComments: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortBlocksOnASingleLine: true
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: All
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: MultiLine
BinPackArguments: true
BinPackParameters: true
BraceWrapping:
AfterClass: true
AfterControlStatement: true
AfterEnum: true
AfterFunction: true
AfterNamespace: true
AfterObjCDeclaration: true
AfterStruct: true
AfterUnion: true
AfterExternBlock: true
BeforeCatch: true
BeforeElse: true
IndentBraces: false
SplitEmptyFunction: true
SplitEmptyRecord: true
SplitEmptyNamespace: true
BreakBeforeBinaryOperators: None
BreakBeforeBraces: Custom
BreakBeforeInheritanceComma: false
BreakInheritanceList: BeforeColon
BreakBeforeTernaryOperators: true
BreakConstructorInitializersBeforeComma: false
BreakConstructorInitializers: BeforeComma
BreakAfterJavaFieldAnnotations: true
BreakStringLiterals: true
ColumnLimit: 0
CommentPragmas: '^ IWYU pragma:'
CompactNamespaces: true
ConstructorInitializerAllOnOneLineOrOnePerLine: false
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: true
DerivePointerAlignment: false
DisableFormat: false
ExperimentalAutoDetectBinPacking: false
FixNamespaceComments: true
ForEachMacros:
- foreach
- Q_FOREACH
- BOOST_FOREACH
IncludeBlocks: Preserve
IncludeCategories:
- Regex: '^"(llvm|llvm-c|clang|clang-c)/'
Priority: 2
- Regex: '^(<|"(gtest|gmock|isl|json)/)'
Priority: 3
- Regex: '.*'
Priority: 1
IncludeIsMainRegex: '(Test)?$'
IndentCaseLabels: true
IndentPPDirectives: None
IndentWrappedFunctionNames: false
JavaScriptQuotes: Leave
JavaScriptWrapImports: true
KeepEmptyLinesAtTheStartOfBlocks: false
MacroBlockBegin: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 3
NamespaceIndentation: All
ObjCBinPackProtocolList: Auto
ObjCBlockIndentWidth: 2
ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: true
PenaltyBreakAssignment: 2
PenaltyBreakBeforeFirstCallParameter: 19
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakString: 1000
PenaltyBreakTemplateDeclaration: 10
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 60
PointerAlignment: Right
ReflowComments: false
SortIncludes: true
SortUsingDeclarations: true
SpaceAfterCStyleCast: false
SpaceAfterTemplateKeyword: true
SpaceBeforeAssignmentOperators: true
SpaceBeforeCpp11BracedList: false
SpaceBeforeCtorInitializerColon: true
SpaceBeforeInheritanceColon: true
SpaceBeforeParens: ControlStatements
SpaceBeforeRangeBasedForLoopColon: true
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 4
SpacesInAngles: false
SpacesInContainerLiterals: true
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard: Cpp11
TabWidth: 8
UseTab: Never
Astyle的格式化参数
如果在vscode中使用,首先,安装Astyle插件。然后在settings.json中粘贴如下设置。
为了不与clang-format起冲突,需要额外添加一条
"C_Cpp.formatting": "Disabled"
"astyle.cmd_options": [
"--style=allman",
"--style=bsd",
"--style=break",
"--style=ansi",
"--indent=spaces=2",
"--attach-closing-while",
"--indent-switches",
"--indent-namespaces",
"--indent-preproc-block",
"--indent-preproc-define",
"--indent-col1-comments",
"--pad-oper",
"--pad-comma",
"--attach-return-type-decl",
"--keep-one-line-statements",
"-A1"
],
Uncrustify的格式化
这部分研究的不多,建议直接去看官方给出的帮助文件
http://uncrustify.sourceforge.net/config.txt
最后
以上就是俭朴大神为你收集整理的代码格式化程序(clang-format,astyle,uncrustify)将下面的代码保存为_clang-format或者.clang-format放到被格式化的文件夹下即可Astyle的格式化参数Uncrustify的格式化的全部内容,希望文章能够帮你解决代码格式化程序(clang-format,astyle,uncrustify)将下面的代码保存为_clang-format或者.clang-format放到被格式化的文件夹下即可Astyle的格式化参数Uncrustify的格式化所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复