Skip to content

Commit 8a6ff30

Browse files
committed
style: Add .clang-format
1 parent d682b84 commit 8a6ff30

9 files changed

Lines changed: 97 additions & 18 deletions

File tree

.clang-format

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
---
2+
Language: Cpp
3+
BasedOnStyle: Google
4+
5+
AccessModifierOffset: -4
6+
AlignAfterOpenBracket: Align
7+
AlignConsecutiveAssignments: true
8+
AlignConsecutiveDeclarations: true
9+
AlignConsecutiveMacros: true
10+
AlignEscapedNewlines: Left
11+
AlignOperands: true
12+
AlignTrailingComments: true
13+
14+
AllowAllParametersOfDeclarationOnNextLine: true
15+
AllowShortBlocksOnASingleLine: true
16+
AllowShortCaseLabelsOnASingleLine: true
17+
AllowShortFunctionsOnASingleLine: InlineOnly
18+
AllowShortIfStatementsOnASingleLine: true
19+
AllowShortLoopsOnASingleLine: true
20+
21+
AlwaysBreakBeforeMultilineStrings: false
22+
BinPackArguments: true
23+
BinPackParameters: true
24+
BreakBeforeBinaryOperators: None
25+
BreakBeforeBraces: Attach
26+
BreakBeforeTernaryOperators: false
27+
BreakConstructorInitializersBeforeComma: false
28+
BreakTemplateDeclarations: Yes
29+
30+
ColumnLimit: 120
31+
CommentPragmas: "^ IWYU pragma:"
32+
ConstructorInitializerAllOnOneLineOrOnePerLine: true
33+
ConstructorInitializerIndentWidth: 4
34+
ContinuationIndentWidth: 4
35+
Cpp11BracedListStyle: true
36+
37+
DerivePointerAlignment: false
38+
PointerAlignment: Left
39+
40+
DisableFormat: false
41+
ExperimentalAutoDetectBinPacking: false
42+
43+
IndentCaseLabels: true
44+
IndentWidth: 4
45+
IndentWrappedFunctionNames: false
46+
KeepEmptyLinesAtTheStartOfBlocks: false
47+
MaxEmptyLinesToKeep: 1
48+
NamespaceIndentation: Inner
49+
50+
PenaltyBreakBeforeFirstCallParameter: 19
51+
PenaltyBreakComment: 300
52+
PenaltyBreakFirstLessLess: 120
53+
PenaltyBreakString: 1000
54+
PenaltyExcessCharacter: 1000000
55+
PenaltyReturnTypeOnItsOwnLine: 60
56+
57+
ReflowComments: true
58+
SortIncludes: true
59+
SpaceAfterCStyleCast: false
60+
SpaceBeforeAssignmentOperators: true
61+
SpaceBeforeParens: ControlStatements
62+
SpaceInEmptyParentheses: false
63+
SpacesBeforeTrailingComments: 2
64+
SpacesInAngles: false
65+
SpacesInContainerLiterals: true
66+
SpacesInCStyleCastParentheses: false
67+
SpacesInParentheses: false
68+
SpacesInSquareBrackets: false
69+
70+
Standard: Auto
71+
TabWidth: 4
72+
UseTab: Never
73+
...

test/include/shared_lib.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ EXPORT int add(int a, int b);
2626
namespace shared_lib {
2727

2828
class EXPORT SharedLib {
29-
public:
30-
static int add(int a, int b);
29+
public:
30+
static int add(int a, int b);
3131
};
3232

3333
}; // namespace shared_lib

test/include/static_lib.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ int sub(int a, int b);
1616
namespace static_lib {
1717

1818
class StaticLib {
19-
public:
20-
static int sub(int a, int b);
19+
public:
20+
static int sub(int a, int b);
2121
};
2222

2323
}; // namespace static_lib

test/src/main.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
#include "static_lib.h"
55

66
int main(void) {
7-
int a = 1, b = 2;
8-
printf("%d + %d = %d\n", a, b, add(a, b));
9-
printf("%d - %d = %d\n", a, b, sub(a, b));
10-
return 0;
7+
int a = 1, b = 2;
8+
printf("%d + %d = %d\n", a, b, add(a, b));
9+
printf("%d - %d = %d\n", a, b, sub(a, b));
10+
return 0;
1111
}

test/src/main.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,8 @@
44
#include "static_lib.h"
55

66
int main(void) {
7-
int a = 1, b = 2;
8-
printf("%d + %d = %d/%d\n", a, b, add(a, b),
9-
shared_lib::SharedLib::add(a, b));
10-
printf("%d - %d = %d/%d\n", a, b, sub(a, b),
11-
static_lib::StaticLib::sub(a, b));
12-
return 0;
7+
int a = 1, b = 2;
8+
printf("%d + %d = %d/%d\n", a, b, add(a, b), shared_lib::SharedLib::add(a, b));
9+
printf("%d - %d = %d/%d\n", a, b, sub(a, b), static_lib::StaticLib::sub(a, b));
10+
return 0;
1311
}

test/src/shared_lib.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
#include "shared_lib.h"
22

3-
int add(int a, int b) { return a + b; }
3+
int add(int a, int b) {
4+
return a + b;
5+
}

test/src/shared_lib.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace shared_lib {
44

5-
int SharedLib::add(int a, int b) { return a + b; }
5+
int SharedLib::add(int a, int b) {
6+
return a + b;
7+
}
68

79
}; // namespace shared_lib

test/src/static_lib.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
#include "static_lib.h"
22

3-
int sub(int a, int b) { return a - b; }
3+
int sub(int a, int b) {
4+
return a - b;
5+
}

test/src/static_lib.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace static_lib {
44

5-
int StaticLib::sub(int a, int b) { return a - b; }
5+
int StaticLib::sub(int a, int b) {
6+
return a - b;
7+
}
68

79
}; // namespace static_lib

0 commit comments

Comments
 (0)