Ask Your Question
1

ros1 and ros2 linting

asked 2018-10-18 15:26:18 -0500

ezra gravatar image

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.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
4

answered 2018-10-18 18:15:00 -0500

William gravatar image

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:

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
  • 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.:

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:

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.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2018-10-18 15:26:18 -0500

Seen: 220 times

Last updated: Oct 18 '18