Skip to content

Commit a86a8c2

Browse files
destoglbmagyar
andauthored
Add initial pre-commit setup. (ros-controls#220)
* Add initial pre-commit setup. * ignore changelog files for codespell * Basic whitespace and typo fixes * Basic whitespace and typo fixes * fix docs Co-authored-by: Bence Magyar <[email protected]>
1 parent 856e8e2 commit a86a8c2

28 files changed

+192
-45
lines changed

.github/workflows/format.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# This is a format job. Pre-commit has a first-party GitHub action, so we use
2+
# that: https://github.com/pre-commit/action
3+
4+
name: Format
5+
6+
on:
7+
workflow_dispatch:
8+
pull_request:
9+
push:
10+
branches:
11+
- master
12+
13+
jobs:
14+
pre-commit:
15+
name: Format
16+
runs-on: ubuntu-latest
17+
steps:
18+
- uses: actions/checkout@v2
19+
- uses: actions/setup-python@v2
20+
- name: Install clang-format-10
21+
run: sudo apt-get install clang-format-10 cppcheck
22+
- uses: pre-commit/[email protected]
23+
with:
24+
extra_args: --all-files --hook-stage manual

.github/workflows/prerelease.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,3 @@ jobs:
2424
- uses: actions/checkout@v2
2525
- name: industrial_ci
2626
uses: ros-industrial/industrial_ci@master
27-

.pre-commit-config.yaml

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
2+
# To use:
3+
#
4+
# pre-commit run -a
5+
#
6+
# Or:
7+
#
8+
# pre-commit install # (runs every time you commit in git)
9+
#
10+
# To update this file:
11+
#
12+
# pre-commit autoupdate
13+
#
14+
# See https://github.com/pre-commit/pre-commit
15+
16+
repos:
17+
# Standard hooks
18+
- repo: https://github.com/pre-commit/pre-commit-hooks
19+
rev: v3.4.0
20+
hooks:
21+
- id: check-added-large-files
22+
- id: check-ast
23+
- id: check-case-conflict
24+
- id: check-docstring-first
25+
- id: check-merge-conflict
26+
- id: check-symlinks
27+
- id: check-xml
28+
- id: check-yaml
29+
- id: debug-statements
30+
- id: end-of-file-fixer
31+
- id: mixed-line-ending
32+
- id: trailing-whitespace
33+
- id: fix-byte-order-marker
34+
35+
# Python hooks
36+
- repo: https://github.com/asottile/pyupgrade
37+
rev: v2.12.0
38+
hooks:
39+
- id: pyupgrade
40+
args: [--py36-plus]
41+
42+
# PEP 257
43+
- repo: https://github.com/FalconSocial/pre-commit-mirrors-pep257
44+
rev: v0.3.3
45+
hooks:
46+
- id: pep257
47+
args: ["--ignore=D100,D101,D102,D103,D104,D105,D106,D107,D203,D212,D404"]
48+
49+
- repo: https://github.com/pycqa/flake8
50+
rev: 3.9.0
51+
hooks:
52+
- id: flake8
53+
args: ["--ignore=E501"]
54+
55+
# CPP hooks
56+
- repo: local
57+
hooks:
58+
- id: ament_uncrustify
59+
name: ament_uncrustify
60+
description: Static code analysis of C/C++ files.
61+
stages: [commit]
62+
entry: ament_cppcheck
63+
language: system
64+
files: \.(h\+\+|h|hh|hxx|hpp|cuh|c|cc|cpp|cu|c\+\+|cxx|tpp|txx)$
65+
66+
- repo: local
67+
hooks:
68+
- id: ament_cppcheck
69+
name: ament_cppcheck
70+
description: Static code analysis of C/C++ files.
71+
stages: [commit]
72+
entry: ament_cppcheck
73+
language: system
74+
files: \.(h\+\+|h|hh|hxx|hpp|cuh|c|cc|cpp|cu|c\+\+|cxx|tpp|txx)$
75+
76+
# Maybe use https://github.com/cpplint/cpplint instead
77+
- repo: local
78+
hooks:
79+
- id: ament_cpplint
80+
name: ament_cpplint
81+
description: Static code analysis of C/C++ files.
82+
stages: [commit]
83+
entry: ament_cpplint
84+
language: system
85+
files: \.(h\+\+|h|hh|hxx|hpp|cuh|c|cc|cpp|cu|c\+\+|cxx|tpp|txx)$
86+
args: ["--linelength=100", "--filter=-whitespace/newline"]
87+
88+
# Cmake hooks
89+
- repo: local
90+
hooks:
91+
- id: ament_lint_cmake
92+
name: ament_lint_cmake
93+
description: Check format of CMakeLists.txt files.
94+
stages: [commit]
95+
entry: ament_lint_cmake
96+
language: system
97+
files: CMakeLists\.txt$
98+
99+
# Copyright
100+
- repo: local
101+
hooks:
102+
- id: ament_copyright
103+
name: ament_copyright
104+
description: Check if copyright notice is available in all files.
105+
stages: [commit]
106+
entry: ament_copyright
107+
language: system
108+
109+
# Docs - RestructuredText hooks
110+
- repo: https://github.com/PyCQA/doc8
111+
rev: 0.9.0a1
112+
hooks:
113+
- id: doc8
114+
args: ['--max-line-length=100', '--ignore=D001']
115+
exclude: CHANGELOG\.rst$
116+
117+
- repo: https://github.com/pre-commit/pygrep-hooks
118+
rev: v1.8.0
119+
hooks:
120+
- id: rst-backticks
121+
exclude: CHANGELOG\.rst$
122+
- id: rst-directive-colons
123+
- id: rst-inline-touching-normal
124+
125+
# Spellcheck in comments and docs
126+
# skipping of *.svg files is not working...
127+
- repo: https://github.com/codespell-project/codespell
128+
rev: v2.0.0
129+
hooks:
130+
- id: codespell
131+
args: ['--write-changes']
132+
exclude: CHANGELOG\.rst|\.(svg|pyc)$

README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,21 @@ Have a look at here: https://github.com/ros-controls/ros2_control
88

99
## Acknowledgements
1010

11-
<!--
11+
<!--
1212
ROSIN acknowledgement from the ROSIN press kit
1313
@ https://github.com/rosin-project/press_kit
1414
-->
1515

1616
<a href="http://rosin-project.eu">
17-
<img src="http://rosin-project.eu/wp-content/uploads/rosin_ack_logo_wide.png"
17+
<img src="http://rosin-project.eu/wp-content/uploads/rosin_ack_logo_wide.png"
1818
alt="rosin_logo" height="60" >
1919
</a>
2020

21-
Supported by ROSIN - ROS-Industrial Quality-Assured Robot Software Components.
21+
Supported by ROSIN - ROS-Industrial Quality-Assured Robot Software Components.
2222
More information: <a href="http://rosin-project.eu">rosin-project.eu</a>
2323

24-
<img src="http://rosin-project.eu/wp-content/uploads/rosin_eu_flag.jpg"
25-
alt="eu_flag" height="45" align="left" >
24+
<img src="http://rosin-project.eu/wp-content/uploads/rosin_eu_flag.jpg"
25+
alt="eu_flag" height="45" align="left" >
2626

27-
This project has received funding from the European Union’s Horizon 2020
28-
research and innovation programme under grant agreement no. 732287.
27+
This project has received funding from the European Union’s Horizon 2020
28+
research and innovation programme under grant agreement no. 732287.

diff_drive_controller/src/diff_drive_controller.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,7 @@ CallbackReturn DiffDriveController::on_activate(const rclcpp_lifecycle::State &)
498498
if (registered_left_wheel_handles_.empty() || registered_right_wheel_handles_.empty()) {
499499
RCLCPP_ERROR(
500500
node_->get_logger(),
501-
"Either left wheel interfaces, right wheel interfaces are non existant");
501+
"Either left wheel interfaces, right wheel interfaces are non existent");
502502
return CallbackReturn::ERROR;
503503
}
504504

