Skip to content

Commit 52b90b0

Browse files
authored
Add C++ and CMake pre-commit hooks (#8)
* ci: add C++ and CMake pre-commit hooks with GitHub Actions workflow * chore(lint): fix cpplint and ament_lint warnings in headers * chore(lint): disable cpplint include order check to align with clang-format
1 parent 02ec978 commit 52b90b0

File tree

6 files changed

+79
-11
lines changed

6 files changed

+79
-11
lines changed

.github/workflows/pre-commit.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
name: pre-commit
2+
3+
on:
4+
pull_request:
5+
workflow_dispatch:
6+
jobs:
7+
call_reusable_workflow:
8+
uses: vortexntnu/vortex-ci/.github/workflows/reusable-pre-commit.yml@main
9+
with:
10+
ros_distro: 'humble'
11+
config_path: '.pre-commit-config-local.yaml'

.pre-commit-config-local.yaml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# To install:
2+
#
3+
# pip install pre-commit identify
4+
#
5+
# To use:
6+
#
7+
# pre-commit run --all-files -c .pre-commit-config-local.yaml
8+
#
9+
# Or to install it for automatic checks on commit:
10+
#
11+
# pre-commit install -c .pre-commit-config-local.yaml
12+
#
13+
# To update this file:
14+
#
15+
# pre-commit autoupdate -c .pre-commit-config-local.yaml
16+
#
17+
# See https://pre-commit.com/ for documentation
18+
#
19+
# NOTE: This configuration uses local hooks specific to ROS2 (ament_* linters)
20+
21+
repos:
22+
# C++ hooks
23+
- repo: local
24+
hooks:
25+
- id: ament_cppcheck
26+
name: ament_cppcheck
27+
description: Static code analysis of C/C++ files.
28+
entry: env AMENT_CPPCHECK_ALLOW_SLOW_VERSIONS=1 ament_cppcheck
29+
language: system
30+
files: \.(h\+\+|h|hh|hxx|hpp|cuh|c|cc|cpp|cu|c\+\+|cxx|tpp|txx)$
31+
- repo: local
32+
hooks:
33+
- id: ament_cpplint
34+
name: ament_cpplint
35+
description: Static code analysis of C/C++ files.
36+
entry: ament_cpplint
37+
language: system
38+
files: \.(h\+\+|h|hh|hxx|hpp|cuh|c|cc|cpp|cu|c\+\+|cxx|tpp|txx)$
39+
args: [
40+
"--linelength=100",
41+
"--filter=-whitespace/newline,-legal/copyright,-build/include_order"
42+
]
43+
# CMake hooks
44+
- repo: local
45+
hooks:
46+
- id: ament_lint_cmake
47+
name: ament_lint_cmake
48+
description: Check format of CMakeLists.txt files.
49+
entry: ament_lint_cmake
50+
language: system
51+
files: CMakeLists\.txt$

.pre-commit-config.yaml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# To install:
2+
#
3+
# pip install pre-commit identify
4+
#
15
# To use:
26
#
37
# pre-commit run -a
@@ -15,7 +19,7 @@
1519
repos:
1620
# Standard hooks
1721
- repo: https://github.com/pre-commit/pre-commit-hooks
18-
rev: v5.0.0
22+
rev: v6.0.0
1923
hooks:
2024
- id: check-added-large-files
2125
- id: check-ast
@@ -35,7 +39,7 @@ repos:
3539
- id: requirements-txt-fixer
3640
# Python hooks
3741
- repo: https://github.com/astral-sh/ruff-pre-commit
38-
rev: v0.12.2
42+
rev: v0.14.3
3943
hooks:
4044
- id: ruff-format
4145
- id: ruff

image-filtering/include/image_filters/image_filtering_ros.hpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
1-
#ifndef IMAGE_FILTERING_ROS_HPP
2-
#define IMAGE_FILTERING_ROS_HPP
1+
#ifndef IMAGE_FILTERS__IMAGE_FILTERING_ROS_HPP_
2+
#define IMAGE_FILTERS__IMAGE_FILTERING_ROS_HPP_
33

44
#include <cv_bridge/cv_bridge.h>
55
#include <spdlog/spdlog.h>
6+
#include <memory>
67
#include <rclcpp/parameter_event_handler.hpp>
78
#include <rclcpp/qos.hpp>
89
#include <rclcpp/rclcpp.hpp>
910
#include <sensor_msgs/msg/image.hpp>
11+
#include <string>
1012
#include "image_processing.hpp"
1113

1214
class ImageFilteringNode : public rclcpp::Node {
1315
public:
1416
explicit ImageFilteringNode(const rclcpp::NodeOptions& options);
15-
~ImageFilteringNode() {};
17+
~ImageFilteringNode() {}
1618

1719
private:
1820
/**
@@ -109,4 +111,4 @@ class ImageFilteringNode : public rclcpp::Node {
109111
std::string filter_;
110112
};
111113

112-
#endif // IMAGE_FILTERING_ROS_HPP
114+
#endif // IMAGE_FILTERS__IMAGE_FILTERING_ROS_HPP_

image-filtering/include/image_filters/image_processing.hpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#ifndef IMAGE_PROCESSING_HPP
2-
#define IMAGE_PROCESSING_HPP
1+
#ifndef IMAGE_FILTERS__IMAGE_PROCESSING_HPP_
2+
#define IMAGE_FILTERS__IMAGE_PROCESSING_HPP_
33

44
#include <iostream>
55
#include <map>
@@ -9,6 +9,7 @@
99
#include <opencv2/imgcodecs.hpp>
1010
#include <opencv2/imgproc.hpp>
1111
#include <opencv2/xphoto.hpp>
12+
#include <string>
1213

1314
struct FlipParams {
1415
int flip_code;
@@ -131,7 +132,7 @@ void otsu_segmentation_filter(const FilterParams& params,
131132
const cv::Mat& original,
132133
cv::Mat& output);
133134

134-
const static std::map<std::string, FilterFunction> filter_functions = {
135+
static const std::map<std::string, FilterFunction> filter_functions = {
135136
{"no_filter", no_filter},
136137
{"flip", flip_filter},
137138
{"sharpening", sharpening_filter},
@@ -142,4 +143,4 @@ const static std::map<std::string, FilterFunction> filter_functions = {
142143
{"ebus", ebus_filter},
143144
{"otsu", otsu_segmentation_filter}};
144145

145-
#endif // IMAGE_PROCESSING_HPP
146+
#endif // IMAGE_FILTERS__IMAGE_PROCESSING_HPP_

image-filtering/src/image_filtering_ros.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,6 @@ void ImageFilteringNode::image_callback(
149149
spdlog::error("Received empty image, skipping processing.");
150150
return;
151151
}
152-
153152
} catch (cv_bridge::Exception& e) {
154153
spdlog::error("cv_bridge exception: {}", e.what());
155154
return;

0 commit comments

Comments
 (0)