From 4870d296384ceb32ef4bcd5b19bf8d8307c9149a Mon Sep 17 00:00:00 2001 From: lanyuanxiaoyao Date: Tue, 5 May 2026 23:52:43 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20pre-commit=20Go=20lint=20=E6=8C=89?= =?UTF-8?q?=E5=8C=85=E7=9B=AE=E5=BD=95=E5=88=86=E7=BB=84=E6=89=A7=E8=A1=8C?= =?UTF-8?q?=EF=BC=8C=E4=BF=AE=E5=A4=8D=E6=B5=8B=E8=AF=95=E6=96=87=E4=BB=B6?= =?UTF-8?q?=20typecheck=20=E5=A4=B1=E8=B4=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 将逐文件 lint 改为按包目录去重分组,同包的 _test.go 与被测文件在同一轮 typecheck 中参与分析,避免 undefined 错误。 --- Makefile | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index 3ef5fd7..7db8493 100644 --- a/Makefile +++ b/Makefile @@ -98,7 +98,9 @@ _hooks-pre-commit: printf 'No staged files to check\n'; \ exit 0; \ fi; \ - printf '%s\n' "$$staged_files" | while IFS= read -r file; do \ + backend_pkgs=''; \ + versionctl_pkgs=''; \ + for file in $$staged_files; do \ [ -n "$$file" ] || continue; \ case "$$file" in scripts/git-hooks/*) continue ;; esac; \ if git show ":$$file" 2>/dev/null | grep -Eq '^(<<<<<<<|=======|>>>>>>>)'; then \ @@ -114,14 +116,12 @@ _hooks-pre-commit: fi; \ case "$$file" in \ backend/*.go) \ - rel=$${file#backend/}; \ - printf 'Go lint: backend/%s\n' "$$rel"; \ - (cd backend && go tool golangci-lint run "$$rel"); \ + dir=$$(dirname "$${file#backend/}"); \ + case " $$backend_pkgs " in *" $$dir "*) ;; *) backend_pkgs="$$backend_pkgs $$dir" ;; esac; \ ;; \ versionctl/*.go) \ - rel=$${file#versionctl/}; \ - printf 'Go lint: versionctl/%s\n' "$$rel"; \ - (cd versionctl && go tool golangci-lint run "$$rel"); \ + dir=$$(dirname "$${file#versionctl/}"); \ + case " $$versionctl_pkgs " in *" $$dir "*) ;; *) versionctl_pkgs="$$versionctl_pkgs $$dir" ;; esac; \ ;; \ frontend/*.ts|frontend/*.tsx) \ rel=$${file#frontend/}; \ @@ -137,6 +137,14 @@ _hooks-pre-commit: ;; \ esac; \ done; \ + for dir in $$backend_pkgs; do \ + printf 'Go lint: backend/%s\n' "$$dir"; \ + (cd backend && go tool golangci-lint run "$$dir/"); \ + done; \ + for dir in $$versionctl_pkgs; do \ + printf 'Go lint: versionctl/%s\n' "$$dir"; \ + (cd versionctl && go tool golangci-lint run "$$dir/"); \ + done; \ printf 'Pre-commit checks passed\n' # ============================================