Pre-commit hook is not working | Husky and Lintstaged

5.3k Views Asked by At

I'm trying to use typescript pre-commit Husky hooks with LintStaged, but when I do a commit, the pre-commit script is not running, I just receive the common git response after commits. git commit response

.huskyrc.json

{
"hooks": {
    "pre-commit": "lint-staged"
}

}

.lintstagedrc.json

{
"*.ts": [
    "eslint 'src/**' --fix",
    "npm run test:staged"
]

}

My file structure

File structure picture

What am I doing wrong?

1

There are 1 best solutions below

2
On BEST ANSWER

The another way of doing it is adding the scripts to the package.json file.

// package.json

"husky": {
    "hooks": {
      "pre-commit": "lint-staged"
    }
},
"lint-staged": {
    "*.ts": [
      "eslint 'src/**' --fix",
      "npm run test:staged"
    ],
}