Skip to content

[Feature] 推动clang-format-ignore机制 #10764

Closed

Description

@kurisaW

Describe problem solved by the proposed feature

主线目前最新已经支持并合并了clang-format机制,相比较之前的.ignore_format.yml机制,现在需要统一替换为.clang-format-ignore机制(clang-format原生支持的机制),该功能用于指定clang-format工具应该跳过哪些文件或目录的格式化

Describe your preferred solution

需要完成两件事情:

1.在每个.ignore_format.yml位置,创建一个名为.clang-format-ignore文件,然后将其中的排除规则放到.clang-format-ignore文件中(注意语法规则)

2.将涉及到.ignore_format.yml文件机制的脚本统一修改为.clang-format-ignore机制,最终删除掉所有的.ignore_format.yml

下面是一个.clang-format-ignore文件的示例:

# .clang-format-ignore 文件功能说明:
# 1. 用于指定clang-format工具应该跳过哪些文件或目录的格式化
# 2. 采用类似.gitignore的语法规则
# 3. 支持通配符模式和路径匹配
# 4. 文件位置通常放在项目根目录,clang-format会递归应用这些规则

# =====================
# 核心语法规则示例
# =====================

# 规则1: 精确目录匹配 - 忽略指定目录下的所有内容
/build/

# 规则2: 通配符*匹配 - 忽略所有以".o"结尾的文件
*.o

# 规则3: 递归**匹配 - 忽略任意层级下的node_modules目录
**/node_modules/

# 规则4: 单字符?匹配 - 忽略类似".a", ".b"的单个字符扩展名
*.?

# 规则5: 字符集[]匹配 - 忽略".a"和".b"文件
*.[ab]

# 规则6: 模式组合 - 忽略src下所有子目录中的test文件夹
/src/**/test/

# 规则7: 相对路径模式 - 忽略当前目录下的临时文件
/tmp_*

# 规则8: 注释用法 - 以#开头的行会被视为注释
# 这是一个注释示例

# 规则9: 文件类型排除 - 忽略所有Markdown文档
**/*.md

# 规则10: 构建输出排除 - 忽略常见的构建输出目录
/out*/
/dist/
/target/

# 规则11: 第三方代码排除 - 忽略第三方依赖目录
/third_party/
/vendor/

# 规则12: 隐藏目录排除 - 忽略所有以点开头的目录
/.*/

Describe possible alternatives

No response

Activity

  1. reopened this on Oct 7, 2025
  2. kurisaW commented on Oct 7, 2025

    @kurisaW
    MemberAuthor

    只完成了瑞萨系列,其他部分还需要修改下,可以给新手贡献者来提交下PR

  3. moved this from Done to In Progress in ci/cd action 优化on Oct 10, 2025
  4. added this to the v5.2.2 milestone on Oct 15, 2025
  5. CYFS3 commented on Oct 15, 2025

    @CYFS3
    Contributor

    还未完成的BSP

    • acm32
    • apm32
    • at32
    • bouffalo_lab
    • core-v-mcu
    • cvitek
    • essemi
    • fm33lc026
    • ft32
    • gd32
    • hc32
    • hc32l136
    • hc32l196
    • hk32
    • hpmicro
    • ht32
    • Infineon
    • microchip
    • mm32f103x
    • mm32f327x
    • mm32f526x
    • n32
    • n32g452xx
    • nxp
    • stm32
    • tae32f5300
    • Vango
    • wch
    • yichip
  6. 16 remaining items

  7. linked a pull request that will close this issueformat/rsoc:clang format ignore migration #10828on Oct 20, 2025
  8. linked a pull request that will close this issueformat/rsoc:clang format ignore migration #10829on Oct 20, 2025
  9. removed this from the v5.2.2 milestone on Oct 20, 2025
  10. supperthomas commented on Oct 20, 2025

    @supperthomas
    Member

    这个改了之后,formatting.py 还生效吗?

  11. kurisaW commented on Oct 21, 2025

    @kurisaW
    MemberAuthor

    后面就不用formatting.py了,这个脚本格式化功能比较有限,我拓展过几次,但是很容易引起其他语法错误,所以决定引用clang-format这种比较成熟,支持语法比较完善的格式化工具,现在用户可以通过本地搭建clang-format环境或者提PR上来后,通过CI自动处理格式化(自动追加一条格式化commit)

  12. supperthomas commented on Oct 21, 2025

    @supperthomas
    Member

    后面就不用formatting.py了,这个脚本格式化功能比较有限,我拓展过几次,但是很容易引起其他语法错误,所以决定引用clang-format这种比较成熟,支持语法比较完善的格式化工具,现在用户可以通过本地搭建clang-format环境或者提PR上来后,通过CI自动处理格式化(自动追加一条格式化commit)

    哦哦,好的。

  13. supperthomas commented on Oct 21, 2025

    @supperthomas
    Member

    嗯,用一些比较成熟的通用的技术,bug会少一些。

  14. supperthomas commented on Oct 21, 2025

    @supperthomas
    Member

    搞完之后,建议发些文档说明一下。如何使用

  15. ComerLater commented on Oct 25, 2025

    @ComerLater
    Contributor

    强烈推荐这个哈

  16. ComerLater commented on Oct 25, 2025

    @ComerLater
    Contributor

    需要注意的地方是在tools或者gihtub/actions里面调用了.ignore_format.yml文件,这块也需要一起同步更新

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    actiongithub action yml imporvegood first issueGood for newcomers 新手任务

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions