Avi*_*h A 4 git package.json lint-staged git-husky
我创建了一个节点应用程序并安装了 Husky7.0.4 和 lint-staged12.3.5
\n以下是\n.husky/pre-commit --- 文件的配置
\n#!/bin/sh\n. "$(dirname "$0")/_/husky.sh"\n\nnpm run pre-commit\n
Run Code Online (Sandbox Code Playgroud)\n以下是 package.json 配置
\n"scripts": {\n "test": "echo \\"Error: no test specified\\" && exit 1",\n "start": "nodemon --exec babel-node index.js",\n "build": "rimraf dist/ && babel ./ --out-dir dist/ --ignore ./node_modules,./.babelrc,./package.json,./npm-debug.log --copy-files",\n "prettier:check": "prettier --check .",\n "prettier:fix": "prettier --write .",\n "lint:check": "eslint .",\n "lint:fix": "eslint --fix .",\n "pre-commit": "lint-staged",\n "prepare": "husky install"\n },\n "lint-staged": {\n "*.js": [\n "lint:check",\n "lint:fix",\n "prettier:fix"\n ]\n },\n "dependencies": {\n "lint-staged": "^12.3.5",\n },\n "devDependencies": {\n "@babel/cli": "^7.17.6",\n "@babel/core": "^7.17.5",\n "@babel/node": "^7.16.8",\n "@babel/preset-env": "^7.16.11",\n "eslint": "^8.10.0",\n "eslint-config-prettier": "^8.5.0",\n "husky": "^7.0.4",\n "nodemon": "^2.0.15",\n "prettier": "^2.5.1"\n } \n
Run Code Online (Sandbox Code Playgroud)\n但每次提交代码时我都会收到以下错误
\n> node-app@1.0.0 pre-commit\n> lint-staged\n\n\xe2\x9c\x94 Preparing lint-staged...\n\xe2\x9a\xa0 Running tasks for staged files...\n \xe2\x9d\xaf package.json \xe2\x80\x94 1 file\n \xe2\x9d\xaf *.js \xe2\x80\x94 1 file\n \xe2\x9c\x96 lint:check [ENOENT]\n \xe2\x97\xbc lint:fix\n \xe2\x97\xbc prettier:fix\n\xe2\x86\x93 Skipped because of errors from tasks. [SKIPPED]\n\xe2\x9c\x94 Reverting to original state because of errors...\n\xe2\x9c\x94 Cleaning up temporary files...\n\n\xe2\x9c\x96 lint:check failed without output (ENOENT).\nhusky - pre-commit hook exited with code 1 (error) \n
Run Code Online (Sandbox Code Playgroud)\n
我可以通过将 lint-stage 中的任务从
"lint-staged": {
"*.js": [
"lint:check",
"lint:fix",
"prettier:fix"
]
}
Run Code Online (Sandbox Code Playgroud)
到
"lint-staged": {
"*.js": [
"npm run lint:check",
"npm run lint:fix",
"npm run prettier:fix"
]
}
Run Code Online (Sandbox Code Playgroud)