Skip to content

Commit 665429c

Browse files
committed
Add clang-format config (moved from cpp_style repo)
1 parent d7d3a07 commit 665429c

2 files changed

Lines changed: 81 additions & 0 deletions

File tree

.clang-format

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
{
2+
"AccessModifierOffset": -4,
3+
"AlignAfterOpenBracket": "AlwaysBreak",
4+
"AlignEscapedNewlinesLeft": false,
5+
"AlignTrailingComments": true,
6+
"AllowAllParametersOfDeclarationOnNextLine": false,
7+
"AllowShortFunctionsOnASingleLine": "None",
8+
"AllowShortIfStatementsOnASingleLine": false,
9+
"AllowShortLoopsOnASingleLine": false,
10+
"AlwaysBreakBeforeMultilineStrings": false,
11+
"AlwaysBreakTemplateDeclarations": true,
12+
"BasedOnStyle": "Google",
13+
"BinPackArguments": false,
14+
"BinPackParameters": false,
15+
"BreakBeforeBinaryOperators": "NonAssignment",
16+
"BreakBeforeBraces": "Allman",
17+
"BreakBeforeTernaryOperators": false,
18+
"BreakConstructorInitializersBeforeComma": true,
19+
"BreakStringLiterals": false,
20+
"ColumnLimit": 120,
21+
"ConstructorInitializerAllOnOneLineOrOnePerLine": true,
22+
"ConstructorInitializerIndentWidth": 2,
23+
"ContinuationIndentWidth": 8,
24+
"Cpp11BracedListStyle": false,
25+
"DerivePointerAlignment": false,
26+
"DerivePointerBinding": true,
27+
"ExperimentalAutoDetectBinPacking": false,
28+
"FixNamespaceComments": true,
29+
"IndentCaseLabels": true,
30+
"IndentFunctionDeclarationAfterType": false,
31+
"IndentPPDirectives": "AfterHash",
32+
"IndentWidth": 4,
33+
"IndentWrappedFunctionNames": true,
34+
"MaxEmptyLinesToKeep": 3,
35+
"NamespaceIndentation": "All",
36+
"ObjCSpaceBeforeProtocolList": true,
37+
"PenaltyBreakBeforeFirstCallParameter": 19,
38+
"PenaltyBreakComment": 60,
39+
"PenaltyBreakFirstLessLess": 1000,
40+
"PenaltyBreakString": 1,
41+
"PenaltyExcessCharacter": 500,
42+
"PenaltyReturnTypeOnItsOwnLine": 1000,
43+
"PointerAlignment": "Right",
44+
"PointerBindsToType": false,
45+
"SortIncludes": false,
46+
"SpaceAfterControlStatementKeyword": true,
47+
"SpaceBeforeAssignmentOperators": true,
48+
"SpaceInEmptyParentheses": false,
49+
"SpacesBeforeTrailingComments": 2,
50+
"SpacesInAngles": false,
51+
"SpacesInCStyleCastParentheses": false,
52+
"SpacesInParentheses": false,
53+
"Standard": "c++17",
54+
"TabWidth": 4,
55+
"UseTab": "Never",
56+
}

pre-commit.clang-format

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/bin/sh
2+
3+
# Allows us to read user input below, assigns stdin to keyboard
4+
exec < /dev/tty
5+
6+
while true;
7+
do
8+
read -p "[pre-commit hook] Format the code? (Y/n) " yn
9+
if [ "$yn" = "" ]; then
10+
yn='Y'
11+
fi
12+
case $yn in
13+
[Yy] ) cd `git rev-parse --show-toplevel`;
14+
FILES=`git status -s | grep "^\(\( *M *\)\|\( *A *\)\).*\(\(cpp\)\|\(h\)$\)" | cut -f 3 -d ' '`
15+
for FILE in ${FILES}
16+
do
17+
echo "Formatting: ${FILE}"
18+
clang-format-4.0 -style=file -i ${FILE}
19+
git add ${FILE}
20+
done
21+
break;;
22+
[Nn] ) exit;;
23+
* ) echo "Please answer y or n for yes or no.";;
24+
esac
25+
done

0 commit comments

Comments
 (0)