• 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
  • 相关阅读:
    Windows 10 资源管理器使用深色主题
    RabbitMQ
    【第十八篇】- Maven Eclipse
    重邮803计网概述
    虚拟化与Docker
    (六)admin-boot项目之全局处理预防xss攻击
    SpringCloud整合spring security+ oauth2+Redis实现认证授权
    什么是分布式软件系统
    Bank Marketing预测一个客户购买理财产品的成功率
    恒运资本:沪指涨逾1%,金融、地产等板块走强,北向资金净买入超60亿元
  • 原文地址:https://blog.csdn.net/yt_42370304/article/details/133746339