in

Husky + lint-staged – DEV Community


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



Source: https://dev.to/edsonjuniornarvaes/husky-lint-staged-2bjo

Leave a Reply

Your email address will not be published. Required fields are marked *

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

GIPHY App Key not set. Please check settings

A Python – SWI-Prolog bridge enabling to query SWI-Prolog

Rookout Launches Live Logger to Dynamically Modify Log Verbosity