doc/writing_new_controller.rst

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ The following is a step-by-step guide to create source files, basic tests, and c
1111
If the package for the controller does not exist, then create it first.
1212
The package should have ``ament_cmake`` as a build type.
1313
The easiest way is to search online for the most recent manual.
14-
A helpful command to support this process is `ros2 pkg create`.
14+
A helpful command to support this process is ``ros2 pkg create``.
1515
Use the ``--help`` flag for more information on how to use it.
1616
There is also an option to create library source files and compile rules to help you in the following steps.
1717

@@ -33,10 +33,10 @@ The following is a step-by-step guide to create source files, basic tests, and c
3333

3434
4. Define the class of the controller, extending ``ControllerInterface``, e.g.,
3535
.. code:: c++
36-
class ControllerName : public controller_interface::ControllerInterface
36+
class ControllerName : public controller_interface::ControllerInterface
3737

3838
5. Add a constructor without parameters and the following public methods overriding the ``ControllerInterface`` definition: ``init``, ``command_interface_configuration``, ``state_interface_configuration``, ``on_configure``, ``on_activate``, ``on_deactivate``, ``update``.
39-
For exact definitions check the ``controller_interface/controller_interface.hpp`` header or one of the controllers from `ros2_controllers <https://github.com/ros-controls/ros2_controllers> `_.
39+
For exact definitions check the ``controller_interface/controller_interface.hpp`` header or one of the controllers from `ros2_controllers <https://github.com/ros-controls/ros2_controllers>`_.
4040

