提交 eecab463 编写于 作者: C changsh726 提交者: Liu Jiaming

Docs: update how_to_lint_and_format.md

上级 2c025ef3
# How to Lint and Format
## Coding style
- **C/C++ coding style**: Apollo adopted the
[Google C++ Style Guide](https://google.github.io/styleguide/cppguide.html).
## Linters provided in apollo
Apollo uses the following lint tools to check the code style. **Note:** As for
now, ci will only check the style of C++ codes and it may do so in the future
for codes in other languages.
| tool | file type | usage (from Apollo root dir) |
| :--------: | :-----------------------------------: | :---------------------------------------------: |
| cpplint | .h .c .hpp .cpp .hh .cc .hxx .cxx .cu | ./apollo.sh lint cpp <path/to/src/dir/or/files> |
| flake8 | .py | ./apollo.sh lint py <path/to/src/dir/or/files> |
| shellcheck | .sh .bash .bashrc | ./apollo.sh lint sh <path/to/src/dir/or/files> |
To make sure your code conforms to the style guide, you can use command
`bash apollo.sh lint all` to check if your code has any style problems and then
fix them manually. Another option is to use formatters to fix style problems
automatically.
## Formatters provided in apollo
Apollo integrated a set of formatting tools that cover many types of files:
| tool | file type | usage (from Apollo root dir) | configuration file |
| :----------: | :-----------------------------------: | :----------------------------------------------: | :----------------: |
| clang-format | .h .c .hpp .cpp .hh .cc .hxx .cxx .cu | ./apollo.sh format -c <path/to/src/dir/or/files> | .clang-format |
| autopep8 | .py | ./apollo.sh format -p <path/to/src/dir/or/files> | tox.ini |
| buildifier | BUILD .BUILD .bzl .bazel | ./apollo.sh format -b <path/to/src/dir/or/files> | NA |
| shfmt | .sh .bash .bashrc | ./apollo.sh format -s <path/to/src/dir/or/files> | .editorconfig |
| prettier | .md .json .yaml | ./apollo.sh format -m <path/to/src/dir/or/files> | .prettier.json |
For ease of use, you can format all the files with types listed above using
command `./apollo.sh format -a <path/to/src/dir/or/files>`
......@@ -33,7 +33,8 @@ function print_usage() {
${BLUE}-b|--bazel ${NO_COLOR}Format Bazel code
${BLUE}-c|--cpp ${NO_COLOR}Format cpp code
${BLUE}-s|--shell ${NO_COLOR}Format Shell code
${BLUE}-a|--all ${NO_COLOR}Format all (C++/Python/Bazel/Shell)
${BLUE}-m|--markdown ${NO_COLOR}Format Markdown file
${BLUE}-a|--all ${NO_COLOR}Format all
${BLUE}-h|--help ${NO_COLOR}Show this message"
}
......@@ -53,11 +54,16 @@ function run_shfmt() {
bash "${TOP_DIR}/scripts/shfmt.sh" "$@"
}
function run_prettier() {
bash "${TOP_DIR}/scripts/mdfmt.sh" "$@"
}
function run_format_all() {
run_clang_format "$@"
run_buildifier "$@"
run_autopep8 "$@"
run_shfmt "$@"
run_prettier "$@"
}
function main() {
......@@ -81,6 +87,9 @@ function main() {
-s | --shell)
run_shfmt "$@"
;;
-m | --markdown)
run_prettier "$@"
;;
-a | --all)
run_format_all "$@"
;;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册