-
Notifications
You must be signed in to change notification settings - Fork 29
/
.clang-tidy
109 lines (107 loc) · 4.34 KB
/
.clang-tidy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
---
# All generic Clang-Tidy check are enabled by default, meaning project-specific
# checks are disabled. From there, unrelevant checks are disable on a
# check-by-check basis.
#
# Disabled checks:
# - bugprone-assignment-in-if-condition
# Very carefully used, but useful when reading a bf_marsh.
# - bugprone-easily-swappable-parameters
# Too many false positives, especially when swapable arguments are of different
# types (which will be flagged by the compiler).
# - cert-dcl37-c
# Handled by bugprone-reserved-identifier.AllowedIdentifiers.
# - cert-dcl51-cpp
# Handled by bugprone-reserved-identifier.AllowedIdentifiers.
# - cert-int09-c
# See readibility-enum-initial-value
# - cert-msc30-c, cert-msc50-cpp
# rand() is used for non-secure randomness, let me use it.
# - clang-analyzer-core.CallAndMessage
# Too many false positives with GCC statement expressions.
# - clang-analyzer-deadcode.DeadStores
# False positives when a bf_jmpctx with cleanup attribute is defined (but
# not initialized) and initialized later on.
# - clang-analyzer-optin.core.EnumCastOutOfRange
# We need to use negative enum values to refer to specific counters (errors
# and policy), while the positive values refers to the counters. We can't
# create an enum value for every possible counter index, so clang-tidy will
# complain the value doesn't exist. Which is true. But it's expected.
# - clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling
# Avoid usage of Annex K functions for portability reasons.
# - clang-analyzer-unix.Malloc
# Generates false positives.
# - modernize-macro-to-enum
# No benefit.
# - modernize-use-trailing-return-type
# No benefit.
# - performance-no-int-to-ptr
# No benefit.
# - readability-enum-initial-value
# clang-tidy complains because the X_MAX value of the enums is not defined
# explicitly, while other are. We prefer to do it this way.
# - readability-function-cognitive-complexity
# Functions generating BPF bytecode will trigger this rule anytime, but they're
# not that complex due to heavy use of macros.
# - readability-isolate-declaration
# Rely on manual check: it's uncommon in bpfilter for multiple variable to be
# defined on a single line, but it's sometimes for the better.
# - readability-suspicious-call-argument
# Raises non-issues.
Checks: >
-*,
bugprone-*,
-bugprone-assignment-in-if-condition,
-bugprone-easily-swappable-parameters,
cert-*,
-cert-dcl37-c,
-cert-dcl51-cpp,
-cert-int09-c,
-cert-msc30-c,
-cert-msc50-cpp,
clang-analyzer-*,
-clang-analyzer-core.CallAndMessage,
-clang-analyzer-deadcode.DeadStores,
-clang-analyzer-optin.core.EnumCastOutOfRange,
-clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling,
-clang-analyzer-unix.Malloc,
misc-*,
modernize-*,
-modernize-macro-to-enum,
-modernize-use-trailing-return-type,
performance-*,
-performance-no-int-to-ptr,
portability-*,
readability-*,
-readability-enum-initial-value,
-readability-function-cognitive-complexity,
-readability-isolate-declaration,
-readability-suspicious-call-argument
WarningsAsErrors: '*'
FormatStyle: none
UseColor: yes
CheckOptions:
# Allow use of reserved identifiers as long as they start with "_bf",
# "_BF", or "_cleanup". This check has been modified starting with
# clang-tools-extra v18 (https://releases.llvm.org/18.1.0/tools/clang/tools/extra/docs/ReleaseNotes.html#improvements-to-clang-tidy)
# and will behave differently for macros. Hence clang-tidy v18+ won't
# warn about _cleanup_ identifiers.
- key: bugprone-reserved-identifier.AllowedIdentifiers
value: '^_(bf|BF|cleanup)_[a-zA-Z0-9_]+$'
- key: misc-non-private-member-variables-in-classes.IgnorePublicMemberVariables
value: true
# Unless a *statement* takes 1 line, it should be in braces
- key: readability-braces-around-statements.ShortStatementLines
value: 6
# Allowed short variable names
- key: readability-identifier-length.IgnoredVariableNames
value: '_|i|fd|r|j[0-9]|op'
# Allowed short parameter names
- key: readability-identifier-length.IgnoredParameterNames
value: 'ip|fd|op|id|cb'
# Allow for magic constants that are power of 2.
- key: readability-magic-numbers.IgnorePowersOf2IntegerValues
value: true
# Allow specific masks
- key: readability-magic-numbers.IgnoredIntegerValues
value: 255;65535