-
Notifications
You must be signed in to change notification settings - Fork 60
Expand file tree
/
Copy path.clang-tidy
More file actions
134 lines (132 loc) · 5.3 KB
/
Copy path.clang-tidy
File metadata and controls
134 lines (132 loc) · 5.3 KB
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
---
# 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
# To use very carefully.
# - bugprone-easily-swappable-parameters
# Too many false positives, especially when swapable arguments are of different
# types (which will be flagged by the compiler).
# - bugprone-multi-level-implicit-pointer-conversion
# Multi-level pointer conversion is used for BF_FREEP
# - cert-dcl03-c
# We use assert(0) for impossible default in switch...case.
# - 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.
# - misc-include-cleaner
# False positives, e.g. with errno.h: E* macros are not directly defined in it,
# but it's the header we should include.
# - misc-no-recursion
# Let me use recursion.
# - misc-redundant-expression
# Macros having the same values can't be or'd without a warning.
# - misc-static-assert
# We use assert(0) for impossible default in switch...case.
# - modernize-macro-to-enum
# No benefit.
# - modernize-use-trailing-return-type
# No benefit.
# - performance-no-int-to-ptr
# No benefit.
# - portability-avoid-pragma-once
# Allow usage of `#pragma once`.
# - 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-implicit-bool-conversion
# Implicit bool<->int conversions are idiomatic C (e.g. returning int from
# `cond ? 0 : -EINVAL` where `cond` is bool). The check has no option to
# suppress just the bool->int direction, which produces most of the noise.
# - 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,
-bugprone-multi-level-implicit-pointer-conversion,
cert-*,
-cert-dcl03-c,
-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-*,
-misc-include-cleaner,
-misc-no-recursion,
-misc-redundant-expression,
-misc-static-assert,
modernize-*,
-modernize-macro-to-enum,
-modernize-use-trailing-return-type,
performance-*,
-performance-no-int-to-ptr,
portability-*,
-portability-avoid-pragma-once,
readability-*,
-readability-enum-initial-value,
-readability-function-cognitive-complexity,
-readability-implicit-bool-conversion,
-readability-isolate-declaration,
-readability-suspicious-call-argument,
WarningsAsErrors: "*"
FormatStyle: none
UseColor: yes
CheckOptions:
# Allow use of reserved identifier was (_)+ underscore, followed by a bpfilter
# specific prefix (.e.g _BF). Other idenfitiers defined by GCC are allowed,
# such as _start, _end...
- key: bugprone-reserved-identifier.AllowedIdentifiers
value: "^(_)+(start|stop|bf|bfc|bft|BF|BFC|GNU)_[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: 3
# Allowed short variable names
- key: readability-identifier-length.IgnoredVariableNames
value: "_|i|fd|r|j[0-9]|op|ns|n"
# Allowed short parameter names
- key: readability-identifier-length.IgnoredParameterNames
value: "ip|fd|op|id|cb|ns|n"
# 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: 3;255;65535;100