husky を使用して git commit 仕様を構成します
1. 使用後npx husky install
、初期化後、プロジェクトの下にフォルダー根目录
が表示されます2. npx husky add .husky/pre-commit 'npx lint-staged' コマンドは、git の場合に lint-staged を使用することです次のコンテンツが pre-commit ファイルで自動的に生成されていることがわかりました:しかし、コンソールは git commit を 2 回実行するとエラーを報告します.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. eslint 検証を実行するコマンドを直接変更し、コミット前ファイルの内容の最後の行を変更します。npm run lint
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"
npm run lint
4. git commit -m 'test: eslint check test completed when git commit' test を再度使用し、送信時にコードが構成された eslint に従ってフォーマットされているかどうかを確認します。この問題は解決されていることがわかりました。
プラグインの問題が解けないのでプラグインで解決しました笑