-
Notifications
You must be signed in to change notification settings - Fork 0
/
.clang-tidy
315 lines (275 loc) · 13.6 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
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
# clang-tidy is a C/C++ static analyzer that is helpful in detecting potential errors or malpractices in C/C++ codebases.
# clang-tidy bundles its own checks and also capable of using Clang Static Analyzer checks.
# Each check offered by clang-tidy or Clang Static Analyzer has a name and can be chosen for use using the `-checks=` option.
# -checks= option specifies a list of comma separated globs.
# these globs are either prefixed with a negative sign or not
# prefixing globs with negative sign removes them from clang-tidy's consideration while no prefix adds them to the checks performed by clang-tidy.
# -checks also accepts wildcard specifiers which help to chose subsets of like named checks or to enable or disable checks alltogether.
# e.g. -checks=-* will disable all the checks available in clang-tidy
# while -checks=* will enable all available checks.
# REMEBER WHAT MATTERS HERE IS THE PREFIX, HYPHENS THAT OCCUR IN THE MIDDLE OF CHECK TOKENS ARE USED WITH WILDCARD SPECIFIERS FOR PATTERN MATCHING.
# e.g. -checks=-*,clang-analyzer-*,-clang-analyzer-cplusplus*
# this will first disable all available (checks that were enabled by default) checks. then will enable all checks under the category
# clang-analyzer-* (note the use of wildcard here) except for checks that were under the subcategory clang-analyzer-cplusplus* (again note the ocurrence of the wildcard here)
# some clang-tidy checks are draconian and overly pedantic. there are few ways to suppress such warnings/errors.
# check specific workarounds are available to disable select instances of certain diagnostics!
# bugprone-use-after-move can be silenced by re-initializing the variable after it has been moved out
# bugprone-string-integer-assignment can be suppressed by explicitly casting the integer to char
# readability-implicit-bool-conversion can also be suppressed by using explicit casts, etc.
# clang-tidy also offers some generic mechanisms to override the diagnostic configs
# an inline trailing // NOLINT disables all diagnostics for the line.
# the reason for choosing to suppress the warning can be registered like so
# // NOLINT: <did that because of this>
# // NOLINT offers customization options with the option to use wildcards for categorical exclusion.
# // NOLINT(google-explicit-constructor, google-runtime-int)
# will disable only the chosen two checks for the line
# // NOLINT(google*) will disable all checks from the module google.
# // NOLINT(*-avoid-c-arrays) will disable all diagnostics (possibly from different modules) with a label that ends with `-avoid-c-arrays`
# this is a cross module linter flag for that line.
# // NOLINTNEXTLINE can be used in the same way as // NOLINT but its effects only apply to the following line.
# specify // NOLINTNEXTLIN in a dedicated line i.e not as a trailing comment on an existing line
# clang-tidy also has an option to ignore diagnostics for code regions, using the BEGIN and END postfixes
# // NOLINTBEGIN starts a section where clang-tidy diagnostics are skipped
# // NOLINTEND closes the preceding section.
# // NOLINTBEGIN also accepts optional parameters inside a parenthesis, like // NOLINTBEGIN(google-*)
# note that whitespaces between NOLINT/NOLINTNEXTLINE/NOLINTBEGIN/NOLINTEND and the opening parenthesis are not allowed
# (in this case the comment will be treated just as NOLINT/NOLINTNEXTLINE/NOLINTBEGIN/NOLINTEND), whereas in the check names list
# (inside the parentheses), whitespaces can be used and will be ignored.
# all NOLINTBEGIN comments must be paired by an equal number of NOLINTEND comments. Moreover, a pair of comments must have matching arguments
# for example, NOLINTBEGIN(check-name) can be paired with NOLINTEND(check-name) but not with NOLINTEND (zero arguments).
# clang-tidy will generate a clang-tidy-nolint error diagnostic if any NOLINTBEGIN/NOLINTEND comment violates these requirements.
########################################################
########################################################
# TAILOR MADE FOR C #
########################################################
# AVOID TRAILING INLINE COMMENTS IN .clang-tidy FILES! #
########################################################
########################################################
# JSON is a subset of YAML, so we could practically use JSON syntax in .clang-format, .clang-tidy and .clangd files!
Checks: >
-*,
bugprone-assert-side-effect,
bugprone-assignment-in-if-condition,
bugprone-bool-pointer-implicit-conversion,
bugprone-branch-clone,
bugprone-casting-through-void,
bugprone-chained-comparison,
bugprone-dynamic-static-initializers,
bugprone-implicit-widening-of-multiplication-result,
bugprone-inc-dec-in-conditions,
bugprone-incorrect-roundings,
bugprone-infinite-loop,
bugprone-integer-division,
bugprone-macro-parentheses,
bugprone-macro-repeated-side-effects,
bugprone-misplaced-operator-in-strlen-in-alloc,
bugprone-misplaced-pointer-arithmetic-in-alloc,
bugprone-misplaced-widening-cast,
bugprone-multi-level-implicit-pointer-conversion,
bugprone-multiple-statement-macro,
bugprone-non-zero-enum-to-bool-conversion,
bugprone-not-null-terminated-result,
bugprone-redundant-branch-condition,
bugprone-signal-handler,
bugprone-signed-char-misuse,
bugprone-sizeof-expression,
bugprone-spuriously-wake-up-functions,
bugprone-suspicious-enum-usage,
bugprone-suspicious-include,
bugprone-suspicious-memory-comparison,
bugprone-suspicious-memset-usage,
bugprone-suspicious-missing-comma,
bugprone-suspicious-realloc-usage,
bugprone-suspicious-semicolon,
bugprone-suspicious-string-compare,
bugprone-swapped-arguments,
bugprone-switch-missing-default-case,
bugprone-terminating-continue,
bugprone-too-small-loop-variable,
bugprone-unsafe-functions,
bugprone-unused-return-value,
cert-dcl50-cpp,
cert-env33-c,
cert-err34-c,
cert-flp30-c,
cert-err52-cpp,
cppcoreguidelines-init-variables,
cppcoreguidelines-narrowing-conversions,
google-runtime-int,
misc-confusable-identifiers,
misc-definitions-in-headers,
misc-header-include-cycle,
misc-misleading-identifier,
misc-no-recursion,
misc-redundant-expression,
misc-static-assert,
misc-unused-parameters,
modernize-use-bool-literals,
readability-avoid-nested-conditional-operator,
readability-avoid-return-with-void-value,
readability-avoid-unconditional-preprocessor-if,
readability-const-return-type,
readability-duplicate-include,
readability-else-after-return,
readability-function-size,
readability-identifier-length,
readability-implicit-bool-conversion,
readability-inconsistent-declaration-parameter-name,
readability-isolate-declaration,
readability-magic-numbers,
readability-misleading-indentation,
readability-misplaced-array-index,
readability-non-const-parameter,
readability-redundant-casting,
readability-redundant-control-flow,
readability-redundant-declaration,
readability-redundant-preprocessor,
clang-analyzer-core.BitwiseShift,
clang-analyzer-core.CallAndMessage,
clang-analyzer-core.DivideZero,
clang-analyzer-core.NonNullParamChecker,
clang-analyzer-core.NullDereference,
clang-analyzer-core.StackAddressEscape,
clang-analyzer-core.UndefinedBinaryOperatorResult,
clang-analyzer-core.VLASize,
clang-analyzer-core.uninitialized.ArraySubscript,
clang-analyzer-core.uninitialized.Assign,
clang-analyzer-core.uninitialized.Branch,
clang-analyzer-core.uninitialized.CapturedBlockVariable,
clang-analyzer-core.uninitialized.UndefReturn,
clang-analyzer-core.uninitialized.NewArraySize,
clang-analyzer.deadcode.DeadStores,
clang-analyzer.optin.core.EnumCastOutOfRange,
clang-analyzer.optin.performance.Padding,
clang-analyzer.security.cert.env.InvalidPtr,
clang-analyzer.security.FloatLoopCounter,
clang-analyzer.security.insecureAPI.UncheckedReturn,
clang-analyzer.security.insecureAPI.bcmp,
clang-analyzer.security.insecureAPI.bcopy,
clang-analyzer.security.insecureAPI.bzero,
clang-analyzer.security.insecureAPI.getpw,
clang-analyzer.security.insecureAPI.gets,
clang-analyzer.security.insecureAPI.mkstemp,
clang-analyzer.security.insecureAPI.mktemp,
clang-analyzer.security.insecureAPI.rand,
clang-analyzer.security.insecureAPI.strcpy,
clang-analyzer.security.insecureAPI.DeprecatedOrUnsafeBufferHandling,
clang-analyzer-unix.API,
clang-analyzer-unix.Errno,
clang-analyzer-unix.Malloc,
clang-analyzer-unix.MallocSizeof,
clang-analyzer-unix.MismatchedDeallocator,
clang-analyzer-unix.StdCLibraryFunctions,
clang-analyzer-unix.cstring.BadSizeArg,
clang-analyzer-unix.cstring.NullArg,
clang-analyzer-valist.CopyToSelf,
clang-analyzer-valist.Uninitialized,
clang-analyzer-valist.Unterminated,
clang-analyzer-webkit.NoUncountedMemberChecker
# -* disables all default checks. doing this as I want to handpick the checks I want without any interference from clang-tidy's defaults.
ExtraArgs: ['-Wall', '-Wextra', '--std=c23', '-c', '-O0', '--pedantic', '-DDEBUG', '-D_DEBUG']
# extra arguments to pass to the compiler, these have decisive impact on the diagnostics issued as clang-tidy uses the AST generated by the
# clang frontend for static analyses, not the raw source file. and these flags can significantly alter the structure of the AST
FormatStyle: file
# format the source file using the specs in the .clang-format file.
HeaderFileExtensions: ['h', 'cuh']
HeaderFilterRegex: ''
# ignore diagnostics from c++ STL headers.
ImplementationFileExtensions: ['c', 'cu']
WarningsAsErrors: ''
User: anoban
# Specifies the name or e-mail of the user running clang-tidy. This option is used, for example, to place the correct user name
# in TODO() comments in the relevant check.
UseColor: true
# for the configs in bugprone-argument-comment, clang-tidy uses an arbitraty heuristic to determine how close the comment is to the
# parameter name. it'll issue a diagnostic if the comment in `ago` where the parameter name was `age` but won't when the comment is `address`
# list of required checks
CheckOptions:
- key: bugprone-assert-side-effect.AssertMacros
value: 'assert,static_assert'
- key: bugprone-assert-side-effect.CheckFunctionCalls
value: false
- key: bugprone-assert-side-effect.IgnoredFunctions
value: ''
- key: bugprone-implicit-widening-of-multiplication-result.UseCXXStaticCastsInCppSources
value: false
- key: bugprone-implicit-widening-of-multiplication-result.UseCXXHeadersInCppSources
value: true
- key: bugprone-not-null-terminated-result.WantToUseSafeFunctions
value: true
- key: bugprone-signal-handler.AsyncSafeFunctionSet
value: POSIX
- key: bugprone-sizeof-expression.WarnOnSizeOfConstant
value: true
- key: bugprone-sizeof-expression.WarnOnSizeOfIntegerExpression
value: true
- key: bugprone-sizeof-expression.WarnOnSizeOfCompareToConstant
value: true
- key: bugprone-sizeof-expression.WarnOnSizeOfPointerToAggregate
value: true
- key: bugprone-suspicious-enum-usage.StrictMode
value: 1
- key: bugprone-too-small-loop-variable.MagnitudeBitsUpperLimit
value: 30
- key: google-runtime-int.UnsignedTypePrefix
value: uint
- key: google-runtime-int.SignedTypePrefix
value: int
- key: google-runtime-int.TypeSuffix
value: 32_t
- key: misc-unused-parameters.StrictMode
value: true
- key: readability-function-size.LineThreshold
value: 500
- key: readability-function-size.StatementThreshold
value: 400
- key: readability-function-size.BranchThreshold
value: 100
- key: readability-function-size.ParameterThreshold
value: 6
- key: readability-function-size.NestingThreshold
value: 10
- key: readability-function-size.VariableThreshold
value: 20
- key: readability-identifier-length.MinimumVariableNameLength
value: 3
- key: readability-identifier-length.MinimumParameterNameLength
value: 3
- key: readability-identifier-length.IgnoredParameterNames
value: ^[abcnxy]$
- key: readability-identifier-length.MinimumLoopCounterNameLength
value: 3
- key: readability-identifier-length.IgnoredLoopCounterNames
value: ^[ijn_]$
- key: readability-inconsistent-declaration-parameter-name.IgnoreMacros
value: false
- key: readability-inconsistent-declaration-parameter-name.Strict
value: true
- key: readability-magic-numbers.IgnoredIntegerValues
value: ''
- key: readability-magic-numbers.IgnorePowersOf2IntegerValues
value: false
- key: readability-magic-numbers.IgnoredFloatingPointValues
value: ''
- key: readability-magic-numbers.IgnoreAllFloatingPointValues
value: false
- key: readability-magic-numbers.IgnoreBitFieldsWidths
value: true
- key: readability-magic-numbers.IgnoreTypeAliases
value: false
- key: clang-analyzer-core.BitwiseShift.Pedantic
value: true
- key: clang-analyzer.security.cert.env.InvalidPtr.InvalidatingGetEnv
value: true
- key: cppcoreguidelines-narrowing-conversions.WarnOnIntegerNarrowingConversion
value: true
- key: cppcoreguidelines-narrowing-conversions.WarnOnIntegerToFloatingPointNarrowingConversion
value: true
- key: cppcoreguidelines-narrowing-conversions.WarnOnFloatingPointNarrowingConversion
value: true
- key: cppcoreguidelines-narrowing-conversions.WarnWithinTemplateInstantiation
value: true
- key: cppcoreguidelines-narrowing-conversions.WarnOnEquivalentBitWidth
value: true
- key: cppcoreguidelines-narrowing-conversions.PedanticMode
value: true