lint-staged added path to command

529 views Asked by At

I have the following package.json:

"scripts": {
    "lint": "npm run v2:lint",
    "v2:lint": "cd ./v2 && npm run lint && cd .."
},
"husky": {
    "hooks": {
        "pre-commit": "lint-staged"
    }
},
"lint-staged": {
    "*.{js, json}": "npm run lint"
}

However when I actually did a commit, I can see:

npm ERR! [email protected] lint: `npm run v2:lint "C:/dev/codes/my-app/v2/app/index.js"`

As we can see, the file path is appended to the end but I didn't ask it to do so. Why is lint-staged do this?

1

There are 1 answers

0
MattJ On

Had the same problem, took me a while to realize. The whole idea of lint-staged is that you can use it to run linting or whatever commands you want ONLY ON STAGED FILES. So what it does is appends them to your command. Basically expect your commands to be run like this (example with prettier):

prettier --config .prettierrc --write {list of staged file paths}

So while usually you would add some path to the end like this

prettier --config .prettierrc --write ./src

Simply remove the path at the end and let the lint-staged provide the paths.

"lint-staged": {
  "*.{js}": "prettier --config .prettierrc --write"
}