### Describe problem solved by the proposed feature 目前有clang-format,也有as.sh,需要确认下两者风格是否一致?如不一致,需要进行调整,确保一致: https://github.com/RT-Thread/rt-thread/blob/master/.clang-format https://github.com/RT-Thread/rt-thread/blob/master/tools/as.sh ### Describe your preferred solution _No response_ ### Describe possible alternatives _No response_
Activity
Rbb666 commentedon Jun 12, 2025
as.sh)BraceWrapping设置将大括号放在新行(如AfterFunction: true、AfterControlStatement: Always)IndentWidth: 4)--convert-tabs)UseTab: Never)int* ptr)int* ptr,PointerAlignment: Right)--pad-oper)SpaceBeforeAssignmentOperators: true);非赋值运算符由BreakBeforeBinaryOperators: NonAssignment决定if、for等后加空格(--pad-header)SpaceBeforeParens: ControlStatements)--unpad-paren)SpacesInParens: Never)--lineend=linux)LineEnding: DeriveLF)Ryan-CW-Code commentedon Jun 12, 2025
赞,统一代码格式化工具可太有用了,强推clang-format
很多bsp内部也有clang-format配置文件,到时候可以清理一波。
clang-format完善后很有必要对整个仓库遍历格式化一遍
Ryan-CW-Code commentedon Jun 12, 2025
最好是也能引入clang-tidy
a1012112796 commentedon Jun 12, 2025
也可以加上 .editorconfig, 可以用于统一特定文件的缩进方式。
BernardXiong commentedon Jun 14, 2025
请帮忙对这个进行统一吧。未来可以考虑只保留一个,都处于一致的工具、环境下,这样不会产生二义性,谢谢。
dongly commentedon Jun 15, 2025
建议只保留 clang-format
kurisaW commentedon Sep 9, 2025
这里提供了一个AStyle CI,效果是会针对每个PR触发一次评论(仅一次),然后生成一个链接直接跳转到fork仓库的workflow界面,用户只需要设置格式化的分支以及需要排除格式化的文件或路径,就可以实现由Github bot自动加一笔format commit到当前PR下,个人认为AStyle的格式化效果挺不错的,后面可以深度定制:
演示PR:
AStyle workflow效果:
Github bot提交的格式化commit:
Ryan-CW-Code commentedon Sep 10, 2025
AStyle 在现代 IDE 中的支持度相对较弱,像 VS Code 或 CLion 都需要额外安装插件和应用程序才能使用。
clang-format现代IDE都原生支持,与 GitHub Actions、Git hooks、CI/CD 也能深度集成,clang-format的规则参数应该比AStyle多很多,由llvm社区官方维护。
主要感觉RT-Thread 作为国内领先的实时操作系统,应当在工具链和开发流程上积极拥抱现代化技术栈,保持创新能力。
最终目标是统一代码风格,无论选择哪种工具,都是很好的。
kurisaW commentedon Sep 10, 2025
可以的,我再看看clang-format的效果
kurisaW commentedon Sep 11, 2025
clang-format相比较astyle,在规则参数上确实丰富的多,并且最新的clang-format v18版本还支持本地.clang-format-ignore文件的过滤规则,最早我看主线上已经提供了一版.clang-format,并且配套了对应的脚本用于排除构建format_ignore.py,用户需要在指定目录下添加.ignore_format.yml
那么我这边建议是:
下面是一个比较贴合RT-Thread编码风格的.clang-format脚本:
ComerLater commentedon Oct 25, 2025
建议只是保留.ignore_format,目前可选配置也很强大