ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

For ROS 1, I think roslint is the best option out there.

I'll just link to the documentation here: https://wiki.ros.org/roslint


There are quite a few linters for ROS 2, but for easy integration they require the use of ament_cmake:

  • https://github.com/ros2/ros2/wiki/Migration-Guide#linters
  • https://github.com/ament/ament_lint

It essentially boils down to depending on certain packages (e.g. ament_lint_common and ament_lint_auto) and then making a cmake macro call to register some new tests for the default linters (i.e. ament_lint_auto_find_test_dependencies()) or manually setting up each linter you want (if you don't want the default list).

Right now (October 2018), the default linters in ROS 2 are:

  • copyright checker
    • checks that each source file has a valid copyright statement and a copy of the license text
  • cppcheck
    • common C++ static analyzer (http://cppcheck.sourceforge.net/)
  • cpplint
    • enforces the Google Style guide (sort of, but we have some small patches) (see: https://github.com/cpplint/cpplint)
  • flake8
    • combination of pep8 style checker and pyflakes
  • a cmake linter
    • does style checks of CMake
  • pep257
    • documentation style checker
  • xmllint
    • xml linter

Each one will try to find the appropriate files to lint and lint them automatically (e.g. cppcheck only checks c++ files and flake8 only looks at python files) as an automated test.

Each one (I think they all do anyways) also has a command line tool, e.g.:

  • ament_uncrustify . will run uncrustify (with our config) over all cpp files under the current directory

Some have automatic reformatting too:

  • again ament_uncrustify . --reformat will also fix the identified violations automatically

Some have a little bit of documentation, but it's limited, e.g.:

  • https://github.com/ament/ament_lint/blob/master/ament_cmake_uncrustify/doc/index.rst

All the core ROS 2 packages run these linters.


There was also a discussion about how to adjust either the ROS 1 or ROS 2 style guides (or both) to make them compatible with one another:

  • https://discourse.ros.org/t/rfc-proposal-to-reconcile-ros-1-and-ros-2-c-style-guides/4616

If we could finish pushing on that it might be possible to eventually use the ROS 2 linters in ROS 1, but as of now that's not possible in any standard way.