Pre-Commit for Git Hooks 之正确关闭提交代码检测

当提交代码如下报错时: 

$ git commit -m '修复线上bug'
 > running pre-commit hook: npm run precommit
g
> invoive-admin@1.1.1 precommit F:\zhdProgram\3wenlvma\simple-ant-admin
> lint-staged

[STARTED] Preparing...
[SUCCESS] Preparing...
[STARTED] Running tasks...
[STARTED] Running tasks for **/*.{js,jsx,ts,tsx}
[STARTED] Running tasks for **/*.{js,jsx,tsx,ts,less,md,json}
[STARTED] npm run lint-staged:js
[STARTED] prettier --write
[SUCCESS] prettier --write
[SUCCESS] Running tasks for **/*.{js,jsx,tsx,ts,less,md,json}
[FAILED] npm run lint-staged:js [FAILED]
[FAILED] npm run lint-staged:js [FAILED]
[SUCCESS] Running tasks...
[STARTED] Applying modifications...
[SKIPPED] Skipped because of errors from tasks.
[STARTED] Reverting to original state because of errors...
[SUCCESS] Reverting to original state because of errors...
[STARTED] Cleaning up...
[SUCCESS] Cleaning up...

× npm run lint-staged:js:
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! invoive-admin@1.1.1 lint-staged:js: `eslint --ext .js,.jsx,.ts,.tsx  "F:/zhdProgram/3wenlvma/simple-ant-admin/src/pages/components/common-table/columnsConfig.js"`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the invoive-admin@1.1.1 lint-staged:js script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\ThinkPad\AppData\Roaming\npm-cache\_logs\2021-02-06T07_35_48_541Z-debug.log

> invoive-admin@1.1.1 lint-staged:js F:\zhdProgram\3wenlvma\simple-ant-admin
> eslint --ext .js,.jsx,.ts,.tsx  "F:/zhdProgram/3wenlvma/simple-ant-admin/src/pages/components/common-table/columnsConfig.js"


F:\zhdProgram\3wenlvma\simple-ant-admin\src\pages\components\common-table\columnsConfig.js
   35:33  error  'record' is defined but never used  @typescript-eslint/no-unused-vars
   35:41  error  'index' is defined but never used   @typescript-eslint/no-unused-vars
   49:25  error  'record' is defined but never used  @typescript-eslint/no-unused-vars

✖ 3 problems (3 errors, 0 warnings)

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! invoive-admin@1.1.1 precommit: `lint-staged`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the invoive-admin@1.1.1 precommit script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\ThinkPad\AppData\Roaming\npm-cache\_logs\2021-02-06T07_35_49_617Z-debug.log

pre-commit hook failed (add --no-verify to bypass)

解决办法1:

删除项目根目录下的 .git/hooks/pre-commit 文件即可

解决办法2(推荐):

打开根目录下的package.json文件, 搜索是否有precommit包, 执行以下命令删除:

npm uninstall precommit

 

上一篇:Svelte 3:反思响应式编程


下一篇:hooks中,useState异步问题解决方案