Skip to content

Commit

Permalink
Add clang-formatting to Jenkins
Browse files Browse the repository at this point in the history
This commit adds a clang-format file to the repository, and scripts
that will call the formatter on Jenkins to make sure that merge requests
are formatted correctly. There is a corresponding jenkins change to make
this happen automatically.

The clang-format version is unspecified by default, to match the unadorned
clang-format that comes with LLVM's binary archives. You can still specify
it when using it with the git hooks if you want to use it locally, say with
'clang-format-3.9', if that is what your package manager has called it.

One minor update has been made to the format file: instead of
inferring where * and & bind to, they are now specified to be on the
left.  Allowing it to be guessed by clang-format means that the style
was inconsistent across the repo's files. It is otherwise the same as
Google style from clang-format-3.9. The repository has been formatted
to match this style in this commit as well. From now on, there should
be no noisy format commits, ideally.
  • Loading branch information
DuncanMcBain committed Mar 28, 2018
1 parent 8a1ced6 commit 52540a3
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 6 deletions.
89 changes: 89 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
---
Language: Cpp
# BasedOnStyle: Google
AccessModifierOffset: -1
AlignAfterOpenBracket: Align
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false
AlignEscapedNewlinesLeft: true
AlignOperands: true
AlignTrailingComments: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortBlocksOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: All
AllowShortIfStatementsOnASingleLine: true
AllowShortLoopsOnASingleLine: true
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: true
AlwaysBreakTemplateDeclarations: true
BinPackArguments: true
BinPackParameters: true
BraceWrapping:
AfterClass: false
AfterControlStatement: false
AfterEnum: false
AfterFunction: false
AfterNamespace: false
AfterObjCDeclaration: false
AfterStruct: false
AfterUnion: false
BeforeCatch: false
BeforeElse: false
IndentBraces: false
BreakBeforeBinaryOperators: None
BreakBeforeBraces: Attach
BreakBeforeTernaryOperators: true
BreakConstructorInitializersBeforeComma: false
BreakStringLiterals: true
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 ]
IncludeCategories:
- Regex: '^<.*\.h>'
Priority: 1
- Regex: '^<.*'
Priority: 2
- Regex: '.*'
Priority: 3
IncludeIsMainRegex: '([-_](test|unittest))?$'
IndentCaseLabels: true
IndentWidth: 2
IndentWrappedFunctionNames: false
KeepEmptyLinesAtTheStartOfBlocks: false
MacroBlockBegin: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
PenaltyBreakBeforeFirstCallParameter: 1
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakString: 1000
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 200
PointerAlignment: Left
ReflowComments: true
SortIncludes: true
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
...

9 changes: 9 additions & 0 deletions hooks/clang-format-all.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash

set -euo pipefail
IFS=$'\n\t'

VERSION=''

git ls-files | grep -E "*\.h$|*\.hpp$|*\.cc$|*\.cpp$" | \
xargs clang-format$VERSION -style=file -i
7 changes: 7 additions & 0 deletions hooks/is-clang-formatted.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash

set -euo pipefail
IFS=$'\n\t'

hooks/clang-format-all.sh
git diff --quiet
6 changes: 3 additions & 3 deletions test/helpers/fast_div.cc
Original file line number Diff line number Diff line change
Expand Up @@ -65,19 +65,19 @@ TYPED_TEST(FastDivTest, DivideBy12) {
}
TYPED_TEST(FastDivTest, AllValuesDivisorsLessThan10) {
TypeParam max = 1024;
for(TypeParam div = 2; div < 10; ++div) {
for (TypeParam div = 2; div < 10; ++div) {
this->check_all_values_up_to(max, div);
}
}
TYPED_TEST(FastDivTest, AllValuesDivisors10To20) {
TypeParam max = 1024;
for(TypeParam div = 10; div < 20; ++div) {
for (TypeParam div = 10; div < 20; ++div) {
this->check_all_values_up_to(max, div);
}
}
TYPED_TEST(FastDivTest, AllValuesDivisors100To200) {
TypeParam max = 1024;
for(TypeParam div = 100; div < 200; ++div) {
for (TypeParam div = 100; div < 200; ++div) {
this->check_all_values_up_to(max, div);
}
}
6 changes: 3 additions & 3 deletions test/helpers/output_window_index.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
template <typename T>
struct IndexHelpersOutWindow : public ::testing::Test {
void check_output_window(T const stride, T const pad,
std::vector<T> const& index,
std::vector<T> const& exp_win,
std::vector<T> const& exp_fil) {
std::vector<T> const& index,
std::vector<T> const& exp_win,
std::vector<T> const& exp_fil) {
ASSERT_EQ(index.size(), exp_win.size());
ASSERT_EQ(index.size(), exp_fil.size());
for (size_t i = 0; i < index.size(); ++i) {
Expand Down

0 comments on commit 52540a3

Please sign in to comment.