• 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
  • 相关阅读:
    园子的现代化建设-复活:沉睡2年多的新闻评论功能重新开放
    记一次 .NET某医疗器械清洗系统 卡死分析
    AI模型训练参数
    Pyhotn: Mac安装selenium没有chromedriver-114以上及chromedriver无法挪到/usr/bin目录下的问题
    C++ vector类模拟实现
    C语言---指针
    【Leetcode】15. 三数之和
    位域的应用(花费时间过长,暂时放弃了,大小端的同步一半也不需要个人去考虑,但是可以作为debug的可能方向)
    vue3.0 axios封装
    『HarmonyOS』Page与AbilitySlice的生命周期
  • 原文地址:https://blog.csdn.net/yt_42370304/article/details/133746339