Hello,
I was playing with the clang-format tool today with the aim of coming up
with a uniform style specifications for the C++ source files.
Our style guide is largely based on Google's style guide, but we deviate
in some places (e.g. pointer alignment). I have created the following
.clang-format file which I believe closely represents our style
specifications.
I would be glad if you can try the file and let me know your thoughts.
Here are the steps:
1. Copy the .clang-format file to the Quickstep source root.
2. Run the clang-format plugin as folllows:
clang-format -style=file abc.hpp | tee abc-clang.hpp
Here's the explanation:
style=file -> This will force clang to pick up the .clang-format file
placed in Quickstep root and use it as the style reference.
abc.hpp -> A sample source file in the project. e.g.
query_execution/Worker.hpp
tee abc-clang.hpp -> The output from the clang-format tool, which
performs changes on abc.hpp and we temporarily save it as abc-clang.hpp
3. vimdiff abc.hpp abc-clang.hpp to see the differences. You can use any
other diff tool instead of vimdiff (e.g. meld)
The long term goal should be to perfect the clang-format file so that it
always gives trusted output. Then the pull request reviewer's burden
(wrt style related comments) is taken off. We could even automate the
style checking as a part of the CI.
--
Thanks,
Harshad
---
Language: Cpp
# BasedOnStyle: Google
AccessModifierOffset: -1
AlignAfterOpenBracket: true
AlignConsecutiveAssignments: false
AlignEscapedNewlinesLeft: true
AlignOperands: true
AlignTrailingComments: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortBlocksOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: All
AllowShortIfStatementsOnASingleLine: true
AllowShortLoopsOnASingleLine: true
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakBeforeMultilineStrings: true
AlwaysBreakTemplateDeclarations: true
BinPackArguments: false
BinPackParameters: false
BreakBeforeBinaryOperators: None
BreakBeforeBraces: Attach
BreakBeforeTernaryOperators: true
BreakConstructorInitializersBeforeComma: false
ColumnLimit: 80
CommentPragmas: '^ IWYU pragma:'
ConstructorInitializerAllOnOneLineOrOnePerLine: true
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: true
DerivePointerAlignment: false
DisableFormat: false
ExperimentalAutoDetectBinPacking: false
ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH ]
IndentCaseLabels: true
IndentWidth: 2
IndentWrappedFunctionNames: false
KeepEmptyLinesAtTheStartOfBlocks: false
Standard: Cpp11
MacroBlockBegin: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
ObjCBlockIndentWidth: 2
ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: false
PenaltyBreakBeforeFirstCallParameter: 1
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakString: 1000
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 200
PointerAlignment: Right
PointerBindsToType: false
SpaceAfterCStyleCast: false
SpaceBeforeAssignmentOperators: true
SpaceBeforeParens: ControlStatements
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 2
SpacesInAngles: false
SpacesInContainerLiterals: true
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard: Auto
TabWidth: 8
UseTab: Never
...