Created
April 3, 2023 01:44
-
-
Save HTLife/920385b97a02f3ad9910ba375ba83255 to your computer and use it in GitHub Desktop.
clang-format examples
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Google C/C++ Code Style settings | |
# https://clang.llvm.org/docs/ClangFormatStyleOptions.html | |
# Author: Kehan Xue, kehan.xue (at) gmail.com | |
Language: Cpp | |
BasedOnStyle: Google | |
AccessModifierOffset: -1 | |
AlignAfterOpenBracket: Align | |
AlignConsecutiveAssignments: None | |
AlignOperands: Align | |
AllowAllArgumentsOnNextLine: true | |
AllowAllConstructorInitializersOnNextLine: true | |
AllowAllParametersOfDeclarationOnNextLine: false | |
AllowShortBlocksOnASingleLine: Empty | |
AllowShortCaseLabelsOnASingleLine: false | |
AllowShortFunctionsOnASingleLine: Inline | |
AllowShortIfStatementsOnASingleLine: Never # To avoid conflict, set this "Never" and each "if statement" should include brace when coding | |
AllowShortLambdasOnASingleLine: Inline | |
AllowShortLoopsOnASingleLine: false | |
AlwaysBreakAfterReturnType: None | |
AlwaysBreakTemplateDeclarations: Yes | |
BinPackArguments: true | |
BreakBeforeBraces: Custom | |
BraceWrapping: | |
AfterCaseLabel: false | |
AfterClass: false | |
AfterStruct: false | |
AfterControlStatement: Never | |
AfterEnum: false | |
AfterFunction: false | |
AfterNamespace: false | |
AfterUnion: false | |
AfterExternBlock: false | |
BeforeCatch: false | |
BeforeElse: false | |
BeforeLambdaBody: false | |
IndentBraces: false | |
SplitEmptyFunction: false | |
SplitEmptyRecord: false | |
SplitEmptyNamespace: false | |
BreakBeforeBinaryOperators: None | |
BreakBeforeTernaryOperators: true | |
BreakConstructorInitializers: BeforeColon | |
BreakInheritanceList: BeforeColon | |
ColumnLimit: 80 | |
CompactNamespaces: false | |
ContinuationIndentWidth: 4 | |
Cpp11BracedListStyle: true | |
DerivePointerAlignment: false # Make sure the * or & align on the left | |
EmptyLineBeforeAccessModifier: LogicalBlock | |
FixNamespaceComments: true | |
IncludeBlocks: Preserve | |
IndentCaseLabels: true | |
IndentPPDirectives: None | |
IndentWidth: 4 | |
KeepEmptyLinesAtTheStartOfBlocks: true | |
MaxEmptyLinesToKeep: 1 | |
NamespaceIndentation: None | |
ObjCSpaceAfterProperty: false | |
ObjCSpaceBeforeProtocolList: true | |
PointerAlignment: Left | |
ReflowComments: false | |
# SeparateDefinitionBlocks: Always # Only support for clang-format 14 | |
SpaceAfterCStyleCast: false | |
SpaceAfterLogicalNot: false | |
SpaceAfterTemplateKeyword: true | |
SpaceBeforeAssignmentOperators: true | |
SpaceBeforeCpp11BracedList: false | |
SpaceBeforeCtorInitializerColon: true | |
SpaceBeforeInheritanceColon: true | |
SpaceBeforeParens: ControlStatements | |
SpaceBeforeRangeBasedForLoopColon: true | |
SpaceBeforeSquareBrackets: false | |
SpaceInEmptyParentheses: false | |
SpacesBeforeTrailingComments: 2 | |
SpacesInAngles: false | |
SpacesInCStyleCastParentheses: false | |
SpacesInContainerLiterals: false | |
SpacesInParentheses: false | |
SpacesInSquareBrackets: false | |
Standard: c++11 | |
TabWidth: 4 | |
UseTab: Never |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
Language: Cpp | |
# BasedOnStyle: LLVM | |
AccessModifierOffset: -2 | |
AlignAfterOpenBracket: Align | |
AlignConsecutiveMacros: false | |
AlignConsecutiveAssignments: false | |
AlignConsecutiveDeclarations: false | |
AlignEscapedNewlines: Right | |
AlignOperands: true | |
AlignTrailingComments: true | |
AllowAllArgumentsOnNextLine: true | |
AllowAllConstructorInitializersOnNextLine: true | |
AllowAllParametersOfDeclarationOnNextLine: true | |
AllowShortBlocksOnASingleLine: Never | |
AllowShortCaseLabelsOnASingleLine: false | |
AllowShortFunctionsOnASingleLine: All | |
AllowShortLambdasOnASingleLine: All | |
AllowShortIfStatementsOnASingleLine: Never | |
AllowShortLoopsOnASingleLine: false | |
AlwaysBreakAfterDefinitionReturnType: None | |
AlwaysBreakAfterReturnType: None | |
AlwaysBreakBeforeMultilineStrings: false | |
AlwaysBreakTemplateDeclarations: MultiLine | |
BinPackArguments: true | |
BinPackParameters: true | |
BraceWrapping: | |
AfterCaseLabel: false | |
AfterClass: false | |
AfterControlStatement: false | |
AfterEnum: false | |
AfterFunction: false | |
AfterNamespace: false | |
AfterObjCDeclaration: false | |
AfterStruct: false | |
AfterUnion: false | |
AfterExternBlock: false | |
BeforeCatch: false | |
BeforeElse: false | |
IndentBraces: false | |
SplitEmptyFunction: true | |
SplitEmptyRecord: true | |
SplitEmptyNamespace: true | |
BreakBeforeBinaryOperators: None | |
BreakBeforeBraces: Attach | |
BreakBeforeInheritanceComma: false | |
BreakInheritanceList: BeforeColon | |
BreakBeforeTernaryOperators: true | |
BreakConstructorInitializersBeforeComma: false | |
BreakConstructorInitializers: BeforeColon | |
BreakAfterJavaFieldAnnotations: false | |
BreakStringLiterals: true | |
ColumnLimit: 80 | |
CommentPragmas: '^ IWYU pragma:' | |
CompactNamespaces: false | |
ConstructorInitializerAllOnOneLineOrOnePerLine: false | |
ConstructorInitializerIndentWidth: 4 | |
ContinuationIndentWidth: 4 | |
Cpp11BracedListStyle: true | |
DeriveLineEnding: true | |
DerivePointerAlignment: false | |
DisableFormat: false | |
ExperimentalAutoDetectBinPacking: false | |
FixNamespaceComments: true | |
ForEachMacros: | |
- foreach | |
- Q_FOREACH | |
- BOOST_FOREACH | |
IncludeBlocks: Regroup | |
IncludeCategories: | |
- Regex: '^"(llvm|llvm-c|clang|clang-c)/' | |
Priority: 2 | |
SortPriority: 0 | |
- Regex: '^(<|"(gtest|gmock|isl|json)/)' | |
Priority: 3 | |
SortPriority: 0 | |
- Regex: '.*' | |
Priority: 1 | |
SortPriority: 0 | |
IncludeIsMainRegex: '(Test)?$' | |
IncludeIsMainSourceRegex: '' | |
IndentCaseLabels: false | |
IndentGotoLabels: true | |
IndentPPDirectives: None | |
IndentWidth: 4 | |
IndentWrappedFunctionNames: false | |
JavaScriptQuotes: Leave | |
JavaScriptWrapImports: true | |
KeepEmptyLinesAtTheStartOfBlocks: true | |
MacroBlockBegin: '' | |
MacroBlockEnd: '' | |
MaxEmptyLinesToKeep: 1 | |
NamespaceIndentation: None | |
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: true | |
SortIncludes: true | |
SortUsingDeclarations: true | |
SpaceAfterCStyleCast: false | |
SpaceAfterLogicalNot: false | |
SpaceAfterTemplateKeyword: true | |
SpaceBeforeAssignmentOperators: true | |
SpaceBeforeCpp11BracedList: false | |
SpaceBeforeCtorInitializerColon: true | |
SpaceBeforeInheritanceColon: true | |
SpaceBeforeParens: ControlStatements | |
SpaceBeforeRangeBasedForLoopColon: true | |
SpaceInEmptyBlock: false | |
SpaceInEmptyParentheses: false | |
SpacesBeforeTrailingComments: 1 | |
SpacesInAngles: false | |
SpacesInConditionalStatement: false | |
SpacesInContainerLiterals: true | |
SpacesInCStyleCastParentheses: false | |
SpacesInParentheses: false | |
SpacesInSquareBrackets: false | |
SpaceBeforeSquareBrackets: false | |
Standard: Latest | |
StatementMacros: | |
- Q_UNUSED | |
- QT_REQUIRE_VERSION | |
TabWidth: 4 | |
UseCRLF: false | |
UseTab: Never | |
... | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment