S
S
Svyatoslav Khusamov2018-12-24 10:29:30
git
Svyatoslav Khusamov, 2018-12-24 10:29:30

How to force husky to make changes before the commit and not after?

In my package.json file I have the following code:

"husky": {
    "hooks": {
      "pre-commit": "lint-staged"
    }
  },
  "lint-staged": {
    "src/**/*.+(tsx|ts|scss)": [
      "prettier --write",
      "git add ."
    ]
  },

How did I think?
I assumed that before the commit, lint-staged would be run, which in turn would:
1) format the code prettier --write
2) index the git add changes.
It formats fine. But I have to make changes with the second commit.
I end up committing TWICE.
How to make it format and index before commit?
I have already tried all the options https://prettier.io/docs/en/precommit.html
always have to commit twice

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Anton Spirin, 2018-12-24
@rockon404

I have these settings:

{
  "scripts": {
    "precommit": "lint-staged"
  },
  "lint-staged": {
    "src/**/*.{ts,tsx}": [
      "prettier --write",
      "tslint --fix",
      "git add"
    ]
  }
}

M
Mikhail Bugakov, 2019-06-11
@fosemberg

Had the same problem.
Solution: Changed the environment in which git runs and git itself:
was:
environment: cygwin64 ( https://cygwin.com/install.html)
git version: 2.17.0
now:
environment: mingw64 ( https://git- scm.com/download/win)
git version: 2.18.0.windows.1
another configs:
win10x64
node -v 10.14.1
npm -v 6.7.0
"husky": "^2.1.0",
"lint-staged" : "^6.1.1",

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question