4141
6. (optional) Often, controllers accept lists of joint names and interface names as parameters.
4242
If so, you can add two protected string vectors to store those values.
@@ -76,7 +76,7 @@ The following is a step-by-step guide to create source files, basic tests, and c
7676
5. **Writing export definition for pluginlib**
7777

7878
1. Create the ``<controller_name>.xml`` file in the package and add a definition of the library and controller's class which has to be visible for the pluginlib.
79-
The easiest way to do that is to check other controllers in the `ros2_controllers <https://github.com/ros-controls/ros2_controllers> `_ package.
79+
The easiest way to do that is to check other controllers in the `ros2_controllers <https://github.com/ros-controls/ros2_controllers>`_ package.
8080

8181
2. Usually, the plugin name is defined by the package (namespace) and the class name, e.g.,
8282
``<controller_name_package>/<ControllerName>``.
@@ -85,9 +85,9 @@ The following is a step-by-step guide to create source files, basic tests, and c
8585

8686
6. **Writing simple test to check if the controller can be found and loaded**
8787

88-
1. Create the folder ``test`` in your package, if it does not exist already, and add a file named ``test_load_<controller_name>.cpp>.
88+
1. Create the folder ``test`` in your package, if it does not exist already, and add a file named ``test_load_<controller_name>.cpp``.
8989

90-
2. You can safely copy the file's content for any controller defined in the `ros2_controllers <https://github.com/ros-controls/ros2_controllers> `_ package.
90+
2. You can safely copy the file's content for any controller defined in the `ros2_controllers <https://github.com/ros-controls/ros2_controllers>`_ package.
9191

9292
3. Change the name of the copied test and in the last line, where controller type is specified put the name defined in ``<controller_name>.xml`` file, e.g., ``<controller_name_package>/<ControllerName>``.
9393

@@ -112,7 +112,7 @@ The following is a step-by-step guide to create source files, basic tests, and c
112112
7. In the test section add the following dependencies: ``ament_cmake_gmock``, ``controller_manager``, ``hardware_interface``, ``ros2_control_test_assets``.
113113

114114
8. Add compile definitions for the tests using the ``ament_add_gmock`` directive.
115-
For details, see how it is done for controllers in the `ros2_controllers <https://github.com/ros-controls/ros2_controllers> `_ package.
115+
For details, see how it is done for controllers in the `ros2_controllers <https://github.com/ros-controls/ros2_controllers>`_ package.
116116

117117
9. (optional) Add your controller`s library into ``ament_export_libraries`` before ``ament_package()``.
118118

effort_controllers/CHANGELOG.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,3 @@ Changelog for package effort_controllers
4343

4444
0.1.0 (2020-12-23)
4545
------------------
46-

effort_controllers/test/test_joint_group_effort_controller.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ TEST_F(JointGroupEffortControllerTest, WrongCommandCheckTest)
151151
controller_->get_node()->set_parameter({"joints", joint_names_});
152152
ASSERT_EQ(controller_->on_configure(rclcpp_lifecycle::State()), CallbackReturn::SUCCESS);
153153

154-
// send command with wrong numnber of joints
154+
// send command with wrong number of joints
155155
auto command_ptr =
156156
std::make_shared<forward_command_controller::CmdType>();
157157
command_ptr->data = {10.0, 20.0};

effort_controllers/test/test_joint_group_effort_controller.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828
using hardware_interface::HW_IF_EFFORT;
2929
using hardware_interface::CommandInterface;
30-
// subclassing and friending so we can access member varibles
30+
// subclassing and friending so we can access member variables
3131
class FriendJointGroupEffortController : public effort_controllers::JointGroupEffortController
3232
{
3333
FRIEND_TEST(JointGroupEffortControllerTest, CommandSuccessTest);

force_torque_sensor_broadcaster/test/test_force_torque_sensor_broadcaster.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
#include "force_torque_sensor_broadcaster/force_torque_sensor_broadcaster.hpp"
2828

29-
// subclassing and friending so we can access member varibles
29+
// subclassing and friending so we can access member variables
3030
class FriendForceTorqueSensorBroadcaster : public force_torque_sensor_broadcaster::
3131
ForceTorqueSensorBroadcaster
3232
{

0 commit comments

Comments
 (0)