Skip to content

Instantly share code, notes, and snippets.

@fbaeuerlein
Last active February 13, 2024 09:31
Show Gist options
  • Save fbaeuerlein/2895f889e451a817d7b2b36fd60e2873 to your computer and use it in GitHub Desktop.
Save fbaeuerlein/2895f889e451a817d7b2b36fd60e2873 to your computer and use it in GitHub Desktop.
A general clang-tidy configuration file
---
Checks: 'clang-diagnostic-*,clang-analyzer-*,cppcoreguidelines-*,modernize-*,-modernize-use-trailing-return-type'
WarningsAsErrors: true
HeaderFilterRegex: ''
AnalyzeTemporaryDtors: false
FormatStyle: google
CheckOptions:
- key: cert-dcl16-c.NewSuffixes
value: 'L;LL;LU;LLU'
- key: cert-oop54-cpp.WarnOnlyIfThisHasSuspiciousField
value: '0'
- key: cppcoreguidelines-explicit-virtual-functions.IgnoreDestructors
value: '1'
- key: cppcoreguidelines-non-private-member-variables-in-classes.IgnoreClassesWithAllMemberVariablesBeingPublic
value: '1'
- key: google-readability-braces-around-statements.ShortStatementLines
value: '1'
- key: google-readability-function-size.StatementThreshold
value: '800'
- key: google-readability-namespace-comments.ShortNamespaceLines
value: '10'
- key: google-readability-namespace-comments.SpacesBeforeComments
value: '2'
- key: modernize-loop-convert.MaxCopySize
value: '16'
- key: modernize-loop-convert.MinConfidence
value: reasonable
- key: modernize-loop-convert.NamingStyle
value: CamelCase
- key: modernize-pass-by-value.IncludeStyle
value: llvm
- key: modernize-replace-auto-ptr.IncludeStyle
value: llvm
- key: modernize-use-nullptr.NullMacros
value: 'NULL'
...
@DavidKroeter84
Copy link

Hi @fbaeuerlein!
How would one integrate the config file using cmake? I have tried the following:

set(CLANG_TIDY_COMMAND ${CLANG_TIDY_EXE} "-config=${CMAKE_SOURCE_DIR}/.clang-tidy")
set_target_properties(test PROPERTIES CXX_CLANG_TIDY "${CLANG_TIDY_COMMAND}")

Apparently the config file is read, but the content does not seem to meet the format expectations:

[build] YAML:1:1: error: not a mapping
[build] C:/Data/Trainings/cpp/twoSum/twoSum/.clang-tidy
[build] ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[build] Error: invalid configuration specified.
[build] invalid argument

Thanks for helping out! ;-)

@SujjithS
Copy link

Even I need to integrate the config file using cmake.
I tried the same way using the -config flag but no luck
@DavidKroeter84 @fbaeuerlein

@mzukovec
Copy link

You can try with -config-file=<path>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment