Use husky to configure git commit specification
1. After we use it npx husky install
, after initialization, a folder 根目录
will appear under the project 2. npx husky add .husky/pre-commit 'npx lint-staged' command is to use lint-staged when git submits Staged formatted code We found that the following content has been automatically generated in the pre-commit file: but the console will report an error when executing git commit twice.husky
PS C:\Users\yunlu\Desktop\yuntuan\yuntuanwebsite> git commit -m "perf: 添加eslint与git commit信息检查"
file:///C:/Users/yunlu/AppData/Local/npm-cache/_npx/8facc973fbdb1091/node_modules/lint-staged/lib/index.js:112
if (runAllError?.ctx?.errors) {
^
SyntaxError: Unexpected token '.'
at Loader.moduleStrategy (internal/modules/esm/translators.js:140:18)
husky - pre-commit hook exited with code 1 (error)
3. So we directly change a command to perform eslint verification, and change the last line of the pre-commit file contentnpm run lint
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"
npm run lint
4. Use git commit -m 'test: eslint check test completed when git commit' test again, check whether the code is formatted according to the configured eslint when submitting, we found that this problem has been solved Oye!
I can't solve the problem of the plug-in, so I solved the plug-in hahahaha