Skip to content

Commit 5de58c4

Browse files
authored
added clang-tidy to CI (cppcheck-opensource#3218)
1 parent 563c9dd commit 5de58c4

9 files changed

Lines changed: 68 additions & 16 deletions

File tree

.clang-tidy

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
---
2-
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'
2+
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'
3+
WarningsAsErrors: '*'
34
CheckOptions:
45
- key: misc-non-private-member-variables-in-classes.IgnoreClassesWithAllMemberVariablesBeingPublic
56
value: '1'

.github/workflows/clang-tidy.yml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Syntax reference https://help.github.com/en/actions/reference/workflow-syntax-for-github-actions
2+
# Environment reference https://help.github.com/en/actions/reference/virtual-environments-for-github-hosted-runners
3+
name: clang-tidy
4+
5+
on: [push, pull_request]
6+
7+
jobs:
8+
build:
9+
10+
strategy:
11+
matrix:
12+
os: [ubuntu-20.04]
13+
fail-fast: false # Prefer quick result
14+
15+
runs-on: ${{ matrix.os }}
16+
17+
steps:
18+
- uses: actions/checkout@v2
19+
20+
- name: Install missing software
21+
run: |
22+
sudo apt-get update
23+
sudo apt-get install z3 libz3-dev
24+
sudo apt-get install clang-tidy
25+
26+
- name: Install Qt
27+
uses: jurplel/install-qt-action@v2
28+
with:
29+
modules: 'qtcharts'
30+
31+
- name: Prepare CMake
32+
run: |
33+
mkdir cmake.output
34+
cd cmake.output
35+
# cannot include GUI since we need to generate the ui_*.h files first
36+
cmake -G "Unix Makefiles" -DUSE_Z3=On -DHAVE_RULES=On -DBUILD_TESTS=On -DBUILD_GUI=Off -DWITH_QCHART=Off ..
37+
cd ..
38+
39+
- name: Clang-Tidy
40+
run: |
41+
# make sure the precompiled headers exist
42+
make -C cmake.output lib/CMakeFiles/lib_objs.dir/cmake_pch.hxx.cxx
43+
make -C cmake.output test/CMakeFiles/testrunner.dir/cmake_pch.hxx.cxx
44+
cmake --build cmake.output --target run-clang-tidy 2> /dev/null

cmake/clang_tidy.cmake

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
1-
find_program(CLANG_TIDY NAMES clang-tidy clang-tidy-11 clang-tidy-10 clang-tidy-9 clang-tidy-8)
2-
message(STATUS "CLANG_TIDY=${CLANG_TIDY}")
3-
if (CLANG_TIDY)
4-
set(CLANG_TIDY_SRCS ${CMAKE_SOURCE_DIR}/cli/*.cpp ${CMAKE_SOURCE_DIR}/lib/*.cpp)
5-
if (BUILD_GUI)
6-
list(APPEND CLANG_TIDY_SRCS ${CMAKE_SOURCE_DIR}/gui/*.cpp)
7-
endif()
8-
if (BUILD_TESTS)
9-
list(APPEND CLANG_TIDY_SRCS ${CMAKE_SOURCE_DIR}/test/*.cpp)
1+
if (NOT NPROC)
2+
include(ProcessorCount)
3+
ProcessorCount(NPROC)
4+
if(NPROC EQUAL 0)
5+
message(FATAL_ERROR "could not get processor count")
106
endif()
7+
endif()
8+
message(STATUS "NPROC=${NPROC}")
119

12-
add_custom_target(run-clang-tidy ${CLANG_TIDY} -p=${CMAKE_BINARY_DIR} ${CLANG_TIDY_SRCS})
10+
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)
11+
message(STATUS "RUN_CLANG_TIDY=${RUN_CLANG_TIDY}")
12+
if (RUN_CLANG_TIDY)
13+
# disable all compiler warnings since we are just interested in the tidy ones
14+
add_custom_target(run-clang-tidy ${RUN_CLANG_TIDY} -p=${CMAKE_BINARY_DIR} -j ${NPROC} -extra-arg=-w -quiet)
1315
endif()

externals/.clang-tidy

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
Checks: '-*,misc-definitions-in-headers'
3+
CheckOptions:
4+
- { key: HeaderFileExtensions, value: "x" }

lib/astutils.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1169,7 +1169,7 @@ static bool isForLoopCondition(const Token * const tok)
11691169

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

lib/checkclass.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -562,6 +562,7 @@ std::vector<CheckClass::Usage> CheckClass::createUsageList(const Scope *scope)
562562
std::vector<Usage> ret;
563563
std::vector<const Variable *> varlist;
564564
getAllVariableMembers(scope, varlist);
565+
ret.reserve(varlist.size());
565566
for (const Variable *var: varlist)
566567
ret.emplace_back(var);
567568
return ret;

lib/programmemory.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -424,8 +424,8 @@ void execute(const Token *expr,
424424

425425
else if (expr->isComparisonOp()) {
426426
MathLib::bigint result1(0), result2(0);
427-
bool error1 = 0;
428-
bool error2 = 0;
427+
bool error1 = false;
428+
bool error2 = false;
429429
execute(expr->astOperand1(), programMemory, &result1, &error1);
430430
execute(expr->astOperand2(), programMemory, &result2, &error2);
431431
if (error1 && error2) {

lib/tokenize.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1815,7 +1815,7 @@ namespace {
18151815
const ScopeInfo3 * findScopeRecursive(const std::string & scope) const {
18161816
if (fullName.size() < scope.size() &&
18171817
fullName == scope.substr(0, fullName.size())) {
1818-
for (auto & child : children) {
1818+
for (const auto & child : children) {
18191819
if (child.fullName == scope && &child != this)
18201820
return &child;
18211821
else {

tools/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ add_executable(dmake EXCLUDE_FROM_ALL
1414
${CMAKE_SOURCE_DIR}/cli/filelister.cpp
1515
${srcs_tools}
1616
${CMAKE_SOURCE_DIR}/lib/utils.cpp
17-
${CMAKE_SOURCE_DIR}/externals/simplecpp/simplecpp
17+
${CMAKE_SOURCE_DIR}/externals/simplecpp/simplecpp.cpp
1818
)
1919
target_include_directories(dmake PRIVATE ${CMAKE_SOURCE_DIR}/cli ${CMAKE_SOURCE_DIR}/lib ${CMAKE_SOURCE_DIR}/externals/simplecpp)
2020
if (WIN32 AND NOT BORLAND)

0 commit comments

Comments
 (0)