Skip to content
Open
124 changes: 123 additions & 1 deletion .clang-tidy
Original file line number Diff line number Diff line change
@@ -1,2 +1,124 @@
Checks: 'clang-diagnostic-*,clang-analyzer-*,-*,cert-*,cppcoreguidelines-*,clang-analyzer-*'
---
Checks:
- -*
- cert-*
- cppcoreguidelines-*
- clang-analyzer-*'
WarningsAsErrors: ''
HeaderFileExtensions:
- ''
- h
- hh
- hpp
- hxx
ImplementationFileExtensions:
- c
- cc
- cpp
- cxx
HeaderFilterRegex: ''
ExcludeHeaderFilterRegex: '(?:.*/bsoncxx/enums/.*|.*/(?:prelude|postlude)\.hpp$)'
FormatStyle: none
User: ''
CheckOptions:
cert-arr39-c.WarnOnOffsetDividedBySizeOf: 'true'
cert-arr39-c.WarnOnSizeOfCompareToConstant: 'false'
cert-arr39-c.WarnOnSizeOfConstant: 'false'
cert-arr39-c.WarnOnSizeOfInLoopTermination: 'true'
cert-arr39-c.WarnOnSizeOfIntegerExpression: 'false'
cert-arr39-c.WarnOnSizeOfPointer: 'false'
cert-arr39-c.WarnOnSizeOfPointerToAggregate: 'false'
cert-arr39-c.WarnOnSizeOfThis: 'false'
cert-ctr56-cpp.IgnoreInheritedVirtualFunctions: 'false'
cert-dcl16-c.IgnoreMacros: 'true'
cert-dcl16-c.NewSuffixes: 'L;LL;LU;LLU'
cert-dcl37-c.AggressiveDependentMemberLookup: 'false'
cert-dcl37-c.AllowedIdentifiers: ''
cert-dcl37-c.Invert: 'false'
cert-dcl51-cpp.AggressiveDependentMemberLookup: 'false'
cert-dcl51-cpp.AllowedIdentifiers: ''
cert-dcl51-cpp.Invert: 'false'
cert-err09-cpp.CheckThrowTemporaries: 'true'
cert-err09-cpp.MaxSize: '18446744073709551615'
cert-err09-cpp.WarnOnLargeObjects: 'false'
cert-err33-c.AllowCastToVoid: 'true'
cert-err33-c.CheckedFunctions: '^::aligned_alloc$;^::asctime_s$;^::at_quick_exit$;^::atexit$;^::bsearch$;^::bsearch_s$;^::btowc$;^::c16rtomb$;^::c32rtomb$;^::calloc$;^::clock$;^::cnd_broadcast$;^::cnd_init$;^::cnd_signal$;^::cnd_timedwait$;^::cnd_wait$;^::ctime_s$;^::fclose$;^::fflush$;^::fgetc$;^::fgetpos$;^::fgets$;^::fgetwc$;^::fopen$;^::fopen_s$;^::fprintf$;^::fprintf_s$;^::fputc$;^::fputs$;^::fputwc$;^::fputws$;^::fread$;^::freopen$;^::freopen_s$;^::fscanf$;^::fscanf_s$;^::fseek$;^::fsetpos$;^::ftell$;^::fwprintf$;^::fwprintf_s$;^::fwrite$;^::fwscanf$;^::fwscanf_s$;^::getc$;^::getchar$;^::getenv$;^::getenv_s$;^::gets_s$;^::getwc$;^::getwchar$;^::gmtime$;^::gmtime_s$;^::localtime$;^::localtime_s$;^::malloc$;^::mbrtoc16$;^::mbrtoc32$;^::mbsrtowcs$;^::mbsrtowcs_s$;^::mbstowcs$;^::mbstowcs_s$;^::memchr$;^::mktime$;^::mtx_init$;^::mtx_lock$;^::mtx_timedlock$;^::mtx_trylock$;^::mtx_unlock$;^::printf_s$;^::putc$;^::putwc$;^::raise$;^::realloc$;^::remove$;^::rename$;^::scanf$;^::scanf_s$;^::setlocale$;^::setvbuf$;^::signal$;^::snprintf$;^::snprintf_s$;^::sprintf$;^::sprintf_s$;^::sscanf$;^::sscanf_s$;^::strchr$;^::strerror_s$;^::strftime$;^::strpbrk$;^::strrchr$;^::strstr$;^::strtod$;^::strtof$;^::strtoimax$;^::strtok$;^::strtok_s$;^::strtol$;^::strtold$;^::strtoll$;^::strtoul$;^::strtoull$;^::strtoumax$;^::strxfrm$;^::swprintf$;^::swprintf_s$;^::swscanf$;^::swscanf_s$;^::thrd_create$;^::thrd_detach$;^::thrd_join$;^::thrd_sleep$;^::time$;^::timespec_get$;^::tmpfile$;^::tmpfile_s$;^::tmpnam$;^::tmpnam_s$;^::tss_create$;^::tss_get$;^::tss_set$;^::ungetc$;^::ungetwc$;^::vfprintf$;^::vfprintf_s$;^::vfscanf$;^::vfscanf_s$;^::vfwprintf$;^::vfwprintf_s$;^::vfwscanf$;^::vfwscanf_s$;^::vprintf_s$;^::vscanf$;^::vscanf_s$;^::vsnprintf$;^::vsnprintf_s$;^::vsprintf$;^::vsprintf_s$;^::vsscanf$;^::vsscanf_s$;^::vswprintf$;^::vswprintf_s$;^::vswscanf$;^::vswscanf_s$;^::vwprintf_s$;^::vwscanf$;^::vwscanf_s$;^::wcrtomb$;^::wcschr$;^::wcsftime$;^::wcspbrk$;^::wcsrchr$;^::wcsrtombs$;^::wcsrtombs_s$;^::wcsstr$;^::wcstod$;^::wcstof$;^::wcstoimax$;^::wcstok$;^::wcstok_s$;^::wcstol$;^::wcstold$;^::wcstoll$;^::wcstombs$;^::wcstombs_s$;^::wcstoul$;^::wcstoull$;^::wcstoumax$;^::wcsxfrm$;^::wctob$;^::wctrans$;^::wctype$;^::wmemchr$;^::wprintf_s$;^::wscanf$;^::wscanf_s$'
cert-err33-c.CheckedReturnTypes: '^::std::error_code$;^::std::error_condition$;^::std::errc$;^::std::expected$;^::boost::system::error_code$'
cert-err61-cpp.CheckThrowTemporaries: 'true'
cert-err61-cpp.MaxSize: '18446744073709551615'
cert-err61-cpp.WarnOnLargeObjects: 'false'
cert-int09-c.AllowExplicitSequentialInitialValues: 'true'
cert-int09-c.AllowExplicitZeroFirstInitialValue: 'true'
cert-msc24-c.CustomFunctions: ''
cert-msc24-c.ReportDefaultFunctions: 'true'
cert-msc24-c.ReportMoreUnsafeFunctions: 'true'
cert-msc32-c.DisallowedSeedTypes: 'time_t,std::time_t'
cert-msc33-c.CustomFunctions: ''
cert-msc33-c.ReportDefaultFunctions: 'true'
cert-msc33-c.ReportMoreUnsafeFunctions: 'true'
cert-msc51-cpp.DisallowedSeedTypes: 'time_t,std::time_t'
cert-msc54-cpp.AsyncSafeFunctionSet: POSIX
cert-oop54-cpp.WarnOnlyIfThisHasSuspiciousField: 'false'
cert-oop57-cpp.MemCmpNames: ''
cert-oop57-cpp.MemCpyNames: ''
cert-oop57-cpp.MemSetNames: ''
cert-sig30-c.AsyncSafeFunctionSet: POSIX
cert-str34-c.CharTypdefsToIgnore: ''
cert-str34-c.DiagnoseSignedUnsignedCharComparisons: 'false'
cppcoreguidelines-avoid-c-arrays.AllowStringArrays: 'false'
cppcoreguidelines-avoid-do-while.IgnoreMacros: 'false'
cppcoreguidelines-avoid-goto.IgnoreMacros: 'false'
cppcoreguidelines-avoid-magic-numbers.IgnoreAllFloatingPointValues: 'false'
cppcoreguidelines-avoid-magic-numbers.IgnoreBitFieldsWidths: 'true'
cppcoreguidelines-avoid-magic-numbers.IgnorePowersOf2IntegerValues: 'false'
cppcoreguidelines-avoid-magic-numbers.IgnoreTypeAliases: 'false'
cppcoreguidelines-avoid-magic-numbers.IgnoreUserDefinedLiterals: 'false'
cppcoreguidelines-avoid-magic-numbers.IgnoredFloatingPointValues: '1.0;100.0;'
cppcoreguidelines-avoid-magic-numbers.IgnoredIntegerValues: '1;2;3;4;'
cppcoreguidelines-avoid-non-const-global-variables.AllowInternalLinkage: 'false'
cppcoreguidelines-explicit-virtual-functions.AllowOverrideAndFinal: 'false'
cppcoreguidelines-explicit-virtual-functions.FinalSpelling: final
cppcoreguidelines-explicit-virtual-functions.IgnoreDestructors: 'false'
cppcoreguidelines-explicit-virtual-functions.IgnoreTemplateInstantiations: 'false'
cppcoreguidelines-explicit-virtual-functions.OverrideSpelling: override
cppcoreguidelines-init-variables.IncludeStyle: llvm
cppcoreguidelines-init-variables.MathHeader: '<math.h>'
cppcoreguidelines-macro-usage.AllowedRegexp: '^DEBUG_*'
cppcoreguidelines-macro-usage.CheckCapsOnly: 'false'
cppcoreguidelines-macro-usage.IgnoreCommandLineMacros: 'true'
cppcoreguidelines-missing-std-forward.ForwardFunction: '::std::forward'
cppcoreguidelines-narrowing-conversions.IgnoreConversionFromTypes: ''
cppcoreguidelines-narrowing-conversions.PedanticMode: 'false'
cppcoreguidelines-narrowing-conversions.WarnOnEquivalentBitWidth: 'true'
cppcoreguidelines-narrowing-conversions.WarnOnFloatingPointNarrowingConversion: 'true'
cppcoreguidelines-narrowing-conversions.WarnOnIntegerNarrowingConversion: 'true'
cppcoreguidelines-narrowing-conversions.WarnOnIntegerToFloatingPointNarrowingConversion: 'true'
cppcoreguidelines-narrowing-conversions.WarnWithinTemplateInstantiation: 'false'
cppcoreguidelines-no-malloc.Allocations: '::malloc;::calloc'
cppcoreguidelines-no-malloc.Deallocations: '::free'
cppcoreguidelines-no-malloc.Reallocations: '::realloc'
cppcoreguidelines-no-suspend-with-lock.LockGuards: '::std::unique_lock;::std::scoped_lock;::std::shared_lock;::std::lock_guard'
cppcoreguidelines-non-private-member-variables-in-classes.IgnoreClassesWithAllMemberVariablesBeingPublic: 'true'
cppcoreguidelines-non-private-member-variables-in-classes.IgnorePublicMemberVariables: 'false'
cppcoreguidelines-owning-memory.LegacyResourceConsumers: '::free;::realloc;::freopen;::fclose'
cppcoreguidelines-owning-memory.LegacyResourceProducers: '::malloc;::aligned_alloc;::realloc;::calloc;::fopen;::freopen;::tmpfile'
cppcoreguidelines-pro-bounds-constant-array-index.GslHeader: ''
cppcoreguidelines-pro-bounds-constant-array-index.IncludeStyle: llvm
cppcoreguidelines-pro-type-const-cast.StrictMode: 'false'
cppcoreguidelines-pro-type-member-init.IgnoreArrays: 'false'
cppcoreguidelines-pro-type-member-init.UseAssignment: 'false'
cppcoreguidelines-pro-type-static-cast-downcast.StrictMode: 'true'
cppcoreguidelines-rvalue-reference-param-not-moved.AllowPartialMove: 'false'
cppcoreguidelines-rvalue-reference-param-not-moved.IgnoreNonDeducedTemplateTypes: 'false'
cppcoreguidelines-rvalue-reference-param-not-moved.IgnoreUnnamedParams: 'false'
cppcoreguidelines-rvalue-reference-param-not-moved.MoveFunction: '::std::move'
cppcoreguidelines-special-member-functions.AllowImplicitlyDeletedCopyOrMove: 'false'
cppcoreguidelines-special-member-functions.AllowMissingMoveFunctions: 'false'
cppcoreguidelines-special-member-functions.AllowMissingMoveFunctionsWhenCopyIsDeleted: 'false'
cppcoreguidelines-special-member-functions.AllowSoleDefaultDtor: 'false'
cppcoreguidelines-special-member-functions.IgnoreMacros: 'true'
cppcoreguidelines-use-default-member-init.IgnoreMacros: 'true'
cppcoreguidelines-use-default-member-init.UseAssignment: 'false'
cppcoreguidelines-use-enum-class.IgnoreUnscopedEnumsInClasses: 'false'
SystemHeaders: false
...
44 changes: 9 additions & 35 deletions etc/run-clang-tidy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ install_build_tools
export CMAKE_GENERATOR="Ninja"

