5

I'm running lint-staged (v11.0.0) as part of my pre-commit hook through Husky (v4.3.8). My lint-staged performs eslint (v7.27.0) and Prettier (v2.3.0). However, after Prettier runs, the "prettified" files aren't added to the commit.

How can files modified by Prettier as part of the lint-staged process be automatically added to the commit?

  "husky": {
    "hooks": {
      "pre-commit": "lint-staged"
    }
  },
  "lint-staged": {
    "{src,test}/**/*.ts": {
      "eslint ./src --ext .ts",
      "prettier ./src --write"
    }
  }
Luke
  • 20,878
  • 35
  • 119
  • 178
  • I had a similar problem with eslint in a pre-commit hook. I added `&& add .` to the hook and it worked fine, the downside to this obviously is that it'll add everything, which you might not want. – Caedmon Jul 20 '21 at 09:55
  • 1
    From the `v10` of lint-staged, the `git add` should not be required but it doesn't work. `From v10.0.0 onwards any new modifications to originally staged files will be automatically added to the commit. If your task previously contained a git add step, please remove this. The automatic behaviour ensures there are less race-conditions, since trying to run multiple git operations at the same time usually results in an error.` https://github.com/okonet/lint-staged#v10 – Luke Jul 29 '21 at 21:48

0 Answers0