Skip to content

Commit fe02e79

Browse files
Add Clang tidy and many fixes (#1047)
1 parent 381612b commit fe02e79

File tree

86 files changed

+862
-556
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

86 files changed

+862
-556
lines changed

.clang-tidy

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
Checks: [
2+
"-*",
3+
"bugprone-*",
4+
"cert-*",
5+
"clang-analyzer-*",
6+
"concurrency-*",
7+
"cppcoreguidelines-*",
8+
"misc-*",
9+
"modernize-*",
10+
"performance-*",
11+
"portability-*",
12+
"readability-*",
13+
"-bugprone-easily-swappable-parameters",
14+
"-bugprone-narrowing-conversions",
15+
"-cert-err58-cpp",
16+
"-cppcoreguidelines-avoid-c-arrays",
17+
"-cppcoreguidelines-avoid-magic-numbers",
18+
"-cppcoreguidelines-avoid-non-const-global-variables",
19+
"-cppcoreguidelines-non-private-member-variables-in-classes",
20+
"-cppcoreguidelines-pro-bounds-array-to-pointer-decay",
21+
"-cppcoreguidelines-pro-bounds-constant-array-index",
22+
"-cppcoreguidelines-pro-bounds-pointer-arithmetic",
23+
"-cppcoreguidelines-pro-type-const-cast",
24+
"-cppcoreguidelines-pro-type-union-access",
25+
"-cppcoreguidelines-pro-type-vararg",
26+
"-misc-no-recursion",
27+
"-misc-non-private-member-variables-in-classes"
28+
]
29+
30+
31+
WarningsAsErrors: '-*,bugprone-*,cert-*,clang-analyzer-*,concurrency-*,cppcoreguidelines-*,misc-*,portability-*,readability-implicit-bool-conversion,-concurrency-mt-unsafe,-readability-function-cognitive-complexity'
32+
33+
CheckOptions:
34+
# ignore macros when computing the cyclomatic complexity. problem caused by RCLCPP LOG macros
35+
- key: readability-function-cognitive-complexity.IgnoreMacros
36+
value: 'true'
37+
38+
# This change makes it compatible with MISRA:2023 rule 4.14.1
39+
- key: misc-non-private-member-variables-in-classes.IgnoreClassesWithAllMemberVariablesBeingPublic
40+
value: 'true'
41+
42+
# Making a copy of a shared_ptr has a non-zero cost, but this cost is small.
43+
# Unfortunately the ROS API (subscriber callbacks) oblige the user to use callbacks functions that will trigger this warning
44+
# This is the reason wht the warning is silenced here
45+
- key: performance-unnecessary-value-param.AllowedTypes
46+
value: 'std::shared_ptr'
47+
48+
# Reference: https://clang.llvm.org/extra/clang-tidy/checks/readability/identifier-naming.html

.github/dependabot.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: "github-actions"
4+
directory: "/"
5+
schedule:
6+
interval: "weekly"

.github/workflows/pre-commit.yaml

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,29 @@ jobs:
1111
pre-commit:
1212
runs-on: ubuntu-latest
1313
steps:
14-
- uses: actions/checkout@v3
15-
- uses: actions/setup-python@v3
14+
- uses: actions/checkout@v4
15+
- uses: actions/setup-python@v5
1616
- uses: pre-commit/action@v3.0.1
17+
18+
clang-tidy:
19+
runs-on: ubuntu-latest
20+
steps:
21+
- uses: actions/checkout@v4
22+
23+
- name: Install LLVM 21
24+
run: |
25+
wget https://apt.llvm.org/llvm.sh
26+
chmod +x llvm.sh
27+
sudo ./llvm.sh 21
28+
sudo apt-get install -y clangd-21 clang-tidy-21
29+
30+
- name: Install dependencies
31+
run: |
32+
sudo apt-get update
33+
sudo apt-get install -y libzmq3-dev libsqlite3-dev
34+
35+
- name: Configure CMake
36+
run: cmake -B build -DBUILD_TESTING=OFF
37+
38+
- name: Run clang-tidy
39+
run: ./run_clang_tidy.sh

.gitignore

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@ site/*
55
/.vscode/
66
.vs/
77

8-
# clangd cache
8+
# clangd cache and config (generated by CMake)
99
/.cache/*
10+
/.clangd
1011
CMakeSettings.json
1112

1213
# OSX junk
@@ -18,3 +19,6 @@ CMakeSettings.json
1819
CMakeUserPresets.json
1920

2021
tags
22+
/clang_tidy_output.log
23+
/.clang-tidy-venv/*
24+
/llvm.sh

.pre-commit-config.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,15 @@ repos:
4343
- id: clang-format
4444
args: ['-fallback-style=none', '-i']
4545

46+
# C++ static analysis (installs clang-tidy automatically via pip)
47+
# - repo: https://github.com/mxmlnrdr/clang_tidy_hook
48+
# rev: v0.3.1
49+
# hooks:
50+
# - id: clang-tidy
51+
# args:
52+
# - --config-file=.clang-tidy
53+
# - -p=build
54+
4655
# Spell check
4756
- repo: https://github.com/codespell-project/codespell
4857
rev: v2.4.1

CMakeLists.txt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,21 @@ if(BTCPP_EXAMPLES)
306306
add_subdirectory(examples)
307307
endif()
308308

309+
######################################################
310+
# Generate .clangd configuration file for standalone header checking
311+
file(WRITE ${CMAKE_SOURCE_DIR}/.clangd
312+
"CompileFlags:
313+
Add:
314+
- -xc++
315+
- -std=c++17
316+
- -I${CMAKE_SOURCE_DIR}/include
317+
- -I${CMAKE_SOURCE_DIR}/3rdparty
318+
- -I${CMAKE_SOURCE_DIR}/3rdparty/minitrace
319+
- -I${CMAKE_SOURCE_DIR}/3rdparty/tinyxml2
320+
- -I${CMAKE_SOURCE_DIR}/3rdparty/minicoro
321+
- -I${CMAKE_SOURCE_DIR}/3rdparty/lexy/include
322+
")
323+
309324
######################################################
310325
# INSTALL
311326

include/behaviortree_cpp/action_node.h

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ class ActionNodeBase : public LeafNode
3838
ActionNodeBase(const std::string& name, const NodeConfig& config);
3939
~ActionNodeBase() override = default;
4040

41+
ActionNodeBase(const ActionNodeBase&) = delete;
42+
ActionNodeBase& operator=(const ActionNodeBase&) = delete;
43+
ActionNodeBase(ActionNodeBase&&) = delete;
44+
ActionNodeBase& operator=(ActionNodeBase&&) = delete;
45+
4146
virtual NodeType type() const override final
4247
{
4348
return NodeType::ACTION;
@@ -55,6 +60,11 @@ class SyncActionNode : public ActionNodeBase
5560
SyncActionNode(const std::string& name, const NodeConfig& config);
5661
~SyncActionNode() override = default;
5762

63+
SyncActionNode(const SyncActionNode&) = delete;
64+
SyncActionNode& operator=(const SyncActionNode&) = delete;
65+
SyncActionNode(SyncActionNode&&) = delete;
66+
SyncActionNode& operator=(SyncActionNode&&) = delete;
67+
5868
/// throws if the derived class return RUNNING.
5969
virtual NodeStatus executeTick() override;
6070

@@ -87,6 +97,11 @@ class SimpleActionNode : public SyncActionNode
8797

8898
~SimpleActionNode() override = default;
8999

100+
SimpleActionNode(const SimpleActionNode&) = delete;
101+
SimpleActionNode& operator=(const SimpleActionNode&) = delete;
102+
SimpleActionNode(SimpleActionNode&&) = delete;
103+
SimpleActionNode& operator=(SimpleActionNode&&) = delete;
104+
90105
protected:
91106
virtual NodeStatus tick() override final;
92107

@@ -197,7 +212,12 @@ class CoroActionNode : public ActionNodeBase
197212
{
198213
public:
199214
CoroActionNode(const std::string& name, const NodeConfig& config);
200-
virtual ~CoroActionNode() override;
215+
~CoroActionNode() override;
216+
217+
CoroActionNode(const CoroActionNode&) = delete;
218+
CoroActionNode& operator=(const CoroActionNode&) = delete;
219+
CoroActionNode(CoroActionNode&&) = delete;
220+
CoroActionNode& operator=(CoroActionNode&&) = delete;
201221

202222
/// Use this method to return RUNNING and temporary "pause" the Action.
203223
void setStatusRunningAndYield();

include/behaviortree_cpp/actions/pop_from_queue.hpp

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -71,18 +71,12 @@ class PopFromQueue : public SyncActionNode
7171
{
7272
return NodeStatus::FAILURE;
7373
}
74-
else
75-
{
76-
T val = items.front();
77-
items.pop_front();
78-
setOutput("popped_item", val);
79-
return NodeStatus::SUCCESS;
80-
}
81-
}
82-
else
83-
{
84-
return NodeStatus::FAILURE;
74+
T val = items.front();
75+
items.pop_front();
76+
setOutput("popped_item", val);
77+
return NodeStatus::SUCCESS;
8578
}
79+
return NodeStatus::FAILURE;
8680
}
8781

8882
static PortsList providedPorts()
@@ -125,11 +119,8 @@ class QueueSize : public SyncActionNode
125119
{
126120
return NodeStatus::FAILURE;
127121
}
128-
else
129-
{
130-
setOutput("size", int(items.size()));
131-
return NodeStatus::SUCCESS;
132-
}
122+
setOutput("size", int(items.size()));
123+
return NodeStatus::SUCCESS;
133124
}
134125
return NodeStatus::FAILURE;
135126
}

include/behaviortree_cpp/actions/sleep_node.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ class SleepNode : public StatefulActionNode
2222
halt();
2323
}
2424

25+
SleepNode(const SleepNode&) = delete;
26+
SleepNode& operator=(const SleepNode&) = delete;
27+
SleepNode(SleepNode&&) = delete;
28+
SleepNode& operator=(SleepNode&&) = delete;
29+
2530
NodeStatus onStart() override;
2631

2732
NodeStatus onRunning() override;
@@ -35,7 +40,7 @@ class SleepNode : public StatefulActionNode
3540

3641
private:
3742
TimerQueue<> timer_;
38-
uint64_t timer_id_;
43+
uint64_t timer_id_ = 0;
3944

4045
std::atomic_bool timer_waiting_ = false;
4146
std::mutex delay_mutex_;

include/behaviortree_cpp/actions/updated_action.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ class EntryUpdatedAction : public SyncActionNode
3030

3131
~EntryUpdatedAction() override = default;
3232

33+
EntryUpdatedAction(const EntryUpdatedAction&) = delete;
34+
EntryUpdatedAction& operator=(const EntryUpdatedAction&) = delete;
35+
EntryUpdatedAction(EntryUpdatedAction&&) = delete;
36+
EntryUpdatedAction& operator=(EntryUpdatedAction&&) = delete;
37+
3338
static PortsList providedPorts()
3439
{
3540
return { InputPort<BT::Any>("entry", "Entry to check") };

0 commit comments

Comments
 (0)