Skip to content

Commit 4a911f9

Browse files
committed
Standardized code style, code formatting automation
- Created .clang-format file with rules describing code style - Created format_code.sh script that automates code formatting - Formatted code
1 parent 7515fd0 commit 4a911f9

12 files changed

+426
-330
lines changed

.clang-format

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
AccessModifierOffset: '-4'
2+
AlignAfterOpenBracket: Align
3+
AlignArrayOfStructures: Left
4+
AlignConsecutiveAssignments: 'false'
5+
AlignConsecutiveBitFields: 'false'
6+
AlignConsecutiveDeclarations: 'false'
7+
AlignConsecutiveMacros: 'true'
8+
AlignEscapedNewlines: Left
9+
AlignOperands: 'true'
10+
AlignTrailingComments: 'true'
11+
AllowAllArgumentsOnNextLine: 'false'
12+
AllowAllConstructorInitializersOnNextLine: 'false'
13+
AllowAllParametersOfDeclarationOnNextLine: 'false'
14+
AllowShortBlocksOnASingleLine: 'false'
15+
AllowShortCaseLabelsOnASingleLine: 'false'
16+
AllowShortFunctionsOnASingleLine: Empty
17+
AllowShortIfStatementsOnASingleLine: Never
18+
AllowShortLambdasOnASingleLine: Empty
19+
AllowShortLoopsOnASingleLine: 'false'
20+
AlwaysBreakAfterReturnType: None
21+
AlwaysBreakBeforeMultilineStrings: 'false'
22+
AlwaysBreakTemplateDeclarations: 'Yes'
23+
BinPackArguments: 'true'
24+
BinPackParameters: 'true'
25+
BreakBeforeBinaryOperators: None
26+
BreakBeforeBraces: Allman
27+
BreakBeforeTernaryOperators: 'true'
28+
BreakConstructorInitializers: AfterColon
29+
BreakInheritanceList: AfterColon
30+
BreakStringLiterals: 'true'
31+
ColumnLimit: '100'
32+
CompactNamespaces: 'false'
33+
ConstructorInitializerAllOnOneLineOrOnePerLine: 'false'
34+
ConstructorInitializerIndentWidth: '4'
35+
ContinuationIndentWidth: '4'
36+
Cpp11BracedListStyle: 'true'
37+
DerivePointerAlignment: 'false'
38+
FixNamespaceComments: 'true'
39+
IncludeBlocks: Regroup
40+
IndentCaseLabels: 'true'
41+
IndentPPDirectives: AfterHash
42+
IndentWidth: '4'
43+
IndentWrappedFunctionNames: 'false'
44+
KeepEmptyLinesAtTheStartOfBlocks: 'false'
45+
Language: Cpp
46+
MaxEmptyLinesToKeep: '1'
47+
NamespaceIndentation: All
48+
PointerAlignment: Left
49+
ReflowComments: 'true'
50+
SortIncludes: 'true'
51+
SortUsingDeclarations: 'true'
52+
SpaceAfterCStyleCast: 'false'
53+
SpaceAfterLogicalNot: 'false'
54+
SpaceAfterTemplateKeyword: 'false'
55+
SpaceBeforeAssignmentOperators: 'true'
56+
SpaceBeforeCpp11BracedList: 'false'
57+
SpaceBeforeCtorInitializerColon: 'true'
58+
SpaceBeforeInheritanceColon: 'true'
59+
SpaceBeforeParens: ControlStatements
60+
SpaceBeforeRangeBasedForLoopColon: 'true'
61+
SpaceInEmptyParentheses: 'false'
62+
SpacesBeforeTrailingComments: '1'
63+
SpacesInAngles: 'false'
64+
SpacesInContainerLiterals: 'false'
65+
SpacesInCStyleCastParentheses: 'false'
66+
SpacesInLineCommentPrefix:
67+
Minimum: 0
68+
Maximum: 0
69+
SpacesInParentheses: 'false'
70+
SpacesInSquareBrackets: 'false'
71+
Standard: Cpp11
72+
TabWidth: '0'
73+
UseTab: Never

build_and_test.sh

-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
11
make all && echo "" && ./test.sh
2-

format_code.sh

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Format the code
2+
clang-format --style=file -i src/*
3+
# Add newline at end of file if missing
4+
find . -type f -not -path './.git/*' -not -path './bin/*' -not -path './obj/*' -not -path './documents/*' -not -path './format_code.sh' -exec sed -i -e '$a\' {} \;
5+
# Remove extra newlines if there is more than one at the end of file
6+
find . -type f -not -path './.git/*' -not -path './bin/*' -not -path './obj/*' -not -path './documents/*' -not -path './format_code.sh' -exec sed -i -e :a -e '/^\n*$/{$d;N;ba' -e '}' {} \;
7+
# Remove trailing spaces from code
8+
find ./src/* -type f -exec sed -i 's/[[:space:]]\+$//' {} \;

makefile

-1
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,3 @@ clean:
3636

3737
cleaner: | clean
3838
@if [ -d ./$(OBJ_DIR) ]; then echo Cleaning $(OBJ_DIR); rm -f $(OBJ_DIR)/*; fi
39-

0 commit comments

Comments
 (0)