Skip to content

Commit 5da564b

Browse files
committed
style: apply clang-format and fix clang-tidy warnings
- Reformat all C++ files using custom .clang-format config - Fix performance-inefficient-string-concatenation warnings - Configure CMakeLists.txt to use custom clang-format/clang-tidy configs - Exclude cpplint (conflicts with clang-format include order)
1 parent fa21035 commit 5da564b

27 files changed

+1474
-1796
lines changed

.clang-format

Lines changed: 83 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,78 +1,99 @@
11
---
2-
BasedOnStyle: Google
3-
ColumnLimit: 120
2+
BasedOnStyle: Google
3+
Language: Cpp
4+
5+
ColumnLimit: 120
6+
IndentWidth: 2
7+
TabWidth: 2
8+
UseTab: Never
49
MaxEmptyLinesToKeep: 1
5-
SortIncludes: false
610

7-
Standard: Auto
8-
IndentWidth: 2
9-
TabWidth: 2
10-
UseTab: Never
11-
AccessModifierOffset: -2
12-
ConstructorInitializerIndentWidth: 2
13-
NamespaceIndentation: None
14-
ContinuationIndentWidth: 4
15-
IndentCaseLabels: true
16-
IndentFunctionDeclarationAfterType: false
11+
Standard: c++17
1712

18-
AlignEscapedNewlinesLeft: false
19-
AlignTrailingComments: true
13+
# Pointers & References - ROS 2 style (spaces around * and &)
14+
DerivePointerAlignment: false
15+
PointerAlignment: Middle
16+
ReferenceAlignment: Middle
17+
18+
# Spaces
19+
SpaceBeforeParens: ControlStatements
20+
SpacesInAngles: false
21+
SpaceAfterCStyleCast: false
22+
SpaceBeforeAssignmentOperators: true
2023

21-
AllowAllParametersOfDeclarationOnNextLine: false
22-
ExperimentalAutoDetectBinPacking: false
23-
ObjCSpaceBeforeProtocolList: true
24-
Cpp11BracedListStyle: false
24+
# Templates
25+
AlwaysBreakTemplateDeclarations: Yes
2526

26-
AllowShortBlocksOnASingleLine: true
27-
AllowShortIfStatementsOnASingleLine: false
28-
AllowShortLoopsOnASingleLine: false
29-
AllowShortFunctionsOnASingleLine: None
30-
AllowShortCaseLabelsOnASingleLine: false
27+
# Binary/Ternary operators
28+
BreakBeforeBinaryOperators: None
29+
BreakBeforeTernaryOperators: true
3130

32-
AlwaysBreakTemplateDeclarations: true
33-
AlwaysBreakBeforeMultilineStrings: false
34-
BreakBeforeBinaryOperators: false
35-
BreakBeforeTernaryOperators: false
36-
BreakConstructorInitializersBeforeComma: true
31+
# Constructor initializers (modern syntax - replaces deprecated options)
32+
BreakConstructorInitializers: BeforeComma
33+
ConstructorInitializerIndentWidth: 2
34+
PackConstructorInitializers: NextLine
3735

38-
BinPackParameters: true
39-
ConstructorInitializerAllOnOneLineOrOnePerLine: true
40-
DerivePointerBinding: false
41-
PointerBindsToType: true
36+
# Short statements
37+
AllowShortBlocksOnASingleLine: Never
38+
AllowShortIfStatementsOnASingleLine: Never
39+
AllowShortLoopsOnASingleLine: false
40+
AllowShortCaseLabelsOnASingleLine: false
41+
AllowShortFunctionsOnASingleLine: None
42+
AllowShortLambdasOnASingleLine: Empty
4243

