fix: pre-commit Go lint 按包目录分组执行,修复测试文件 typecheck 失败
将逐文件 lint 改为按包目录去重分组,同包的 _test.go 与被测文件在同一轮 typecheck 中参与分析,避免 undefined 错误。
This commit is contained in:
22
Makefile
22
Makefile
@@ -98,7 +98,9 @@ _hooks-pre-commit:
|
|||||||
printf 'No staged files to check\n'; \
|
printf 'No staged files to check\n'; \
|
||||||
exit 0; \
|
exit 0; \
|
||||||
fi; \
|
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; \
|
[ -n "$$file" ] || continue; \
|
||||||
case "$$file" in scripts/git-hooks/*) continue ;; esac; \
|
case "$$file" in scripts/git-hooks/*) continue ;; esac; \
|
||||||
if git show ":$$file" 2>/dev/null | grep -Eq '^(<<<<<<<|=======|>>>>>>>)'; then \
|
if git show ":$$file" 2>/dev/null | grep -Eq '^(<<<<<<<|=======|>>>>>>>)'; then \
|
||||||
@@ -114,14 +116,12 @@ _hooks-pre-commit:
|
|||||||
fi; \
|
fi; \
|
||||||
case "$$file" in \
|
case "$$file" in \
|
||||||
backend/*.go) \
|
backend/*.go) \
|
||||||
rel=$${file#backend/}; \
|
dir=$$(dirname "$${file#backend/}"); \
|
||||||
printf 'Go lint: backend/%s\n' "$$rel"; \
|
case " $$backend_pkgs " in *" $$dir "*) ;; *) backend_pkgs="$$backend_pkgs $$dir" ;; esac; \
|
||||||
(cd backend && go tool golangci-lint run "$$rel"); \
|
|
||||||
;; \
|
;; \
|
||||||
versionctl/*.go) \
|
versionctl/*.go) \
|
||||||
rel=$${file#versionctl/}; \
|
dir=$$(dirname "$${file#versionctl/}"); \
|
||||||
printf 'Go lint: versionctl/%s\n' "$$rel"; \
|
case " $$versionctl_pkgs " in *" $$dir "*) ;; *) versionctl_pkgs="$$versionctl_pkgs $$dir" ;; esac; \
|
||||||
(cd versionctl && go tool golangci-lint run "$$rel"); \
|
|
||||||
;; \
|
;; \
|
||||||
frontend/*.ts|frontend/*.tsx) \
|
frontend/*.ts|frontend/*.tsx) \
|
||||||
rel=$${file#frontend/}; \
|
rel=$${file#frontend/}; \
|
||||||
@@ -137,6 +137,14 @@ _hooks-pre-commit:
|
|||||||
;; \
|
;; \
|
||||||
esac; \
|
esac; \
|
||||||
done; \
|
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'
|
printf 'Pre-commit checks passed\n'
|
||||||
|
|
||||||
# ============================================
|
# ============================================
|
||||||
|
|||||||
Reference in New Issue
Block a user