uv tool install -q clang-tidy
clang-tidy --version
version="$(clang-tidy --version | perl -lne 'print $1 if m|LLVM version (\d+\.\d+\.\d+)|')"
echo "clang-tidy version: ${version:?}"

# Use ccache if available.
if [[ -f "../mongoc/.evergreen/scripts/find-ccache.sh" ]]; then
Expand All @@ -37,41 +38,14 @@ cmake_config_flags=(
)

# Generate the compilation database file.
cmake -S . -B build "${cmake_config_flags[@]}"
cmake "${cmake_config_flags[@]}" -B build

# Some files (i.e. headers) may need to be generated during the build step.
cmake --build build
mapfile -t sources < <(find src -type f \( -name *.cc -o -name *.cpp \) | perl -lne 'print if m$.*/(?:bsoncxx|mongocxx)/lib/.*$')

#
# Each check has a name and the checks to run can be chosen using the -checks= option, which specifies a comma-separated
# list of positive and negative (prefixed with -) globs. For example:
#
# $ clang-tidy test.cpp -checks=-*,clang-analyzer-*,-clang-analyzer-cplusplus*
#
# will disable all default checks (-*) and enable all clang-analyzer-* checks except for clang-analyzer-cplusplus* ones.
#
# The -list-checks option lists all the enabled checks. When used without -checks=, it shows checks enabled by default.
# Use -checks=* to see all available checks or with any other value of -checks= to see which checks are enabled by this
# value.
#
# see https://clang.llvm.org/extra/clang-tidy
#

echo "Running clang-tidy with configuration:"
clang-tidy -p=build -dump-config

find_args=(
-type f
\( -name *.hh -o -name *.hpp -o -name *.cpp \) # All sources including headers.
-not -path "*/third_party/*" # Excluding third party headers.
-not -path "*/config/*.hpp" # Excluding config headers.
-not -path "*bsoncxx/v_noabi/bsoncxx/enums/*.hpp" # Excluding X macro headers.
clang_tidy_flags=(
--quiet
-p build
--header-filter '.*/(?:bsoncxx|mongocxx)/(?:include|lib)/.*'
)

echo "Scanning the following files:"
find src "${find_args[@]}" | sed -E -e 's/^/ - /'

# TODO: update clang-tidy config and address warnings.
{
find src "${find_args[@]}" | parallel clang-tidy --quiet -p=build {} 2>/dev/null
} || true
printf "%s\n" "${sources[@]}" | parallel -q "${parallel_flags[@]}" clang-tidy "${clang_tidy_flags[@]:?}" {} 2>/dev/null