43-
PenaltyExcessCharacter: 50
44-
PenaltyBreakBeforeFirstCallParameter: 30
45-
PenaltyBreakComment: 1000
46-
PenaltyBreakFirstLessLess: 10
47-
PenaltyBreakString: 100
48-
PenaltyReturnTypeOnItsOwnLine: 50
44+
# Braces
45+
InsertBraces: true
46+
BraceWrapping:
47+
AfterCaseLabel: false
48+
AfterClass: false
49+
AfterControlStatement: Never
50+
AfterEnum: false
51+
AfterFunction: false
52+
AfterNamespace: false
53+
AfterStruct: false
54+
AfterUnion: false
55+
BeforeCatch: false
56+
BeforeElse: false
57+
IndentBraces: false
58+
SplitEmptyFunction: false
59+
SplitEmptyRecord: false
60+
SplitEmptyNamespace: false
4961

62+
# Comments
63+
AlignTrailingComments: true
5064
SpacesBeforeTrailingComments: 2
51-
SpacesInParentheses: false
52-
SpacesInAngles: false
53-
SpaceInEmptyParentheses: false
54-
SpacesInCStyleCastParentheses: false
55-
SpaceAfterCStyleCast: false
56-
SpaceAfterControlStatementKeyword: true
57-
SpaceBeforeAssignmentOperators: true
65+
ReflowComments: true
5866

59-
# Configure each individual brace in BraceWrapping
60-
BreakBeforeBraces: Custom
67+
# Includes - ROS 2 friendly
68+
SortIncludes: CaseSensitive
69+
IncludeBlocks: Preserve
70+
IncludeCategories:
71+
- Regex: '^<.*>'
72+
Priority: 1
73+
- Regex: '^"rclcpp/.*"'
74+
Priority: 2
75+
- Regex: '^".*"'
76+
Priority: 3
6177

62-
# Qualifiers (const, volatile, static, etc)
78+
# Qualifiers
6379
QualifierAlignment: Custom
6480
QualifierOrder: ['static', 'inline', 'constexpr', 'const', 'volatile', 'type']
6581

66-
# Control of individual brace wrapping cases
67-
BraceWrapping:
68-
AfterCaseLabel: true
69-
AfterClass: true
70-
AfterControlStatement: true
71-
AfterEnum: true
72-
AfterFunction: true
73-
AfterNamespace: true
74-
AfterStruct: true
75-
AfterUnion: true
76-
BeforeCatch: true
77-
BeforeElse: true
78-
IndentBraces: false
82+
# Modern C++ options
83+
InsertNewlineAtEOF: true
84+
SeparateDefinitionBlocks: Leave
85+
EmptyLineAfterAccessModifier: Never
86+
EmptyLineBeforeAccessModifier: LogicalBlock
87+
88+
# Alignment
89+
AlignAfterOpenBracket: Align
90+
AlignOperands: Align
91+
AlignEscapedNewlines: Left
92+
93+
# Penalties (prefer breaking at certain places)
94+
PenaltyBreakBeforeFirstCallParameter: 19
95+
PenaltyBreakComment: 300
96+
PenaltyBreakFirstLessLess: 120
97+
PenaltyBreakString: 1000
98+
PenaltyExcessCharacter: 1000000
99+
PenaltyReturnTypeOnItsOwnLine: 60

.clang-tidy

