DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»

Cover image for Husky + lint-staged
Edson Junior de Andrade
Edson Junior de Andrade

Posted on

Husky + lint-staged

In this post, I'll show you how to improve your husky workflow, using pre-commit to trigger error checking on your code before uploading it to the repository.

To get started, let's install husky with the following command:

yarn add husky -D
Enter fullscreen mode Exit fullscreen mode

In the package.json file I define the scope of the husky with the hook call and then the scope with the definition of the files to be checked, in the example I define the files that end in js and ts.

  "husky": {
    "hooks": {
      "pre-commit": "lint-staged"
    }
  },
  "lint-staged": {
    "*.{js, ts}": [""]
  }
Enter fullscreen mode Exit fullscreen mode

At this point it is necessary to install and configure eslint, in this article I explain how to install eslint step by step link.

Here I configure it to automatically fix our changes: eslint --fix, if it can't fix the file, it will inform the user about the error, so I set git add to include the changes fromeslint -fix

  "lint-staged": {
      "*.{js, ts}": ["eslint --fix", "git add ."]
  }
Enter fullscreen mode Exit fullscreen mode

Top comments (0)

⬇️ The only reason people scroll to the bottom...

Β 

is because they want to read more. Sign up for an account to bookmark, comment, and react to articles that interest you.