Skip to content

Commit 34c93d0

Browse files
committed
Add clang-{format,tidy} rules
1 parent 833f1e3 commit 34c93d0

File tree

2 files changed

+130
-0
lines changed

2 files changed

+130
-0
lines changed

.clang-format

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
BasedOnStyle: LLVM
2+
IndentWidth: 4
3+
4+
Language: Cpp
5+
6+
# Yes: int *a;
7+
# No: int* a;
8+
# Absolutely not: int * a;
9+
DerivePointerAlignment: false
10+
PointerAlignment: Right
11+
12+
# East const
13+
# Yes: int const a;
14+
# No: const int a;
15+
QualifierAlignment: Right
16+
17+
# If parameters do not fit on one line, do this:
18+
# void func(
19+
# int a,
20+
# int b
21+
# )
22+
AlignAfterOpenBracket: BlockIndent
23+
BinPackArguments: false
24+
BinPackParameters: false
25+
ExperimentalAutoDetectBinPacking: false
26+
AllowAllParametersOfDeclarationOnNextLine: false
27+
PenaltyReturnTypeOnItsOwnLine: 1000
28+
29+
# Attach braces to surrounding context, except on functions.
30+
BreakBeforeBraces: Linux
31+
32+
AllowShortLoopsOnASingleLine: true
33+
34+
BitFieldColonSpacing: Before

.clang-tidy

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
Checks: [
2+
bugprone*,
3+
4+
cert*,
5+
6+
cppcoreguidelines*,
7+
# Need globals to communicate with interrupts
8+
-cppcoreguidelines-avoid-non-const-global-variables,
9+
# Covered by readability-magic-numbers
10+
-cppcoreguidelines-avoid-magic-numbers,
11+
# We use global aggregates to dispatch extern registers.
12+
# This cannot cause order-of-initialization problems because
13+
# registers are guaranteed to be initialized at reset.
14+
-cppcoreguidelines-interfaces-global-init,
15+
16+
google*,
17+
18+
hicpp*,
19+
# Bad warning: https://stackoverflow.com/questions/50399090/use-of-a-signed-integer-operand-with-a-binary-bitwise-operator-when-using-un
20+
-hicpp-signed-bitwise,
21+
22+
llvm*,
23+
# We use a different include guard style
24+
-llvm-header-guard,
25+
26+
misc*,
27+
28+
modernize*,
29+
30+
performance*,
31+
32+
readability*,
33+
]
34+
35+
CheckOptions:
36+
- key: bugprone-easily-swappable-parameters.ModelImplicitConversions
37+
value: false
38+
- key: readability-function-cognitive-complexity.Threshold
39+
value: '10'
40+
- key: readability-function-size.LineThreshold
41+
value: '80'
42+
43+
- key: readability-identifier-length.MinimumParameterNameLength
44+
value: '1'
45+
- key: readability-identifier-length.IgnoredVariableNames
46+
value: '^dt|pu$'
47+
48+
- key: readability-magic-numbers.IgnorePowersOf2IntegerValues
49+
value: 'true'
50+
- key: readability-magic-numbers.IgnoredIntegerValues
51+
value: '15;255;4095;65535;'
52+
53+
# Empty loops should look like this: while (condition) continue;
54+
- key: readability-braces-around-statements.ShortStatementLines
55+
value: '1'
56+
- key: hicpp-braces-around-statements.ShortStatementLines
57+
value: '1'
58+
59+
- key: readability-identifier-naming.EnumCase
60+
value: 'CamelCase'
61+
- key: readability-identifier-naming.FunctionCase
62+
value: 'lower_case'
63+
# Public functions have capitalized prefix
64+
- key: readability-identifier-naming.GlobalFunctionCase
65+
value: 'aNy_CasE'
66+
# Interrupt service routines
67+
- key: readability-identifier-naming.GlobalFunctionIgnoredRegexp
68+
value: '_[A-Z0-9]+Interrupt'
69+
- key: readability-identifier-naming.VariableCase
70+
value: 'lower_case'
71+
# Register names
72+
- key: readability-identifier-naming.VariableIgnoredRegexp
73+
value: '[A-Z][A-Z0-9]+(bits)?'
74+
- key: readability-identifier-naming.StructCase
75+
value: 'CamelCase'
76+
- key: readability-identifier-naming.TypedefCase
77+
value: 'CamelCase'
78+
- key: readability-identifier-naming.TypedefIgnoredRegexp
79+
value: '[A-Z]+_[a-zA-Z0-9]+'
80+
- key: readability-identifier-naming.EnumIgnoredRegexp
81+
value: '[A-Z]+_[a-zA-Z0-9]+'
82+
- key: readability-identifier-naming.StructIgnoredRegexp
83+
value: '[A-Z]+_[a-zA-Z0-9]+'
84+
- key: readability-identifier-naming.UnionIgnoredRegexp
85+
value: '[A-Z]+_[a-zA-Z0-9]+'
86+
- key: readability-identifier-naming.UnionCase
87+
value: 'CamelCase'
88+
- key: readability-identifier-naming.GlobalConstantCase
89+
value: 'UPPER_CASE'
90+
- key: readability-identifier-naming.GlobalConstantPrefix
91+
value: 'g_'
92+
- key: readability-identifier-naming.MacroDefinitionCase
93+
value: 'UPPER_CASE'
94+
95+
FormatStyle: file
96+
SystemHeaders: false

0 commit comments

Comments
 (0)