lint-staged 未在预提交时运行

新手上路,请多包涵

prettier 未在预提交时运行。这在其他项目中使用相同的配置,所以我很困惑为什么这次不工作。

这是我的 package.json 文件的相关部分:

 "scripts": {
    "precommit": "lint-staged"
  },
"lint-staged": {
  "*.{js,json,css,scss,html,md}": [
    "prettier --write",
    "git add"
  ]
},

编辑。以下是相关的 devDependencies:

 "devDependencies": {
  "husky": "^0.14.3",
  "lint-staged": "^7.0.4",
  "prettier": "1.12.0"
},

原文由 Andrew Horn 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 523
2 个回答

重新安装了哈士奇,现在似乎可以正常工作了。感谢@mpasko256 的帮助!

原文由 Andrew Horn 发布,翻译遵循 CC BY-SA 3.0 许可协议

2021年

有时钩子不是由 husky 添加的,所以你需要使用一个简单的 easy hack 添加它。

您需要在安装 V4 之后先卸载 husky,因为它确保您的挂钩已正确安装,然后安装最新版本的 husky 以便您获得最新更新。

NPM

 npm uninstall husky

npm install -D husky@4

npm install -D husky

yarn remove husky

yarn add -D husky@4

yarn add -D husky

如果有时上面的技巧不起作用,那么让我们将钩子添加到 husky 中,下面提到的方法仅用于 V6 我正在展示 huskylint-staged .

NPM

 npm install -D husky

npm set-script prepare "husky install" && npm run prepare

npx husky add .husky/pre-commit "npx lint-staged"

git commit -m "added husky and lint-stagged" // here you will notice the lint-staged checking the files with help of husky

yarn add -D husky

npm set-script prepare "husky install" && yarn prepare

npx husky add .husky/pre-commit "yarn lint-staged"

git commit -m "added husky and lint-stagged" // here you will notice the lint-staged checking the files with help of husky

原文由 Nisharg Shah 发布,翻译遵循 CC BY-SA 4.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题