1. clang-format工具安装
在本地shell环境管理git代码仓库,需要先安装clang-format工具。 安装指令:
apt-get update && apt-get install -y clang-format
安装成功后,执行clang-format --version
可以看到clang-format的版本号。
clang-format version 10.0.0-4ubuntu1
推荐大家安装与这个版本一致的clang-format软件版本。
2. clang-format检查编码风格
2.1 开发本地检查编码风格
规则文件名为.clang-format,在代码仓库的根目录下
如果使用谷歌编码风格,.clang-format文件内容:
# Run manually to reformat a file: # clang-format -i --style=file <file> Language: Cpp BasedOnStyle: Google # 对#include 行的做格式化,但不要求#include按照项目文件、系统文件、其他文件的顺序排序 IncludeCategories: - Regex: '^"(udp_service|idl_wrapper|communication/common/types|dataflow/module/port|dataflow/module_loader/register_module_macro|log|udp_service_parms)"' Priority: 1 - Regex: '^<.*\.h>' Priority: 2 - Regex: