From e4e5464be0069617d7afd318d75a95ffc703e7fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9B=A8=E9=9C=96=E9=93=83?= Date: Sat, 30 May 2026 21:31:12 +0800 Subject: [PATCH] =?UTF-8?q?chore(hooks):=20=E4=BC=98=E5=8C=96=20lint-stage?= =?UTF-8?q?d=20=E5=92=8C=20git=20hooks=20=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - lint-staged: 本地开发仅自动修复不阻塞,CI 环境严格检查 - pre-commit: 后台运行 tsc 类型检查,前台运行 lint-staged - pre-push: 新增严格检查闸门(tsc + eslint --max-warnings=0) --- .husky/pre-commit | 6 +++++- .husky/pre-push | 6 ++++++ lint-staged.config.mjs | 10 +++++++++- 3 files changed, 20 insertions(+), 2 deletions(-) create mode 100644 .husky/pre-push diff --git a/.husky/pre-commit b/.husky/pre-commit index d0a7784..5ca943d 100644 --- a/.husky/pre-commit +++ b/.husky/pre-commit @@ -1 +1,5 @@ -npx lint-staged \ No newline at end of file +# 后台运行类型检查,结果输出到 stderr 但不阻塞提交 +npx tsc --noEmit & + +# 前台运行 lint-staged(自动修复 + 格式化) +npx lint-staged diff --git a/.husky/pre-push b/.husky/pre-push new file mode 100644 index 0000000..e703b2b --- /dev/null +++ b/.husky/pre-push @@ -0,0 +1,6 @@ +# pre-push: 严格检查,阻塞有问题的代码推送到远程 +# 类型检查 +npx tsc --noEmit + +# ESLint 严格检查(不允许 warning) +npx eslint . --max-warnings=0 diff --git a/lint-staged.config.mjs b/lint-staged.config.mjs index 12b9d01..b84fec8 100644 --- a/lint-staged.config.mjs +++ b/lint-staged.config.mjs @@ -1,4 +1,12 @@ +/* global process */ + +const isCI = process.env.CI === 'true'; + export default { - '*.{ts,tsx,js,jsx,mjs}': ['eslint --fix --max-warnings=0 --no-warn-ignored', 'prettier --write'], + '*.{ts,tsx,js,jsx,mjs}': [ + 'eslint --fix --no-warn-ignored', + ...(isCI ? ['eslint --max-warnings=0'] : []), + 'prettier --write', + ], '*.{json,css,scss,md}': ['prettier --write'], };