0
votes

What's the ros way of linting ros code?

For ros1 I have found roslint but it is unclear to me if this is the recommended way to lint ros code and if it is still maintained/supported (last commit from three years ago).

For ros2 I couldn't find any official lint solution.

2

2 Answers

2
votes

Not sure if there is "the ROS way of linting". For your Python/C++ code you can basically use any standard Python/C++ linter.

In addition (when using ROS 1) I can highly recommend catkin_lint, which checks the package definition and notifies about issues like inconsistent dependency declarations or missing install commands (especially the later can save a lot of time when moving from a devel workspace to installing packages on the robot).

1
votes

The ROS2 development guide explains the rules used. Link1 and Link2

There is a linter located in ament_lint to enforce some rules. To run the linter automatically as part of the tests of the package (use BUILD_TEST):

  • depend on ament_lint_auto and ament_lint_common:

Src file example Package.xml

<test_depend>ament_lint_auto</test_depend>
<test_depend>ament_lint_common</test_depend>
  • 2 lines to your CMakeLists: (with BUILD_TEST)

Src file example CMakeList

find_package(ament_lint_auto REQUIRED)
ament_lint_auto_find_test_dependencies()