lint-staged 未在预提交上运行

漂亮不是在预承诺上运行。这在其他项目中使用相同的配置,所以我很困惑为什么这次它不起作用。

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

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

编辑。以下是相关的开发独立性:

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

答案 1

2021年

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

在安装赫斯基之后,您需要首先卸载赫斯基,因为它可以确保您的钩子正确安装,之后安装最新版本,以便您获得最新的更新。V4husky

断续器

npm uninstall husky

npm install -D husky@4

npm install -D husky

yarn remove husky

yarn add -D husky@4

yarn add -D husky

如果有时上面的技巧不起作用,那么让我们将钩子添加到哈士奇中,下面的提及方法仅用于,我正在展示与示例。V6huskylint-staged

断续器

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

答案 2

我在这里尝试了很多解决方案,但组合终于奏效了!

  1. 确保已安装赫斯基 v4。v6从未触发过我。
  2. 检查 的输出。这不应该返回任何内容。如果它确实运行,git config core.hooksPath
git config --unset core.hookspath

最后它起作用了!