6

When I execute git commit -m "commit message" command, lint-staged shows this error:

enter image description here

My configuration in package.json:

"husky": {
    "hooks": {
        "pre-commit": "npm run validate && lint-staged"
    }
},
"lint-staged": {
    "*.+(js|ts|tsx)": [
        "eslint"
    ],
    "**/*.+(js|json|ts|tsx)": [
        "prettier --write"
    ]
},

It works fine on mac but windows-10 shows this error. Can anyone tell me what's going wrong with windows?

Arif
  • 6,094
  • 4
  • 49
  • 81

1 Answers1

5

Given the messages that are displayed : I think this hook runs

  1. git stash -k (stash everything that's not in the index)
  2. reformats the staged code, and run git add
  3. git stash pop

On your Windows machine, you happen to be in a configuration where :

  • a. you have some modifications which are not staged
  • b. these modifications conflict with the index when you reformat the index

"fixing" would be :

  • manually run git stash -k
  • create your commit (the pre-commit hook should pass without error)
  • run git stash pop
  • fix the resulting conflicts
LeGEC
  • 46,477
  • 5
  • 57
  • 104
  • Thanks for the info. But I can confirm you there is no conflict in my repository. I have cleaned/reset my full repository, but the error doesn't go away from windows. – Arif Dec 10 '20 at 08:41
  • @Arif: updated the "fixing" paragraph in my answer – LeGEC Dec 10 '20 at 13:31
  • 1
    To debug your issue, you can run the actions manually : what do you get if you run `npm run validate` from your repo's root directory ? and `lint-staged` ? – LeGEC Dec 10 '20 at 13:37
  • As soon as I changed npm to yarn like `npm run validate && lint-staged` to `yarn validate && lint-staged` it start working. – Arif Dec 10 '20 at 14:05
  • 1
    hmmm, so it looks like a javascript issue, and probably versions of packages not exactly the same on both machines. Well, since you fixed it, I guess you won't need to dig deeper into how it works. – LeGEC Dec 10 '20 at 14:18