added clang-tidy to CI (#3218)

This commit is contained in:
Oliver Stöneberg 2021-04-18 21:51:47 +02:00 committed by GitHub
parent 563c9dd9cc
commit 5de58c4ddd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 68 additions and 16 deletions

View File

@ -1,5 +1,6 @@
--- ---
Checks: '*,-abseil-*,-android-*,-cert-*,-cppcoreguidelines-*,-fuchsia-*,-google-*,-hicpp-*,-linuxkernel-*,-llvm-*,-llvmlibc-*,-mpi-*,-objc-*,-openmp-*,-zircon-*,-readability-braces-around-statements,-readability-magic-numbers,-bugprone-macro-parentheses,-readability-isolate-declaration,-readability-function-size,-modernize-use-trailing-return-type,-readability-implicit-bool-conversion,-readability-uppercase-literal-suffix,-modernize-use-auto,-readability-else-after-return,-modernize-use-default-member-init,-readability-named-parameter,-readability-redundant-member-init,-performance-faster-string-find,-modernize-avoid-c-arrays,-modernize-use-equals-default,-readability-container-size-empty,-readability-simplify-boolean-expr,-modernize-use-override,-modernize-pass-by-value,-bugprone-branch-clone,-bugprone-narrowing-conversions,-modernize-raw-string-literal,-readability-convert-member-functions-to-static,-modernize-loop-convert,-misc-unused-using-decls,-modernize-use-emplace,-readability-const-return-type,-performance-unnecessary-value-param,-modernize-return-braced-init-list,-performance-inefficient-string-concatenation,-performance-for-range-copy,-misc-throw-by-value-catch-by-reference,-readability-avoid-const-params-in-decls,-readability-non-const-parameter,-misc-non-private-member-variables-in-classes,-bugprone-suspicious-string-compare,-readability-misleading-indentation,-misc-unused-parameters-,-clang-analyzer-*,-bugprone-signed-char-misuse,-readability-make-member-function-const,-misc-no-recursion,-readability-use-anyofallof,-performance-no-automatic-move,-bugprone-suspicious-include,-modernize-replace-random-shuffle' Checks: '*,-abseil-*,-android-*,-cert-*,-cppcoreguidelines-*,-fuchsia-*,-google-*,-hicpp-*,-linuxkernel-*,-llvm-*,-llvmlibc-*,-mpi-*,-objc-*,-openmp-*,-zircon-*,-readability-braces-around-statements,-readability-magic-numbers,-bugprone-macro-parentheses,-readability-isolate-declaration,-readability-function-size,-modernize-use-trailing-return-type,-readability-implicit-bool-conversion,-readability-uppercase-literal-suffix,-modernize-use-auto,-readability-else-after-return,-modernize-use-default-member-init,-readability-named-parameter,-readability-redundant-member-init,-performance-faster-string-find,-modernize-avoid-c-arrays,-modernize-use-equals-default,-readability-container-size-empty,-readability-simplify-boolean-expr,-modernize-use-override,-modernize-pass-by-value,-bugprone-branch-clone,-bugprone-narrowing-conversions,-modernize-raw-string-literal,-readability-convert-member-functions-to-static,-modernize-loop-convert,-misc-unused-using-decls,-modernize-use-emplace,-readability-const-return-type,-performance-unnecessary-value-param,-modernize-return-braced-init-list,-performance-inefficient-string-concatenation,-performance-for-range-copy,-misc-throw-by-value-catch-by-reference,-readability-avoid-const-params-in-decls,-readability-non-const-parameter,-misc-non-private-member-variables-in-classes,-bugprone-suspicious-string-compare,-readability-misleading-indentation,-clang-analyzer-*,-bugprone-signed-char-misuse,-readability-make-member-function-const,-misc-no-recursion,-readability-use-anyofallof,-performance-no-automatic-move,-bugprone-suspicious-include,-modernize-replace-random-shuffle'
WarningsAsErrors: '*'
CheckOptions: CheckOptions:
- key: misc-non-private-member-variables-in-classes.IgnoreClassesWithAllMemberVariablesBeingPublic - key: misc-non-private-member-variables-in-classes.IgnoreClassesWithAllMemberVariablesBeingPublic
value: '1' value: '1'

44
.github/workflows/clang-tidy.yml vendored Normal file
View File

@ -0,0 +1,44 @@
# Syntax reference https://help.github.com/en/actions/reference/workflow-syntax-for-github-actions
# Environment reference https://help.github.com/en/actions/reference/virtual-environments-for-github-hosted-runners
name: clang-tidy
on: [push, pull_request]
jobs:
build:
strategy:
matrix:
os: [ubuntu-20.04]
fail-fast: false # Prefer quick result
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v2
- name: Install missing software
run: |
sudo apt-get update
sudo apt-get install z3 libz3-dev
sudo apt-get install clang-tidy
- name: Install Qt
uses: jurplel/install-qt-action@v2
with:
modules: 'qtcharts'
- name: Prepare CMake
run: |
mkdir cmake.output
cd cmake.output
# cannot include GUI since we need to generate the ui_*.h files first
cmake -G "Unix Makefiles" -DUSE_Z3=On -DHAVE_RULES=On -DBUILD_TESTS=On -DBUILD_GUI=Off -DWITH_QCHART=Off ..
cd ..
- name: Clang-Tidy
run: |
# make sure the precompiled headers exist
make -C cmake.output lib/CMakeFiles/lib_objs.dir/cmake_pch.hxx.cxx
make -C cmake.output test/CMakeFiles/testrunner.dir/cmake_pch.hxx.cxx
cmake --build cmake.output --target run-clang-tidy 2> /dev/null

View File

@ -1,13 +1,15 @@
find_program(CLANG_TIDY NAMES clang-tidy clang-tidy-11 clang-tidy-10 clang-tidy-9 clang-tidy-8) if (NOT NPROC)
message(STATUS "CLANG_TIDY=${CLANG_TIDY}") include(ProcessorCount)
if (CLANG_TIDY) ProcessorCount(NPROC)
set(CLANG_TIDY_SRCS ${CMAKE_SOURCE_DIR}/cli/*.cpp ${CMAKE_SOURCE_DIR}/lib/*.cpp) if(NPROC EQUAL 0)
if (BUILD_GUI) message(FATAL_ERROR "could not get processor count")
list(APPEND CLANG_TIDY_SRCS ${CMAKE_SOURCE_DIR}/gui/*.cpp)
endif()
if (BUILD_TESTS)
list(APPEND CLANG_TIDY_SRCS ${CMAKE_SOURCE_DIR}/test/*.cpp)
endif() endif()
endif()
message(STATUS "NPROC=${NPROC}")
add_custom_target(run-clang-tidy ${CLANG_TIDY} -p=${CMAKE_BINARY_DIR} ${CLANG_TIDY_SRCS}) find_program(RUN_CLANG_TIDY NAMES run-clang-tidy run-clang-tidy-11 run-clang-tidy-10 run-clang-tidy-9 run-clang-tidy-8)
message(STATUS "RUN_CLANG_TIDY=${RUN_CLANG_TIDY}")
if (RUN_CLANG_TIDY)
# disable all compiler warnings since we are just interested in the tidy ones
add_custom_target(run-clang-tidy ${RUN_CLANG_TIDY} -p=${CMAKE_BINARY_DIR} -j ${NPROC} -extra-arg=-w -quiet)
endif() endif()

4
externals/.clang-tidy vendored Normal file
View File

@ -0,0 +1,4 @@
---
Checks: '-*,misc-definitions-in-headers'
CheckOptions:
- { key: HeaderFileExtensions, value: "x" }

View File

@ -1169,7 +1169,7 @@ static bool isForLoopCondition(const Token * const tok)
/** /**
* Is token used a boolean (cast to a bool, or used as a condition somewhere) * Is token used a boolean (cast to a bool, or used as a condition somewhere)
* @param tok * @param tok the token to check
* @param checkingParent true if we are checking a parent. This is used to know * @param checkingParent true if we are checking a parent. This is used to know
* what we are checking. For instance in `if (i == 2)`, isUsedAsBool("==") is * what we are checking. For instance in `if (i == 2)`, isUsedAsBool("==") is
* true whereas isUsedAsBool("i") is false, but it might call * true whereas isUsedAsBool("i") is false, but it might call

View File

@ -562,6 +562,7 @@ std::vector<CheckClass::Usage> CheckClass::createUsageList(const Scope *scope)
std::vector<Usage> ret; std::vector<Usage> ret;
std::vector<const Variable *> varlist; std::vector<const Variable *> varlist;
getAllVariableMembers(scope, varlist); getAllVariableMembers(scope, varlist);
ret.reserve(varlist.size());
for (const Variable *var: varlist) for (const Variable *var: varlist)
ret.emplace_back(var); ret.emplace_back(var);
return ret; return ret;

View File

@ -424,8 +424,8 @@ void execute(const Token *expr,
else if (expr->isComparisonOp()) { else if (expr->isComparisonOp()) {
MathLib::bigint result1(0), result2(0); MathLib::bigint result1(0), result2(0);
bool error1 = 0; bool error1 = false;
bool error2 = 0; bool error2 = false;
execute(expr->astOperand1(), programMemory, &result1, &error1); execute(expr->astOperand1(), programMemory, &result1, &error1);
execute(expr->astOperand2(), programMemory, &result2, &error2); execute(expr->astOperand2(), programMemory, &result2, &error2);
if (error1 && error2) { if (error1 && error2) {

View File

@ -1815,7 +1815,7 @@ namespace {
const ScopeInfo3 * findScopeRecursive(const std::string & scope) const { const ScopeInfo3 * findScopeRecursive(const std::string & scope) const {
if (fullName.size() < scope.size() && if (fullName.size() < scope.size() &&
fullName == scope.substr(0, fullName.size())) { fullName == scope.substr(0, fullName.size())) {
for (auto & child : children) { for (const auto & child : children) {
if (child.fullName == scope && &child != this) if (child.fullName == scope && &child != this)
return &child; return &child;
else { else {

View File

@ -14,7 +14,7 @@ add_executable(dmake EXCLUDE_FROM_ALL
${CMAKE_SOURCE_DIR}/cli/filelister.cpp ${CMAKE_SOURCE_DIR}/cli/filelister.cpp
${srcs_tools} ${srcs_tools}
${CMAKE_SOURCE_DIR}/lib/utils.cpp ${CMAKE_SOURCE_DIR}/lib/utils.cpp
${CMAKE_SOURCE_DIR}/externals/simplecpp/simplecpp ${CMAKE_SOURCE_DIR}/externals/simplecpp/simplecpp.cpp
) )
target_include_directories(dmake PRIVATE ${CMAKE_SOURCE_DIR}/cli ${CMAKE_SOURCE_DIR}/lib ${CMAKE_SOURCE_DIR}/externals/simplecpp) target_include_directories(dmake PRIVATE ${CMAKE_SOURCE_DIR}/cli ${CMAKE_SOURCE_DIR}/lib ${CMAKE_SOURCE_DIR}/externals/simplecpp)
if (WIN32 AND NOT BORLAND) if (WIN32 AND NOT BORLAND)