HUSKY is invalid? How does the new version of Husky configuration?

HUSKY does not take effect

Install Husky, Lint-staged, and complete the configuration. Configuration is shown:

 

Commit is still there is no effect, did not execute LinT-staged

 

Cause: Husky’s new version is different from the old version, as the configuration of the above picture, only 4.x

So directly install a 4.3.8 version of Husky to take effect

 

About the new version of Husky, more actions than the old version.

Old versions: installation -> configuration

New version: Installation -> Enable -> Build .husky related configuration

 

Steps:

  1. npm install husky –save-dev installation
  2. npx husky INSTALL manually enables husky
  3. npx husky add .husky/pre-commit “NPM Run Lint-staged” generates a HUSKY configuration file (this step is performed, the root directory will have a .husky directory)

Complete this three steps can be used normally (provided that the lint-staged inside package.js “is already configured)

 

The above configuration method has oneQuestion: We can’t make Husky every time INSTALL, if developing A is configured and submitted, develop B pull down code, and it needs to be manually enabled.

Solve this issue, add the following configuration in Package.json:

“scripts”: { “prepare”: “husky install” }

Its role is to automatically associate after Husky installation. In addition to developing A requires concern if Husky configuration, other subsequent developers do not need to care about Husky configuration.

 

Husky Lint-Staged Complete Steps

  1. npm install husky lint-staged prettier –save-dev
  2. npx husky install [Enable]
  3. “prepare”“husky install”  [Install is automatically enabled, this action must be done, otherwise the next new pull code also needs to be manually enabled]
  4. npx husky add .husky/pre-commit “NPM Run Lint-staged” [Create a hook, perform the root directory back to generate a .husky directory]
  5. Continue to add “Lint” in Scripts: “Eslint –ext .js, .jsx, .ts, .tsx src”, “lint-staged”: “lint-staged”
  6. Paackage.json Add “Lint-Staged”: {“** / *. {JS, JSX, TS, TSX}”: “NPM Run Lint”, “** / *. {JS, JSX, TSX, TS, LESS, MD}: [“prettier –write”]}

After completing the above operation, you can try it.

 

 husky 7

Related documents:https://typicode.github.io/husky/#/?id=install