已合并
[ci] style: 引入 pre-commit 并应用全代码库格式化 #347
[ci] style: 引入 pre-commit 并应用全代码库格式化 #347
已合并
shilinlee创建于 7月9日
shilinlee
shilinlee成员
7月9日

合入来源

问题/功能描述

引入 pre-commit CI 格式化检查机制,并对全代码库应用自动格式化修正。

修改方案描述

  1. 新增/更新 pre-commit 基础设施:.clang-format.pre-commit-config.yamlscript/ci-pre-commit-pr.sh CI 脚本
  2. 对全代码库执行 pre-commit 自动格式化:clang-format、文件末尾补换行、去除尾随空格等

是否涉及UT/ST

开发自检

likedislike
Pull Request已成功合入, 合并人@zhangjinshi
(感谢 shilinlee 的贡献)
atomgit-bot
atomgit-bot
7月9日 评论:

变更摘要

本 PR 引入 pre-commit CI 格式化检查机制,并对全代码库执行自动格式化修正。核心变更包括:更新 .clang-format.pre-commit-config.yaml 配置,重写 script/ci-pre-commit-pr.sh 从增量检查切换为全量检查模式,以及对 214 个 C++/Python/Shell/YAML 源文件应用 clang-format 格式化、文件末尾补换行、删除尾随空格等纯格式调整,不涉及任何逻辑改动。

主要改动

  • .pre-commit-config.yaml 配置重构:clang-format 钩子改用 --style=file 以引用仓库 .clang-format 配置文件并统一下排除 third_party/3rdparty 目录;ruff-checkpylintbandit 临时设为 stages: [manual] 跳过;移除 typos 检查;codespell 改为非阻塞模式(|| true)并新增排除词 TE

  • .clang-format 新增配置项:添加 SortUsingDeclarations: Never,确保格式化时不对 using 声明进行排序

  • script/ci-pre-commit-pr.sh 全量检查模式:从原先基于 git diff 的增量文件检查重构为 pre-commit run --all-files 全量检查/格式化模式,新增帮助信息、自动安装 pre-commit、结果打印和修复指引等功能

  • 全代码库 clang-format 自动格式化:涉及 src/memcache/csrc/ 下大量 C++ 头文件与源文件的缩进对齐、长参数换行、空格调整、命名空间尾注添加(如 } // namespace mmc)、版权头注释格式化、#endif 尾部注释格式统一等,涵盖 client/common/config/meta_service/proto/net/ 等核心模块

  • Python/Shell/YAML 文件格式修正:Python 文件(example/test/src/memcache/python/)应用 ruff-format 进行参数缩进对齐、多余括号清理、空行规范化;Shell 脚本和 YAML 文件补全文件末尾换行

likedislike
atomgit-bot
atomgit-bot
7月9日 评论:

代码审查

我已对所有 214 个变更文件完成了全面审查。以下是最终结论:


审查总结

按优先级统计的问题数量

  • P0: 0
  • P1: 0
  • P2: 0
  • P3: 1(bandit 安全扫描器暂时禁用)

变更文件审查确认

已逐一审查以下全部 214 个文件,均确认为纯格式化变更、无逻辑修改:

配置文件与 CI(均无逻辑问题)

  • .clang-format — 新增 SortUsingDeclarations: Never 配置项,无问题
  • .gitattributes — 末尾补换行,无问题
  • .gitmodules — 删除末尾空行,无问题
  • .pre-commit-config.yaml — 见上述 P3 报告(bandit 暂时禁用),其余为 hook 配置优化
  • CMakeLists.txt — 末尾补换行,无问题
  • LICENSEREADME.mdVERSION — 末尾补换行 / 去除尾随空格,无问题

文档(均无问题)

  • doc/SECURITYNOTE.mddoc/memcache_c_api.mddoc/memcache_restful_api.md — 去除尾随空格、末尾补换行
  • example/benchmark/README.mdexample/cpp/README.mdexample/examples.md — 末尾补换行、去除尾随空格
  • script/README.mdtest/k8s_deploy/README.md — 末尾补换行

