Skip to content

Conversation

@tju-wang
Copy link

-文件.clang-format配置基于Google C++风格指南,并做了适当调整
1.使用4空格缩进
2.行宽限制为100字符
3.采用风格的大括号和空格规则

-编写code_style.m
1.针对不同开发平台(windows/Linux/macOs)
2.举例进行整体项目格式化(建议owner择机进行)
3.举例单文件格式化、格式检查
4.举例如何跳过特定代码段的格式化(待补充指定跳过文件格式化)
5.IDE集成说明

-文件.clang-format配置基于Google C++风格指南,并做了适当调整
1.使用4空格缩进
2.行宽限制为100字符
3.采用风格的大括号和空格规则

-编写code_style.m
1.针对不同开发平台(windows/Linux/macOs)
2.举例进行整体项目格式化(建议owner择机进行)
3.举例单文件格式化、格式检查
4.举例如何跳过特定代码段的格式化(待补充指定跳过文件格式化)
5.IDE集成说明
@tju-wang
Copy link
Author

虾哥,为项目新增clang-format代码格式检查工具,您先帮忙review下初版,同步验证下工具效果。我会继续完善使用案例
@78 Xiaoxia @78

@78
Copy link
Owner

78 commented Mar 13, 2025

这里如何做到,提交PR的代码如果不符合要求,提示调整? 当前项目不符合要求的代码,是否需要先统一调整?

@tju-wang
Copy link
Author

第一个问题我再研究下
第二个问题,我来修改patch,让整体项目主要代码符合clang-format格式

@laride
Copy link
Collaborator

laride commented Nov 18, 2025

这里如何做到,提交PR的代码如果不符合要求,提示调整? 当前项目不符合要求的代码,是否需要先统一调整?

  1. CI 里可以加一步校验。
  2. 初期可以只校验 commit 中有修改的文件,避免因格式化产生一次巨大改动。

.clang-format 格式可以再讨论一下? @78

@tju-wang
Copy link
Author

tju-wang commented Nov 18, 2025 via email

@78
Copy link
Owner

78 commented Nov 19, 2025

这里如何做到,提交PR的代码如果不符合要求,提示调整? 当前项目不符合要求的代码,是否需要先统一调整?

  1. CI 里可以加一步校验。
  2. 初期可以只校验 commit 中有修改的文件,避免因格式化产生一次巨大改动。

.clang-format 格式可以再讨论一下? @78

CI我不会弄,我觉得你可以试试,遇到问题我们再调整

@KingingWang
Copy link

我觉得加上一个format文件是有必要的,至于提交PR的代码如果不符合要求,提示调整,可以使用git提供的hook,检查变更的文件,不通过无法push

Copy link
Collaborator

@laride laride left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

有一些参数可能需要讨论一下

AllowShortFunctionsOnASingleLine: All
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: None
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AlwaysBreakAfterDefinitionReturnType: The function definition return type breaking style to use.

替代选项是 BreakAfterReturnType: ExceptShortType

https://clang.llvm.org/docs/ClangFormatStyleOptions.html#alwaysbreakafterdefinitionreturntype
https://clang.llvm.org/docs/ClangFormatStyleOptions.html#breakafterreturntype

Comment on lines +36 to +38
SplitEmptyFunction: true
SplitEmptyRecord: true
SplitEmptyNamespace: true
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

现有的代码似乎是 SplitEmpty*: false 为主?

ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: true
DerivePointerAlignment: true
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PointerAlignment 同时使用时会覆盖 PointerAlignment 的效果。用 PointerAlignment 强制对齐可能会更好一点?

https://clang.llvm.org/docs/ClangFormatStyleOptions.html#derivepointeralignment

Suggested change
DerivePointerAlignment: true
DerivePointerAlignment: false

Comment on lines +59 to +62
ForEachMacros:
- foreach
- Q_FOREACH
- BOOST_FOREACH
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

xiaozhi 项目中没有 foreach Q_FOREACHBOOST_FOREACH,但是用了 cJSON_ArrayForEach

Suggested change
ForEachMacros:
- foreach
- Q_FOREACH
- BOOST_FOREACH
ForEachMacros:
- cJSON_ArrayForEach

Comment on lines +64 to +72
IncludeCategories:
- Regex: '^<ext/.*\.h>'
Priority: 2
- Regex: '^<.*\.h>'
Priority: 1
- Regex: '^<.*'
Priority: 2
- Regex: '.*'
Priority: 3
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
IncludeCategories:
- Regex: '^<ext/.*\.h>'
Priority: 2
- Regex: '^<.*\.h>'
Priority: 1
- Regex: '^<.*'
Priority: 2
- Regex: '.*'
Priority: 3
IncludeCategories:
- Regex: '^<esp_.*\.h>'
Priority: 1
- Regex: '^<driver/.*\.h>'
Priority: 1
- Regex: '^<.*\.h>'
Priority: 2
- Regex: '^<.*'
Priority: 3
- Regex: '.*'
Priority: 4

这样是否更合适一些

Comment on lines +78 to +79
JavaScriptQuotes: Leave
JavaScriptWrapImports: true
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

现阶段 clang-format 只对 C/C++ 代码启用

Suggested change
JavaScriptQuotes: Leave
JavaScriptWrapImports: true

Comment on lines +85 to +88
ObjCBinPackProtocolList: Never
ObjCBlockIndentWidth: 2
ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: true
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

同上

Suggested change
ObjCBinPackProtocolList: Never
ObjCBlockIndentWidth: 2
ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: true

SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard: Auto
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Standard: Auto
Standard: Latest

By default, ESP-IDF compiles C++ code with C++23 language standard with GNU extensions (-std=gnu++23).

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants