1

I want to test my code on the pre-commit hook. To achieve it I installed husky, and list-staged.

Here's the config:

  "scripts": {
    "test": "eslint --ext .ts,.tsx ./**/*",
  },
  "husky": {
    "hooks": {
      "pre-commit": "lint-staged"
    }
  },
  "lint-staged": {
    "*.(ts|tsx)": [
      "npm run test"
    ]

So, in the theory, I can do something like:

git add file.ts
git commit -m commit

And ESLint will automatically check only file.ts. But actually it shows all the exceptions during pre-commit. Even if file.ts is the only file that staged, ESLint checks everything.

What is the problem?

Yoskutik
  • 1,859
  • 2
  • 17
  • 43
  • 1
    What that configuration says is "before the commit is made, if any TS or TSX files have changed, run the test script, which lints (not the usual meaning of 'test') all of the files". If you want to reuse an NPM script, you at least need to add `--` to the end so the extra arguments lint-staged adds go to the script, not NPM itself: https://github.com/okonet/lint-staged#reuse-npm-script – jonrsharpe Jan 03 '21 at 08:20
  • Oh, I got it, thank you. Now I use `"*.(ts|tsx)": ["eslint"]` – Yoskutik Jan 03 '21 at 11:27

0 Answers0