From 88ae9d6baf7f14b7d3708add3c9ef50757905a4b Mon Sep 17 00:00:00 2001 From: Simon Liu <331435+monadbobo@users.noreply.github.com> Date: Thu, 3 Sep 2020 10:42:33 +0800 Subject: [PATCH] Added the Clang-tidy support (ENABLE_CLANG_TIDY option for CMake). (#214) * Added the Clang-tidy support (ENABLE_CLANG_TIDY option for CMake). * address laura's comment. --- .clang-tidy | 141 +++++++++++++++++++++++++ cmake/ClangTidy.cmake | 13 +++ cmake/ThriftGenerate.cmake | 6 ++ cmake/nebula/GeneralCMakeOptions.cmake | 1 + 4 files changed, 161 insertions(+) create mode 100644 .clang-tidy create mode 100644 cmake/ClangTidy.cmake diff --git a/.clang-tidy b/.clang-tidy new file mode 100644 index 00000000000..ed3c5f554f1 --- /dev/null +++ b/.clang-tidy @@ -0,0 +1,141 @@ +Checks: '-*,clang-diagnostic-*,clang-analyzer-*,-misc-unused-parameters, + + bugprone-argument-comment, + bugprone-assert-side-effect, + bugprone-bad-signal-to-kill-thread, + bugprone-bool-pointer-implicit-conversion, + bugprone-branch-clone, + bugprone-copy-constructor-init, + bugprone-dangling-handle, + bugprone-dynamic-static-initializers, + bugprone-fold-init-type, + bugprone-forward-declaration-namespace, + bugprone-forwarding-reference-overload, + bugprone-inaccurate-erase, + bugprone-incorrect-roundings, + bugprone-infinite-loop, + 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-multiple-statement-macro, + bugprone-not-null-terminated-result, + bugprone-parent-virtual-call, + bugprone-posix-return, + bugprone-reserved-identifier, + bugprone-signed-char-misuse, + bugprone-sizeof-container, + bugprone-sizeof-expression, + 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-memset-usage, + bugprone-suspicious-missing-comma, + bugprone-suspicious-semicolon, + bugprone-suspicious-string-compare, + bugprone-swapped-arguments, + bugprone-terminating-continue, + bugprone-throw-keyword-missing, + bugprone-too-small-loop-variable, + bugprone-undefined-memory-manipulation, + bugprone-undelegated-constructor, + bugprone-unhandled-self-assignment, + bugprone-unused-raii, + bugprone-unused-return-value, + bugprone-use-after-move, + + google-build-explicit-make-pair, + google-build-namespaces, + google-build-using-namespace, + google-default-arguments, + google-explicit-constructor, + google-global-names-in-headers, + google-objc-avoid-nsobject-new, + google-objc-function-naming, + google-objc-global-variable-declaration, + google-readability-avoid-underscore-in-googletest-name, + google-readability-casting, + google-runtime-int, + google-runtime-operator, + google-upgrade-googletest-case, + + modernize-avoid-bind, + modernize-concat-nested-namespaces, + modernize-deprecated-headers, + modernize-deprecated-ios-base-aliases, + modernize-loop-convert, + modernize-make-shared, + modernize-make-unique, + modernize-raw-string-literal, + modernize-redundant-void-arg, + modernize-replace-auto-ptr, + modernize-replace-random-shuffle, + modernize-return-braced-init-list, + modernize-shrink-to-fit, + modernize-unary-static-assert, + modernize-use-bool-literals, + modernize-use-default-member-init, + modernize-use-emplace, + modernize-use-equals-default, + modernize-use-equals-delete, + modernize-use-nodiscard, + modernize-use-nullptr, + modernize-use-override, + modernize-use-trailing-return-type, + modernize-use-transparent-functors, + modernize-use-using, + + 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-constructor-init, + performance-no-automatic-move, + performance-trivially-destructible, + performance-type-promotion-in-math-fn, + performance-unnecessary-copy-initialization, +' + +HeaderFilterRegex: '/(?!third-party)|(?!interface)/' +AnalyzeTemporaryDtors: false +FormatStyle: 'file' +WarningsAsErrors: '*' +CheckOptions: + - key: cert-dcl16-c.NewSuffixes + value: 'L;LL;LU;LLU' + - 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' + - key: readability-identifier-naming.EnumConstantCase + value: CamelCase + - key: readability-identifier-naming.EnumConstantPrefix + value: k + diff --git a/cmake/ClangTidy.cmake b/cmake/ClangTidy.cmake new file mode 100644 index 00000000000..0abca6b4ea5 --- /dev/null +++ b/cmake/ClangTidy.cmake @@ -0,0 +1,13 @@ +if (ENABLE_CLANG_TIDY) + if (${CMAKE_VERSION} VERSION_LESS "3.6.0") + message(FATAL_ERROR "clang-tidy requires CMake version at least 3.6.") + endif() + + find_program (CLANG_TIDY_PATH NAMES "clang-tidy") + if (CLANG_TIDY_PATH) + message(STATUS "Using clang-tidy: ${CLANG_TIDY_PATH}.") + set (CMAKE_CXX_CLANG_TIDY ${CLANG_TIDY_PATH} --config=) + else () + message(STATUS "clang-tidy is not found.") + endif () +endif () diff --git a/cmake/ThriftGenerate.cmake b/cmake/ThriftGenerate.cmake index aafa8d7d2d3..1dd2c15585c 100644 --- a/cmake/ThriftGenerate.cmake +++ b/cmake/ThriftGenerate.cmake @@ -98,6 +98,12 @@ add_library( OBJECT ${${file_name}-cpp2-SOURCES} ) + +set_target_properties( + "${file_name}_thrift_obj" + PROPERTIES CXX_CLANG_TIDY "" +) + target_compile_options(${file_name}_thrift_obj PRIVATE "-Wno-pedantic") target_compile_options(${file_name}_thrift_obj PRIVATE "-Wno-extra") export( diff --git a/cmake/nebula/GeneralCMakeOptions.cmake b/cmake/nebula/GeneralCMakeOptions.cmake index 35fa8aada39..896c6dce1b3 100644 --- a/cmake/nebula/GeneralCMakeOptions.cmake +++ b/cmake/nebula/GeneralCMakeOptions.cmake @@ -15,6 +15,7 @@ option(ENABLE_STRICT_ALIASING "Build with -fstrict-aliasing" OFF) option(ENABLE_COVERAGE "Build with coverage report" OFF) option(ENABLE_PIC "Build with -fPIC" OFF) option(ENABLE_COMPRESSED_DEBUG_INFO "Compress debug info to reduce binary size" ON) +option(ENABLE_CLANG_TIDY "Enable clang-tidy if present" OFF) get_cmake_property(variable_list VARIABLES) foreach(_varname ${variable_list})