• ros2 代码风格检查


    ament_uncrustify是一个用于ROS2项目的代码格式化工具,它使用Uncrustify作为底层的格式化工具。

    它的基本用法如下:

    1. 检查代码格式:在你的ROS2项目的根目录下,运行以下命令,可以检查你的代码是否符合预设的代码格式规则:
    ament_uncrustify --config /path/to/your/config/file
    
    • 1

    这个命令会输出不符合规则的代码行和文件。–config选项用于指定格式化规则的配置文件。

    2.自动修复代码格式:如果你想让ament_uncrustify自动修复不符合规则的代码,可以加上–reformat选项:

    ament_uncrustify --config /path/to/your/config/file --reformat
    
    • 1

    这个命令会自动修复不符合规则的代码,并且把修复后的代码写回原来的文件。
    注意:和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)
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
  • 相关阅读:
    基于SqlSugar的开发框架循序渐进介绍(8)-- 在基类函数封装实现用户操作日志记录
    ARM官方推荐的JTAG/SWD接口
    【Python 实战】---- 使用【百度人像分割】实现一键批量抠图
    Spark Join类型和适用的场景
    RabbitMq的最终一致性分布式事务
    Hugging News #0821: 新的里程碑:一百万个代码仓库!
    #【软件STM32cubeIDE下F103配置uart3+uart1+DMA收发+简单数据解析-基础样例-进阶】
    38.sed高级编辑命令
    Linux上部署MySQL5.6 rpm包数据库
    第P4周:猴痘病识别
  • 原文地址:https://blog.csdn.net/yt_42370304/article/details/133746339