Skip to content

Coding guidelines#

This section describes how to write code for Autoware. The language-specific guidelines describe the formatters, linters, and conventions for each file type. The ROS nodes guidelines describe how to structure a ROS 2 package and node.

Common guidelines#

Autoware follows the ROS 2 developer guide when this section does not define a rule:

Also, keep in mind the following concepts.

Language-specific guidelines#

Language or file typeMain automated checks
C++ClangFormat, cpplint, ros-include-guard, Clang-Tidy, Cppcheck
PythonBlack, isort, flake8 (flake8-ros)
Shell scriptsShellCheck, shfmt
Markdownmarkdownlint, Prettier, CSpell
CMakeament_cmake_lint_cmake, compiler warnings set by autoware_package()
package.xmlsort-package-xml, prettier-package-xml, check-package-depends, ament_cmake_xmllint
Dockerhadolint
GitHub Actionsyamllint, Prettier

Automated checks#

Most of these rules are checked by tools, so you do not have to remember them. Autoware runs the tools in two places.

pre-commit runs the formatters and linters on the files of a pull request. Most Autoware repositories get their .pre-commit-config.yaml through the sync-files workflow, which copies it from autowarefoundation/sync-file-templates. The configuration files of the tools come from the same repository: .clang-format, CPPLINT.cfg, setup.cfg, .markdownlint.yaml, .prettierrc.yaml, and .yamllint.yaml. Do not change a synced file in your repository. Change it in sync-file-templates, and the next sync copies it to all repositories.

pre-commit.ci runs pre-commit on every pull request of a public repository and pushes a style(pre-commit): autofix commit with the fixes. To get the same result before you push, run pre-commit on your computer:

pre-commit run -a

colcon test runs the linters that need a built package. A package that adds ament_lint_auto and autoware_lint_common as test dependencies runs ament_cmake_copyright, ament_cmake_cppcheck, ament_cmake_lint_cmake, and ament_cmake_xmllint. autoware_lint_common does not include cpplint, flake8, or uncrustify, because pre-commit runs those tools faster and with any version.

For the CI workflows that run these checks on a pull request, see CI checks.

Autoware style guide#

For Autoware-specific styles, refer to the following: