You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[clang-format] Refine style rules with a thread.c formatting example - #11859
👋 感谢您对 RT-Thread 的贡献!Thank you for your contribution to RT-Thread!
为确保代码符合 RT-Thread 的编码规范,请在你的仓库中执行以下步骤运行代码格式化工作流(如果格式化CI运行失败)。
To ensure your code complies with RT-Thread's coding style, please run the code formatting workflow by following the steps below (If the formatting of CI fails to run).
Use workflow from 保持默认分支(通常为 master)
Keep the default branch (usually master) in Use workflow from
在 branch 输入框填写 PR 分支 style/clang-format-discussion-11653
Enter PR branch style/clang-format-discussion-11653 in the branch field
设置需排除的文件/目录(目录请以"/"结尾)
Set files/directories to exclude (directories should end with "/")
等待工作流完成 | Wait for the workflow to complete
格式化后的代码将作为独立提交推送至你的分支。
The formatting changes will be pushed to your branch as a separate commit.
完成后,提交将自动更新至 style/clang-format-discussion-11653 分支,关联的 Pull Request 也会同步更新。
Once completed, commits will be pushed to the style/clang-format-discussion-11653 branch automatically, and the related Pull Request will be updated.
如有问题欢迎联系我们,再次感谢您的贡献!💐
If you have any questions, feel free to reach out. Thanks again for your contribution!
CYFS3
changed the title
[clang-format] Refine alignment, brace wrapping and spacing rules
[clang-format] Refine style rules with a thread.c formatting example
Oct 9, 2026
The reason will be displayed to describe this comment to others. Learn more.
LGTM
This branch has not been deployed
No deployments
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
拉取/合并请求描述:(PR description)
[
为什么提交这份PR (why to submit this PR)
关联 #11653
当前配置仍关闭连续声明和赋值对齐,并允许短函数、lambda、extern 块和 do-while 保留部分紧凑写法。本 PR 作为讨论用草稿,调整根目录
.clang-format,并以独立提交格式化src/thread.c,展示新配置在核心代码中的实际效果。参考评论:
你的解决方案是什么 (what is your solution)
本次配置修改:
AlignConsecutiveDeclarations.Enabled、AlignConsecutiveDeclarations.AlignFunctionPointers和AlignConsecutiveAssignments.Enabled。声明和赋值不跨空行、独立注释分组对齐。AlignTrailingComments.Kind改为Always,OverEmptyLines改为0,尾部注释只在连续分组内对齐。AllowShortFunctionsOnASingleLine、AllowShortLambdasOnASingleLine改为None,关闭AllowShortLoopsOnASingleLine;开启BraceWrapping.AfterExternBlock、BeforeLambdaBody、BeforeWhile,展开相应语句块。IndentPPDirectives改为BeforeHash,沿用PPIndentWidth: 4,按预处理嵌套层级缩进#。MaxEmptyLinesToKeep从2改为1,连续空行最多保留一行。另外新增一个独立提交,仅使用 clang-format 18.1.8 和本 PR 的根配置格式化
src/thread.c,可单独查看该提交的差异,观察参数/局部变量、赋值、预处理指令和 switch 排版效果。现有InsertBraces: true同时为两处单语句 if 补充大括号,已检查语义不变。该文件通过 clang-format 18.1.8、23.1.3 的--dry-run --Werror和git diff --check检查,未编译整个工程。以下是样例经过 clang-format 后的实际输出节选。
声明和赋值对齐会同时影响函数参数、局部变量、typedef 和函数指针。例如:
预处理指令先采用
BeforeHash,效果如下(头文件保护符由 clang-format 单独识别):do-while的右大括号与while分行:需要继续讨论的部分:
BeforeHash,还是保持#顶格、只缩进指令文字的AfterHash。index ++仍未实现:clang-format 18.1.8 和 23.1.3 实测都会输出index++,没有对应配置项。本 PR 不将此行为视为符合该条规范,需另行确定工具扩展或独立处理方式。指针已经使用
PointerAlignment: Right;宏、位域和表达式已有对齐配置,继续沿用。行宽、include 顺序和行尾策略保持现状。已有第三方目录的DisableFormat和忽略机制继续生效,第三方例外的完整覆盖另行梳理。上游格式检查已经按 PR 改动行运行,编码规范也已有 clang-format 命令行示例;
tools/as.sh等 astyle 遗留入口的清理另行处理。验证:使用 clang-format 18.1.8、23.1.3 对 C/C++/头文件样例执行格式化、重复格式化一致性检查及
--dry-run --Werror,覆盖声明/赋值/注释对齐、空函数、lambda、extern、循环、嵌套预处理指令、指针和连续空行。另验证 lwIP 的DisableFormat仍生效,git diff --check通过。本次未编译整个工程。请提供验证的bsp和config (provide the config and bsp)
]
当前拉取/合并请求的状态 Intent for your PR
必须选择一项 Choose one (Mandatory):
代码质量 Code Quality:
我在这个拉取/合并请求中已经考虑了 As part of this pull request, I've considered the following:
#if 0代码,不包含已经被注释了的代码 All redundant code is removed and cleaned up