-
Notifications
You must be signed in to change notification settings - Fork 4.5k
新增clang-format对代码进行格式管控 #341
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
-文件.clang-format配置基于Google C++风格指南,并做了适当调整 1.使用4空格缩进 2.行宽限制为100字符 3.采用风格的大括号和空格规则 -编写code_style.m 1.针对不同开发平台(windows/Linux/macOs) 2.举例进行整体项目格式化(建议owner择机进行) 3.举例单文件格式化、格式检查 4.举例如何跳过特定代码段的格式化(待补充指定跳过文件格式化) 5.IDE集成说明
|
这里如何做到,提交PR的代码如果不符合要求,提示调整? 当前项目不符合要求的代码,是否需要先统一调整? |
|
第一个问题我再研究下 |
|
|
你好邮件已收到、祝生活愉快!by tju_MrWang
|
CI我不会弄,我觉得你可以试试,遇到问题我们再调整 |
|
我觉得加上一个format文件是有必要的,至于提交PR的代码如果不符合要求,提示调整,可以使用git提供的hook,检查变更的文件,不通过无法push |
laride
left a comment
There was a problem hiding this 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 |
There was a problem hiding this comment.
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
| SplitEmptyFunction: true | ||
| SplitEmptyRecord: true | ||
| SplitEmptyNamespace: true |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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
| DerivePointerAlignment: true | |
| DerivePointerAlignment: false |
| ForEachMacros: | ||
| - foreach | ||
| - Q_FOREACH | ||
| - BOOST_FOREACH |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
xiaozhi 项目中没有 foreach Q_FOREACH 和 BOOST_FOREACH,但是用了 cJSON_ArrayForEach
| ForEachMacros: | |
| - foreach | |
| - Q_FOREACH | |
| - BOOST_FOREACH | |
| ForEachMacros: | |
| - cJSON_ArrayForEach |
| IncludeCategories: | ||
| - Regex: '^<ext/.*\.h>' | ||
| Priority: 2 | ||
| - Regex: '^<.*\.h>' | ||
| Priority: 1 | ||
| - Regex: '^<.*' | ||
| Priority: 2 | ||
| - Regex: '.*' | ||
| Priority: 3 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| 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 |
这样是否更合适一些
| JavaScriptQuotes: Leave | ||
| JavaScriptWrapImports: true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
现阶段 clang-format 只对 C/C++ 代码启用
| JavaScriptQuotes: Leave | |
| JavaScriptWrapImports: true |
| ObjCBinPackProtocolList: Never | ||
| ObjCBlockIndentWidth: 2 | ||
| ObjCSpaceAfterProperty: false | ||
| ObjCSpaceBeforeProtocolList: true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
同上
| ObjCBinPackProtocolList: Never | |
| ObjCBlockIndentWidth: 2 | |
| ObjCSpaceAfterProperty: false | |
| ObjCSpaceBeforeProtocolList: true |
| SpacesInCStyleCastParentheses: false | ||
| SpacesInParentheses: false | ||
| SpacesInSquareBrackets: false | ||
| Standard: Auto |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| Standard: Auto | |
| Standard: Latest |
By default, ESP-IDF compiles C++ code with C++23 language standard with GNU extensions (-std=gnu++23).
-文件.clang-format配置基于Google C++风格指南,并做了适当调整
1.使用4空格缩进
2.行宽限制为100字符
3.采用风格的大括号和空格规则
-编写code_style.m
1.针对不同开发平台(windows/Linux/macOs)
2.举例进行整体项目格式化(建议owner择机进行)
3.举例单文件格式化、格式检查
4.举例如何跳过特定代码段的格式化(待补充指定跳过文件格式化)
5.IDE集成说明