Python 代码(均无逻辑问题,ruff-format 格式化)

  • example/benchmark/mooncake_store.pymutil_process.pyrun_mutil_process.pystart_meta_service.py
  • example/python/interactive_app.pytest_mmc_layers.pytest_mmc_layers_batch.py
  • src/memcache/python/memcache_hybrid/meta_service_leader_election.py
  • src/memcache/python/setup.py
  • test/python/memcache/ha/*.py
  • test/python/memcache/mock_server/*.py

Shell 脚本(均无问题,末尾补换行)

  • script/ci-pre-commit-pr.sh — 完全重写为全量检查模式,逻辑正确
  • script/build_and_pack_run.shscript/performance_compare.shscript/run_fuzz.shscript/run_pkg_maker/uninstall.shscript/run_ut.sh

YAML/JSON(均无问题,末尾补换行)

  • test/k8s_deploy/local-pods-demo.yamlmeta-cluster-ip-demo.yamlmeta-lease-lock-demo.yamlmeta-pods-demo.yaml
  • example/metrics/memcache_dashboard_graph.json

C/C++ 代码(共约 150+ 文件,均无逻辑问题,clang-format 格式化)

变更类型均为:指针/引用对齐 (void*void *, const T&const T &)、函数签名换行重排、命名空间闭合注释格式、宏定义 \ 对齐、{} {} 空格调整、单行 if→多行、末尾补换行、去除尾随空格。无任何语义变更。

整体风险评估

风险:极低。 这是一个纯格式化 PR,引入 pre-commit 基础设施并对全代码库应用自动格式化。唯一的注意点是 bandit 安全扫描器被暂时设为手动触发(stages: [manual]),待存量问题修复后应恢复自动运行。所有代码逻辑均未被修改。

⚠️ 已识别出整体风险,但无法提取行内评论,请参考整体评估。

likedislike
ascend-robot
ascend-robot成员
7月9日 评论:
流水线 PR-pipeline_memcache#1360 [ commitID:9d61a720 ] 已完成
阶段 任务名 状态 详情
编译构建 Build_memcache >>>
恶意代码检查 Antipoison_memcache >>>
编码安全与规范检查 pre-commit >>>
CodeCheck_memcache >>>
开源片段检查 SCA_memcache >>>
开发者测试 UT_memcache >>>
流水线 PR-pipeline_memcache >>>
此流水线已支持下列评论快捷指令,仅PR创建者和白名单成员评论有效
  • compile : 运行流水线
  • retry : 重试流水线所有失败子任务
  • retry <任务名> : 仅重试指定失败子任务
  • stop : 停止流水线
likedislike
Xxiangjie10成员
7月9日 添加了label:pr-audit-failed
xiangjie10成员
7月9日 评论:
🔍 PR 规范审计未通过,以下项目需要修正:
  • PR 未关联里程碑或 Issue
  • PR 新增代码 1446 行超过 1000 行,且标题未标注"反合"

请修正后重新提交,或联系仓库管理员。

likedislike
ascend-robotascend-robot成员
7月9日 添加了label:stat/needs-squash
ascend-robotascend-robot成员
7月9日 添加了label:ci-pipeline-running
ascend-robotascend-robot成员
7月9日 添加了label:ascend-cla/yes
ascend-robot
ascend-robot成员
7月9日 评论:

CLA Signature Pass

shilinlee_com, thanks for your pull request. All authors of the commits have signed the CLA. 👍

likedislike
ascend-robot
ascend-robot成员
7月9日 评论:

Thanks for your pull-request.
The full list of commands accepted by me can be found at here
You can get sig-info at here


PR Approval Progress

⚠️ This PR does not yet meet the following requirements:lgtm (requires ≥ 3 person(s) per module)、approve (requires ≥ 1 person(s) per module)

Module Approval Details

module lgtm status approve status
repo-Ascend/memcache ❌ (0/3)(You can also ask: shepherd-cheung, waglog, getee0506, 邓洪, 陈元明) ❌ (0/1)(You can also ask: 李睿, weihaoran1, yangpeng197, yrewzjsx, 陈元明)

💡 Tip:

  • Committer can comment /approve or /lgtm
  • Commenting /approve implies both code review (lgtm) and intent to merge (approve)

CLA Signature Pass

shilinlee_com, thanks for your pull request. All authors of the commits have signed the CLA. 👍

likedislike
shilinleeshilinlee成员
7月9日 关联了issue:[Usage]: 使能pre-commit,统一代码风格
shilinlee
shilinlee成员
7月9日 评论:

retry UT_memcache

likedislike
shilinlee
shilinlee成员
7月9日 评论:

retry CodeCheck_memcache

likedislike
ascend-robotascend-robot成员
7月9日 删除了label:ci-pipeline-running
ascend-robotascend-robot成员
7月9日 添加了label:ci-pipeline-failed
shilinlee
shilinlee成员
7月9日 评论:

retry

likedislike
ascend-robotascend-robot成员
7月9日 删除了label:ci-pipeline-failed
此处折叠了17条事件消息 查看更多
songxiaoyusongxiaoyu成员
7月9日 将nbbb24设为评审人
shilinlee
shilinlee成员
7月9日 评论:

retry

likedislike
ascend-robot
ascend-robot成员
7月9日 评论:

重试流水线失败:PR-pipeline_memcache 仅失败状态流水线支持重试操作。

likedislike
shilinlee
shilinlee成员
7月9日 评论:

compile

likedislike
ascend-robotascend-robot成员
7月9日 删除了label:ci-pipeline-passed
此处折叠了6条事件消息 查看更多
ascend-robotascend-robot成员
7月9日 添加了label:ci-pipeline-passed