-1

I'm trying to run the yarn prettier command at each pre-commit.

I found out that I should use Husky in order to create a git hook.

And it works but since I'm a monorepo it pushed my working directory and erased the parent.

Here are the steps that I took:

  1. since the .git directory is at the root of the project, I've created a symlink in my working directory (and I think the issue is here)

  2. yarn add -D husky lint-staged

  3. npx husky-init && yarn

  4. Added "prepare": "husky install" to the package.json scripts

  5. Added the following configuration to package.json:

    "lint-staged": {
        "*.{js,ts,tsx}": [
            "eslint --quiet --cache --fix"
        ],
        "*.{json,js,ts,jsx,tsx,html}": [
            "prettier --write"
        ]
    },
    
  6. Added my action to the pre-commit file :

    npx husky add .husky/pre-commit "yarn prettier"
    

prettier runs when I commit, but everything outside my directory is erased and does not appear anymore on my repo.

How should I handle this?

jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
JSharles
  • 565
  • 1
  • 5
  • 16

0 Answers0