Skip to content

Commit 29ef924

Browse files
committed
Update clang format rules, with examples
1 parent 6289616 commit 29ef924

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

.clang-format

+6
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
---
2+
# https://clang.llvm.org/docs/ClangFormatStyleOptions.html
23
# We base things of WebKit + Allman braces
34
# BasedOnStyle: WebKit
5+
AccessModifierOffset: -4
6+
AllowShortFunctionsOnASingleLine: None
47
BreakBeforeBraces: Allman
58
BreakConstructorInitializers: BeforeComma
9+
# This is not the ACTUAL column limit, this is just to make
10+
# clang-format chill out! Use your best judgement!
11+
ColumnLimit: 160
612
CompactNamespaces: 'false'
713
ConstructorInitializerIndentWidth: 0
814
Cpp11BracedListStyle: 'false'

CONTRIBUTING.md

+36-1
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,41 @@ Here are the points from `.clang-format` explained:
6464

6565
When in doubt, defaulting to `WebKit style with Allman braces` is _seemingly_ a safe option.
6666

67+
`AccessModifierOffset: -4`
68+
```cpp
69+
// Correct ✔️
70+
class Classname
71+
{
72+
public:
73+
Classname();
74+
75+
private:
76+
int member;
77+
}
78+
79+
// Wrong ❌
80+
class Classname
81+
{
82+
public:
83+
Classname();
84+
85+
private:
86+
int member;
87+
}
88+
```
89+
90+
`AllowShortFunctionsOnASingleLine: Empty`
91+
```cpp
92+
// Correct ✔️
93+
void f()
94+
{
95+
foo();
96+
}
97+
98+
// Wrong ❌
99+
void f() { foo(); }
100+
```
101+
67102
`BreakBeforeBraces: Allman`
68103

69104
Braces should _almost always_ be on a new line.
@@ -255,7 +290,7 @@ else
255290
256291
### C++ Misc & Naming
257292
258-
`Casting - static_cast over C-Style`
293+
`Casting - static_cast over C-Style (cppcoreguidelines-pro-type-cstyle-cast)`
259294
```cpp
260295
// Correct ✔️
261296
uint32 param = static_cast<uint32>(input);

0 commit comments

Comments
 (0)