Coding Convention

:blue_book: The official home page for mobile-aware SWAM

https://mobile-swam.github.io

The official home page for mobile-aware SWAM

SWAM, the SWAM mascot

Coding Convention

SWAM project follows Google Style Guide for coding convention. A few rules might be ignored depending on modules. For the full list of ignored rules, please see the following link:

C/C++

When you push your commits, ALWAYS run clang-format & cpplint to submit a commit with style change. If there is a change due to code style issues, make two separate commits: (Please do not include other codes’ style change in the same commit)

clang-format

clang-format automatically formats your code. Please, refer to the options of Clang format style for more details.

  1. Install the latest clang-format (>= 3.8)
    $ sudo apt-cache search clang-format
    $ sudo apt-get install -y clang-format-XX.XX
    
  2. Copy clang-format file from AuDri/ROS/catkin/style/.clang-format to your caktin workspace (catkin_ws), or copy .clang-format to root path of source codes.
  3. Run clang-format with –style=File option:
    $ clang-format-XX.XX -i --style=File [my_source_code_file]
    or 
    $ find . -name '*.h' -or -name '*.hpp' -or -name '*.cpp' | xargs clang-format-XX.XX -i -style=file $1
    

cpplint

cpplint is a static C++ style checker following Google’s C++ style guide. cpplint for ROS modules is available at AuDri/ROS/catkin/style/cpplint.py.

  1. Directly run it with:
    $ python cpplint.py [file_path]
    or
    $ find . -name '*.h' -or -name '*.hpp' -or -name '*.cpp' | xargs python cpplint.py $1
    

Python

Formatter yapf

We use yapf as a formatter for python files. It changes the python files according to the defined style in ~/.config/yapf/style file. We use pep 8. We use style config as below. You can use yapf with PIP.

$ sudo pip install --proxy=http://192.168.1.184:8080 yapf
$ vi ~/.config/yapf/style
[style]
based\_on\_style = pep8
indent\_width = 4
split\_before\_logical\_operator = true
$ yapf -i *.py

Checker pylint

Pylint is a source code, bug and quality checker for the Python programming language. It follows the style recommended by PEP 8, the Python style guide. To check a python file with pylint:

$ sudo pip install --proxy=http://192.168.1.184:8080 pylint
$ cd ros_prj
$ cp ROS/catkin/style/.pylintrc ~/
$ pylint your_file.py
Then, modify incorrect statements that are checked by pylint before submitting your PR.