feat: enforce Google-based clang-format style and add style checker#156
Open
chen2021673 wants to merge 1 commit into
Open
feat: enforce Google-based clang-format style and add style checker#156chen2021673 wants to merge 1 commit into
chen2021673 wants to merge 1 commit into
Conversation
Switch .clang-format from LLVM to Google base style with project-specific rules (include regrouping, pointer alignment, brace insertion). Add scripts/style_check.py for additional style enforcement and integrate it into the CI format-check workflow.
kilinchange
requested changes
May 23, 2026
| #include <nccl.h> | ||
| #include <vector> | ||
|
|
||
| #include <nccl.h> |
Collaborator
There was a problem hiding this comment.
c 语言系统库头文件应当放在 c++标准库头文件上一个分组。
Contributor
Author
There was a problem hiding this comment.
NCCL 是第三方通信库,不是 c 语言系统库吧
| @@ -1,3 +1,5 @@ | |||
| #include "infini_train/include/autograd/linear.h" | |||
Collaborator
There was a problem hiding this comment.
这个不是配套头文件,不需要放首行,以及理论上 kernel 层不应当引用 autograd 层头文件。
Contributor
Author
There was a problem hiding this comment.
这里不需要引用这个头文件,删掉了错误引用及添加规则。但目前头文件的匹配检查机制还是根据后缀来的,是clang-format默认行为。
| #include <memory> | ||
| #include <tuple> | ||
|
|
||
| #include <fcntl.h> |
| class _NoColor: | ||
| BLACK = RED = GREEN = YELLOW = BLUE = MAGENTA = CYAN = WHITE = RESET_ALL = "" | ||
|
|
||
| Fore = Style = _NoColor() |
Contributor
Author
There was a problem hiding this comment.
我感觉其他不动,关于头文件顺序检查可以保留。但我看头文件检测也都是简单的按规则匹配,有可能出现错误(文件名相同但并不是对应头文件)或后续需要更新(比如添加third_party)。
| add_executable(test_maca_allocator test/runtime/test_maca_allocator.cc) | ||
| link_infini_train_exe(test_maca_allocator) | ||
| endif() | ||
|
|
Collaborator
|
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
将 .clang-format 基础风格从 LLVM 切换为 Google,并增加项目定制规则(include 分组排序、指针右对齐、强制大括号等)
新增 scripts/style_check.py 自定义风格检查脚本,覆盖 CJK 字符检测、thread_local 命名规范等 clang-format 无法覆盖的规则
CI workflow 增加 style check 步骤,并以 advisory 模式集成 IWYU (include-what-you-use) 检查
对现有 29 个源文件按新规则进行格式化(主要是 include 重新分组排序)