ament_uncrustify是一个用于ROS2项目的代码格式化工具,它使用Uncrustify作为底层的格式化工具。
它的基本用法如下:
ament_uncrustify --config /path/to/your/config/file
这个命令会输出不符合规则的代码行和文件。–config选项用于指定格式化规则的配置文件。
2.自动修复代码格式:如果你想让ament_uncrustify自动修复不符合规则的代码,可以加上–reformat选项:
ament_uncrustify --config /path/to/your/config/file --reformat
这个命令会自动修复不符合规则的代码,并且把修复后的代码写回原来的文件。
注意:和Uncrustify一样,ament_uncrustify也会直接修改源代码文件,所以在使用之前最好备份你的代码。
3.ament_uncrustify 命令详情
ament_uncrustify -help
usage: ament_uncrustify [-h] [-c CFG] [--linelength N] [--exclude [EXCLUDE [EXCLUDE ...]]] [--language {C,C++,CPP}] [--reformat] [--xunit-file XUNIT_FILE] [paths [paths ...]]
ament_uncrustify: error: argument -h/--help: ignored explicit argument 'elp'
yong@docker_yong-thinkstation-p520:/zdrive$ ament_uncrustify --help
usage: ament_uncrustify [-h] [-c CFG] [--linelength N] [--exclude [EXCLUDE [EXCLUDE ...]]] [--language {C,C++,CPP}] [--reformat] [--xunit-file XUNIT_FILE] [paths [paths ...]]
Check code style using uncrustify.
positional arguments:
paths The files or directories to check. For directories files ending in '.c', '.cc', '.cpp', '.cxx', '.h', '.hh', '.hpp', '.hxx' will be considered. (default: ['.'])
optional arguments:
-h, --help show this help message and exit
-c CFG The config file (default: /opt/ros2/x86_64/lib/python3.8/site-packages/ament_uncrustify/configuration/ament_code_style.cfg)
--linelength N The maximum line length (default: specified in the config file) (default: None)
--exclude [EXCLUDE [EXCLUDE ...]]
Exclude specific file names and directory names from the check (default: [])
--language {C,C++,CPP}
Passed to uncrustify as '-l ' to force a specific language rather then choosing one based on file extension (default: None)
--reformat Reformat the files in place (default: False)
--xunit-file XUNIT_FILE
Generate a xunit compliant XML file (default: None)