improve[clang-format]: optimize the formatting logic for RT-Thread coding standard#10736
improve[clang-format]: optimize the formatting logic for RT-Thread coding standard#10736Rbb666 merged 1 commit intoRT-Thread:masterfrom
Conversation
|
👋 感谢您对 RT-Thread 的贡献!Thank you for your contribution to RT-Thread! 为确保代码符合 RT-Thread 的编码规范,请在你的仓库中执行以下步骤运行代码格式化工作流。 🛠 操作步骤 | Steps
完成后,提交将自动更新至 如有问题欢迎联系我们,再次感谢您的贡献!💐 |
|
这个 PR 修改了 1. AlignArrayOfStructures: Right → None原来: struct {
int a;
float b;
} arr[2];数组元素的字段会“右对齐”。 现在: struct {
int a;
float b;
} arr[2];字段不再对齐,直接按原始书写方式排列。 2. AlignConsecutiveAssignments/Declarations: Enabled: true → false原来: int a = 1;
float b = 2.0;
char c = 'x';连续赋值、声明会被对齐等号或类型。 现在: int a = 1;
float b = 2.0;
char c = 'x';不再自动对齐,保持原始间距。 3. AlignTrailingComments: Kind: Always → Leave原来: int a = 1; // comment
int b = 2; // another comment所有同行注释会被对齐。 现在: int a = 1; // comment
int b = 2; // another comment注释不会强制对齐,留在原位。 4. AllowShortFunctionsOnASingleLine: None → Inline原来: int foo()
{
return 1;
}即使很短,也不会一行写。 现在: int foo() { return 1; }短函数允许写在一行,更简洁。 5. BraceWrapping: AfterCaseLabel: false → true原来: switch (x) {
case 1:
doSomething();
}
现在: switch (x) {
case 1:
{
doSomething();
}
}
6. NamespaceIndentation: None → All原来: namespace foo {
int a;
}namespace 内部没有缩进。 现在: namespace foo {
int a;
}namespace 内部内容会缩进,提高可读性。 这些改动主要影响代码对齐、注释、缩进和短结构的写法,让格式更紧凑或更规范,具体效果可在实际格式化后直观体现。 |
|
@kurisaW 这个确认下修改后是否会这样,不建议格式化成同行显示,会降低可阅读性
|
|
补充格式化说明(以下测试情况都是根据最新修改format脚本进行): 1. AlignArrayOfStructures: Right → None格式化前: struct {
int a;
float b;
} arr[2];格式化后: struct
{
int a;
float b;
} arr[2];2. AlignConsecutiveAssignments/Declarations: Enabled: true → false格式化前: int a = 1;
float b = 2.0;
char c = 'x';现在: int a = 1;
float b = 2.0;
char c = 'x';ps:这里不建议根据运算符对齐,否则如果遇到命名很长的声明,其他底下的名字会看起来很突兀 3. AlignTrailingComments: Kind: Always → Leave格式化前: int a = 1; // comment
int b = 2; // another comment格式化后: int a = 1; // comment
int b = 2; // another comment注释不会强制对齐,留在原位。 4. AllowShortFunctionsOnASingleLine: None → Inline格式化前: int foo() { return 1; }即使很短,也不会一行写。 格式化后: int foo()
{
return 1;
}5. BraceWrapping: AfterCaseLabel: false → true格式化前: switch (x) {
case 1:
doSomething();
}格式化后: switch (x)
{
case 1:
doSomething();
}6. NamespaceIndentation: None → All格式化前: namespace foo {
int a;
}namespace 内部没有缩进。 现在: namespace foo
{
int a;
} |

拉取/合并请求描述:(PR description)
[
优化clang-format规则,使其更加满足RT-Thread编码规范
主要修改内容:
AlignConsecutiveAssignments、AlignConsecutiveDeclarations设为false),数组结构对齐改为None。Leave),case标签后换行(AfterCaseLabel: true)。Inline),命名空间内容全部缩进(All)。]