Lines changed: 4 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
---
2+
# Clang-tidy configuration for ROS 2 Medkit Gateway
3+
# ROS 2 uses snake_case convention for methods/functions, so we disable
4+
# identifier-naming rules that would conflict with ROS 2 style guidelines.
25
Checks: '-*,
36
performance-*,
47
-performance-enum-size,
@@ -18,7 +21,6 @@ Checks: '-*,
1821
readability-redundant-string-cstr,
1922
readability-simplify-boolean-expr,
2023
readability-container-size-empty,
21-
readability-identifier-naming,
2224
readability-static-definition-in-anonymous-namespace,
2325
'
2426
HeaderFilterRegex: ''
@@ -30,36 +32,4 @@ CheckOptions:
3032
- key: misc-unused-parameters.StrictMode
3133
value: '1'
3234
- key: readability-braces-around-statements.ShortStatementLines
33-
value: '2'
34-
# type names
35-
- key: readability-identifier-naming.ClassCase
36-
value: CamelCase
37-
- key: readability-identifier-naming.EnumCase
38-
value: CamelCase
39-
- key: readability-identifier-naming.UnionCase
40-
value: CamelCase
41-
# function names
42-
- key: readability-identifier-naming.FunctionCase
43-
value: camelBack
44-
# method names
45-
- key: readability-identifier-naming.MethodCase
46-
value: camelBack
47-
# variable names
48-
- key: readability-identifier-naming.VariableCase
49-
value: lower_case
50-
- key: readability-identifier-naming.ProtectedMemberSuffix
51-
value: '_'
52-
- key: readability-identifier-naming.PrivateMemberSuffix
53-
value: '_'
54-
# const static or global variables are UPPER_CASE
55-
- key: readability-identifier-naming.EnumConstantCase
56-
value: UPPER_CASE
57-
- key: readability-identifier-naming.StaticVariableCasePrefix
58-
value: 's_'
59-
- key: readability-identifier-naming.StaticConstantCase
60-
value: UPPER_CASE
61-
- key: readability-identifier-naming.GlobalConstantCase
62-
value: UPPER_CASE
63-
- key: readability-identifier-naming.ClassConstantCase
64-
value: UPPER_CASE
65-
...
35+
value: '2'

.devcontainer/Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ RUN DEBIAN_FRONTEND=noninteractive apt-get update && apt-get install -y \
3333
yq \
3434
ca-certificates \
3535
clang-format \
36+
clang-tidy \
3637
graphviz \
3738
plantuml \
3839
&& locale-gen en_US.UTF-8 \

src/ros2_medkit_gateway/CMakeLists.txt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ project(ros2_medkit_gateway)
33

44
set(CMAKE_CXX_STANDARD 23)
55
set(CMAKE_CXX_STANDARD_REQUIRED ON)
6+
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
67

