-
Notifications
You must be signed in to change notification settings - Fork 0
/
.clang-tidy
417 lines (372 loc) · 18.3 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
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
# 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!
# Here is a list of slow checks that were initially enabled, now removed to improve lint time.
# REMEMBER THESE ARE C++ PROBLEMS, DOESN'T APPLY TO LINTING C SOURCES.
# misc-const-correctness, readability-uppercase-literal-suffix, bugprone-standalone-empty, modernize-use-std-numbers, bugprone-unused-return-value,
# bugprone-assert-side-effect, cppcoreguidelines-pro-bounds-array-to-pointer-decay, modernize-use-nullptr, misc-unused-using-decls,
# bugprone-stringview-nullptr, bugprone-infinite-loop, readability-non-const-parameter, readability-container-size-empty, bugprone-suspicious-string-compare,
# misc-redundant-expression, modernize-type-traits, misc-confusable-identifiers, bugprone-implicit-widening-of-multiplication-result, readability-redundant-control-flow,
# readability-identifier-length, bugprone-multiple-statement-macro, bugprone-suspicious-semicolon, bugprone-sizeof-expression, bugprone-inc-dec-in-conditions,
# readability-redundant-casting, modernize-use-bool-literals,
Checks: >
-*,
bugprone-assignment-in-if-condition,
bugprone-bool-pointer-implicit-conversion,
bugprone-branch-clone,
bugprone-casting-through-void,
bugprone-chained-comparison,
bugprone-compare-pointer-to-member-virtual-function,
bugprone-copy-constructor-init,
bugprone-crtp-constructor-accessibility,
bugprone-dangling-handle,
bugprone-dynamic-static-initializers,
bugprone-empty-catch,
bugprone-exception-escape,
bugprone-fold-init-type,
bugprone-forward-declaration-namespace,
bugprone-forwarding-reference-overload,
bugprone-inaccurate-erase,
bugprone-incorrect-enable-if,
bugprone-incorrect-roundings,
bugprone-integer-division,
bugprone-lambda-function-name,
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-move-forwarding-reference,
bugprone-multi-level-implicit-pointer-conversion,
bugprone-multiple-new-in-one-expression,
bugprone-non-zero-enum-to-bool-conversion,
bugprone-not-null-terminated-result,
bugprone-redundant-branch-condition,
bugprone-shared-ptr-array-mismatch,
bugprone-signal-handler,
bugprone-signed-char-misuse,
bugprone-sizeof-container,
bugprone-spuriously-wake-up-functions,
bugprone-string-constructor,
bugprone-string-integer-assignment,
bugprone-string-literal-with-embedded-nul,
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-stringview-data-usage,
bugprone-swapped-arguments,
bugprone-switch-missing-default-case,
bugprone-terminating-continue,
bugprone-throw-keyword-missing,
bugprone-too-small-loop-variable,
bugprone-unchecked-optional-access,
bugprone-undefined-memory-manipulation,
bugprone-undelegated-constructor,
bugprone-unhandled-exception-at-new,
bugprone-unhandled-self-assignment,
bugprone-unique-ptr-array-mismatch,
bugprone-unsafe-functions,
bugprone-unused-local-non-trivial-variable,
bugprone-unused-raii,
bugprone-use-after-move,
bugprone-virtual-near-miss,
cert-dcl50-cpp,
cert-dcl58-cpp,
cert-env33-c,
cert-err34-c,
cert-flp30-c,
cert-err52-cpp,
cert-err58-cpp,
cert-err60-cpp,
cert-mem57-cpp,
cert-oop57-cpp,
cert-oop58-cpp,
cppcoreguidelines-avoid-capturing-lambda-coroutines,
cppcoreguidelines-avoid-const-or-ref-data-members,
cppcoreguidelines-avoid-non-const-global-variables,
cppcoreguidelines-avoid-reference-coroutine-parameters,
cppcoreguidelines-init-variables,
cppcoreguidelines-interfaces-global-init,
cppcoreguidelines-macro-usage,
cppcoreguidelines-misleading-capture-default-by-value,
cppcoreguidelines-missing-std-forward,
cppcoreguidelines-narrowing-conversions,
cppcoreguidelines-no-suspend-with-lock,
cppcoreguidelines-prefer-member-initializer,
cppcoreguidelines-pro-bounds-constant-array-index,
cppcoreguidelines-pro-bounds-pointer-arithmetic,
cppcoreguidelines-pro-type-const-cast,
cppcoreguidelines-pro-type-cstyle-cast,
cppcoreguidelines-pro-type-member-init,
cppcoreguidelines-pro-type-static-cast-downcast,
cppcoreguidelines-pro-type-union-access,
cppcoreguidelines-pro-type-vararg,
cppcoreguidelines-rvalue-reference-param-not-moved,
cppcoreguidelines-slicing,
cppcoreguidelines-special-member-functions,
cppcoreguidelines-virtual-class-destructor,
google-build-namespaces,
google-build-using-namespace,
google-explicit-constructor,
google-runtime-operator,
misc-coroutine-hostile-raii,
misc-definitions-in-headers,
misc-header-include-cycle,
misc-misplaced-const,
misc-new-delete-overloads,
misc-no-recursion,
misc-non-private-member-variables-in-classes,
misc-static-assert,
misc-throw-by-value-catch-by-reference,
misc-unconventional-assign-operator,
misc-unused-alias-decls,
misc-unused-parameters,
modernize-avoid-c-arrays,
modernize-concat-nested-namespaces,
modernize-deprecated-headers,
modernize-deprecated-ios-base-aliases,
modernize-raw-string-literal,
modernize-redundant-void-arg,
modernize-replace-random-shuffle,
modernize-return-braced-init-list,
modernize-use-constraints,
modernize-use-designated-initializers,
modernize-use-emplace,
modernize-use-equals-default,
modernize-use-equals-delete,
modernize-use-override,
modernize-use-uncaught-exceptions,
modernize-use-using,
performance-avoid-endl,
performance-enum-size,
performance-faster-string-find,
performance-for-range-copy,
performance-implicit-conversion-in-loop,
performance-inefficient-algorithm,
performance-inefficient-string-concatenation,
performance-inefficient-vector-operation,
performance-move-const-arg,
performance-no-int-to-ptr,
performance-noexcept-destructor,
performance-noexcept-move-constructor,
performance-trivially-destructible,
performance-type-promotion-in-math-fn,
performance-unnecessary-copy-initialization,
performance-unnecessary-value-param,
readability-avoid-const-params-in-decls,
readability-avoid-nested-conditional-operator,
readability-avoid-return-with-void-value,
readability-avoid-unconditional-preprocessor-if,
readability-const-return-type,
readability-convert-member-functions-to-static,
readability-delete-null-pointer,
readability-duplicate-include,
readability-else-after-return,
readability-enum-initial-value,
readability-inconsistent-declaration-parameter-name,
readability-isolate-declaration,
readability-make-member-function-const,
readability-misleading-indentation,
readability-misplaced-array-index,
readability-qualified-auto,
readability-redundant-access-specifiers,
readability-redundant-declaration,
readability-redundant-function-ptr-dereference,
readability-redundant-inline-specifier,
readability-redundant-member-init,
readability-redundant-preprocessor,
readability-redundant-smartptr-get,
readability-redundant-string-cstr,
readability-redundant-string-init,
readability-reference-to-constructed-temporary,
readability-simplify-boolean-expr,
readability-simplify-subscript-expr,
readability-static-accessed-through-instance,
readability-static-definition-in-anonymous-namespace,
readability-string-compare,
readability-uniqueptr-delete-release,
readability-use-anyofallof,
readability-use-std-min-max,
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-cplusplus.ArrayDelete,
clang-analyzer-cplusplus.InnerPointer,
clang-analyzer-cplusplus.NewDelete,
clang-analyzer-cplusplus.NewDeleteLeaks,
clang-analyzer-cplusplus.PlacementNew,
clang-analyzer-cplusplus.SelfAssignment,
clang-analyzer-cplusplus.StringChecker,
clang-analyzer.deadcode.DeadStores,
clang-analyzer.optin.core.EnumCastOutOfRange,
clang-analyzer.optin.cplusplus.UninitializedObject,
clang-analyzer.optin.cplusplus.VirtualCall,
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=c++20', '-c', '-O0', '--pedantic', '-DDEBUG', '-D_DEBUG', '-I./']
# 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: ['hpp', 'cuh', '']
HeaderFilterRegex: ''
# ignore diagnostics from c++ STL headers.
ImplementationFileExtensions: ['cpp', 'cu']
WarningsAsErrors: '-*'
# treat all clang-tidy warnings as errors, similar to -Werr or /WX, but for linting
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-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: misc-unused-parameters.StrictMode
value: true
- key: readability-enum-initial-value.AllowExplicitZeroFirstInitialValue
value: true
- key: readability-enum-initial-value.AllowExplicitSequentialInitialValues
value: true
- key: readability-inconsistent-declaration-parameter-name.IgnoreMacros
value: false
- key: readability-inconsistent-declaration-parameter-name.Strict
value: true
- key: readability-redundant-inline-specifier.StrictMode
value: true
- key: readability-uppercase-literal-suffix.NewSuffixes
value: 'L;LU;LLU;I8;U8,I16,U16,I32,U32,I64,U64'
- 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
- key: cppcoreguidelines-pro-type-const-cast.StrictMode
value: true
- key: cppcoreguidelines-pro-type-member-init.IgnoreArrays
value: true
- key: misc-non-private-member-variables-in-classes.IgnoreClassesWithAllMemberVariablesBeingPublic
value: true
- key: misc-non-private-member-variables-in-classes.IgnorePublicMemberVariables
value: true
- key: misc-throw-by-value-catch-by-reference.CheckThrowTemporaries
value: true
- key: misc-throw-by-value-catch-by-reference.WarnOnLargeObject
value: true
- key: misc-throw-by-value-catch-by-reference.MaxSize
value: 8