node.jstypescripthuskylint-staged

Pre-commit hook is not working | Husky and Lintstaged


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?


Solution

  • 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"
        ],
    }