78
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
89
add_compile_options(-Wall -Wextra -Wpedantic)
@@ -63,8 +64,13 @@ install(DIRECTORY launch config
6364
if(BUILD_TESTING)
6465
# Linting and code quality checks
6566
find_package(ament_lint_auto REQUIRED)
66-
# Exclude uncrustify since we use clang-format
67-
list(APPEND AMENT_LINT_AUTO_EXCLUDE ament_cmake_uncrustify)
67+
68+
# Use custom clang-format and clang-tidy configs from repo root
69+
set(ament_cmake_clang_format_CONFIG_FILE "${CMAKE_CURRENT_SOURCE_DIR}/../../.clang-format")
70+
set(ament_cmake_clang_tidy_CONFIG_FILE "${CMAKE_CURRENT_SOURCE_DIR}/../../.clang-tidy")
71+
72+
# Exclude uncrustify (conflicts with clang-format) and cpplint (conflicts with clang-format include order)
73+
list(APPEND AMENT_LINT_AUTO_EXCLUDE ament_cmake_uncrustify ament_cmake_cpplint)
6874
ament_lint_auto_find_test_dependencies()
6975

7076
# Add GTest

src/ros2_medkit_gateway/include/ros2_medkit_gateway/data_access_manager.hpp

Lines changed: 32 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -15,66 +15,53 @@
1515
#pragma once
1616

1717
#include <memory>
18+
#include <nlohmann/json.hpp>
19+
#include <rclcpp/rclcpp.hpp>
1820
#include <string>
1921
#include <vector>
2022

21-
#include <rclcpp/rclcpp.hpp>
22-
#include <nlohmann/json.hpp>
23-
24-
#include "ros2_medkit_gateway/ros2_cli_wrapper.hpp"
2523
#include "ros2_medkit_gateway/output_parser.hpp"
24+
#include "ros2_medkit_gateway/ros2_cli_wrapper.hpp"
2625

2726
namespace ros2_medkit_gateway {
2827

2928
using json = nlohmann::json;
3029

3130
class DataAccessManager {
32-
public:
33-
explicit DataAccessManager(rclcpp::Node* node);
31+
public:
32+
explicit DataAccessManager(rclcpp::Node * node);
3433

35-
/**
36-
* @brief Get a single sample from a specific topic
37-
*/
38-
json get_topic_sample(
39-
const std::string& topic_name,
40-
double timeout_sec = 3.0
41-
);
34+
/**
35+
* @brief Get a single sample from a specific topic
36+
*/
37+
json get_topic_sample(const std::string & topic_name, double timeout_sec = 3.0);
4238

43-
/**
44-
* @brief Get all data from topics under a component's namespace
45-
*/
46-
json get_component_data(
47-
const std::string& component_namespace,
48-
double timeout_sec = 3.0
49-
);
39+
/**
40+
* @brief Get all data from topics under a component's namespace
41+
*/
42+
json get_component_data(const std::string & component_namespace, double timeout_sec = 3.0);
5043

51-
/**
52-
* @brief Publish data to a specific topic
53-
* @param topic_path Full topic path (e.g., /chassis/brakes/command)
54-
* @param msg_type ROS 2 message type (e.g., std_msgs/msg/Float32)
55-
* @param data JSON data to publish
56-
* @param timeout_sec Timeout for the publish operation
57-
* @return JSON with publish status
58-
*/
59-
json publish_to_topic(
60-
const std::string& topic_path,
61-
const std::string& msg_type,
62-
const json& data,
63-
double timeout_sec = 5.0
64-
);
44+
/**
45+
* @brief Publish data to a specific topic
46+
* @param topic_path Full topic path (e.g., /chassis/brakes/command)
47+
* @param msg_type ROS 2 message type (e.g., std_msgs/msg/Float32)
48+
* @param data JSON data to publish
49+
* @param timeout_sec Timeout for the publish operation
50+
* @return JSON with publish status
51+
*/
52+
json publish_to_topic(const std::string & topic_path, const std::string & msg_type, const json & data,
53+
double timeout_sec = 5.0);
6554

66-
private:
67-
/**
68-
* @brief Find all topics under a given namespace
69-
*/
70-
std::vector<std::string> find_component_topics(
71-
const std::string& component_namespace
72-
);
55+
private:
56+
/**
57+
* @brief Find all topics under a given namespace
58+
*/
59+
std::vector<std::string> find_component_topics(const std::string & component_namespace);
7360

74-
rclcpp::Node* node_;
75-
std::unique_ptr<ROS2CLIWrapper> cli_wrapper_;
76-
std::unique_ptr<OutputParser> output_parser_;
77-
int max_parallel_samples_;
61+
rclcpp::Node * node_;
62+
std::unique_ptr<ROS2CLIWrapper> cli_wrapper_;
63+
std::unique_ptr<OutputParser> output_parser_;
64+
int max_parallel_samples_;
7865
};
7966

8067
} // namespace ros2_medkit_gateway

src/ros2_medkit_gateway/include/ros2_medkit_gateway/discovery_manager.hpp

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,26 +14,25 @@
1414

1515
#pragma once
1616

17+
#include <rclcpp/rclcpp.hpp>
1718
#include <string>
1819
#include <vector>
1920

20-
#include <rclcpp/rclcpp.hpp>
21-
2221
#include "ros2_medkit_gateway/models.hpp"
2322

2423
namespace ros2_medkit_gateway {
2524

2625
class DiscoveryManager {
27-
public:
28-
explicit DiscoveryManager(rclcpp::Node* node);
26+
public:
27+
explicit DiscoveryManager(rclcpp::Node * node);
2928

30-
std::vector<Area> discover_areas();
31-
std::vector<Component> discover_components();
29+
std::vector<Area> discover_areas();
30+
std::vector<Component> discover_components();
3231

33-
private:
34-
std::string extract_area_from_namespace(const std::string& ns);
32+
private:
33+
std::string extract_area_from_namespace(const std::string & ns);
3534

36-
rclcpp::Node* node_;
35+
rclcpp::Node * node_;
3736
};
3837

3938
} // namespace ros2_medkit_gateway

0 commit comments

Comments
 (0)