.clang_format
Maksim Shabunin edited this page Apr 2, 2024
·
8 revisions
Note: clang-format 12 is used as a baseline
Standalone LLVM builds - LLVM GitHub Releases: https://github.com/llvm/llvm-project/releases
For example 16: https://github.com/llvm/llvm-project/releases/tag/llvmorg-16.0.4
sudo apt install clang-format
Ubuntu 22.04 - clang-format 14
One of variants:
- Visual studio component "C++ Clang Tools for Windows"
- Visual Studio extension: https://marketplace.visualstudio.com/items?itemName=LLVMExtensions.ClangFormat
brew install clang-format
- Run in "check" mode (print formatting issues)
clang-format --style=file:${HOME}/my-clang-format --dry-run --Werror <path-to-src-file>
- Run in "inplace edit" mode (replace file contents with formatted code)
clang-format --style=file:${HOME}/my-clang-format -i <path-to-src-file>
- Run in editor using extension: consult your editor/extension documentation
- (ver. 12) introduction + editor integrations: https://releases.llvm.org/12.0.0/tools/clang/docs/ClangFormat.html
- (ver. 12) configuration reference: https://releases.llvm.org/12.0.0/tools/clang/docs/ClangFormatStyleOptions.html
- (latest) Introduction: https://clang.llvm.org/docs/ClangFormat.html
- Create list of tracked files
- Add cmake targets for check/format modes
- Add CI task to check tracked files (in Documentation builder, for example)
# clang-format version 12
# https://releases.llvm.org/12.0.0/tools/clang/docs/ClangFormatStyleOptions.html
BasedOnStyle: LLVM
AccessModifierOffset: -4
AlignAfterOpenBracket: Align
AlignConsecutiveAssignments: None
AlignConsecutiveBitFields: None
AlignConsecutiveDeclarations: None
AlignConsecutiveMacros: None
AlignEscapedNewlines: DontAlign
AlignOperands: Align
AlignTrailingComments: false
AllowAllArgumentsOnNextLine: false
AllowAllConstructorInitializersOnNextLine: false
AllowAllParametersOfDeclarationOnNextLine: false
AllowShortBlocksOnASingleLine: Never
AllowShortCaseLabelsOnASingleLine: true
AllowShortEnumsOnASingleLine: true
AllowShortFunctionsOnASingleLine: Empty
AllowShortIfStatementsOnASingleLine: Never
AllowShortLambdasOnASingleLine: None
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: Yes
BinPackArguments: false
BinPackParameters: false
BitFieldColonSpacing: Both
BreakBeforeBraces: Custom
BraceWrapping:
AfterCaseLabel: true
AfterClass: true
AfterControlStatement: Always
AfterEnum: true
AfterFunction: true
AfterNamespace: false
AfterObjCDeclaration: true
AfterStruct: true
AfterUnion: true
AfterExternBlock: true
BeforeCatch: true
BeforeElse: true
BeforeLambdaBody: false
BeforeWhile: true
IndentBraces: false
SplitEmptyFunction: true
SplitEmptyRecord: true
SplitEmptyNamespace: true
BreakBeforeBinaryOperators: None
BreakBeforeTernaryOperators: true
BreakConstructorInitializers: AfterColon
BreakInheritanceList: AfterColon
BreakStringLiterals: true
ColumnLimit: 100
CompactNamespaces: true
ConstructorInitializerAllOnOneLineOrOnePerLine: false
ContinuationIndentWidth: 4
Cpp11BracedListStyle: true
DerivePointerAlignment: false
FixNamespaceComments: true
IncludeBlocks: Preserve
IndentCaseLabels: true
IndentExternBlock: NoIndent
IndentPPDirectives: AfterHash
IndentWidth: 4
IndentWrappedFunctionNames: true
InsertTrailingCommas: None
KeepEmptyLinesAtTheStartOfBlocks: false
Language: Cpp
MaxEmptyLinesToKeep: 2
NamespaceIndentation: None
PenaltyBreakBeforeFirstCallParameter: 15
PenaltyBreakString: 10
#PenaltyReturnTypeOnItsOwnLine: 15
#PenaltyExcessCharacter: 3
PenaltyIndentedWhitespace: 1
PointerAlignment: Left
ReflowComments: true
SortIncludes: false
SortUsingDeclarations: false
SpaceAfterCStyleCast: false
SpaceAfterLogicalNot: false
SpaceAfterTemplateKeyword: true
SpaceBeforeAssignmentOperators: true
SpaceBeforeCaseColon: false
SpaceBeforeCpp11BracedList: true
SpaceBeforeCtorInitializerColon: true
SpaceBeforeInheritanceColon: true
SpaceBeforeParens: ControlStatementsExceptForEachMacros
SpaceBeforeRangeBasedForLoopColon: true
SpaceBeforeSquareBrackets: false
SpaceInEmptyBlock: false
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 2
SpacesInAngles: false
SpacesInCStyleCastParentheses: false
SpacesInConditionalStatement: false
SpacesInContainerLiterals: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard: c++11
TabWidth: 8
UseTab: Never
#WhitespaceSensitiveMacros: ["CV_Check"]
© Copyright 2024, OpenCV team
- Home
- Deep Learning in OpenCV
- Running OpenCV on Various Platforms
- OpenCV 5
- OpenCV 4
- OpenCV 3
- Development process
- OpenCV GSoC
- Archive