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

I…


This content originally appeared on DEV Community and was authored by Edson Junior de Andrade

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

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}": [""]
  }

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 ."]
  }


This content originally appeared on DEV Community and was authored by Edson Junior de Andrade


Print Share Comment Cite Upload Translate Updates
APA

Edson Junior de Andrade | Sciencx (2021-09-21T00:03:15+00:00) Husky + lint-staged. Retrieved from https://www.scien.cx/2021/09/21/husky-lint-staged/

MLA
" » Husky + lint-staged." Edson Junior de Andrade | Sciencx - Tuesday September 21, 2021, https://www.scien.cx/2021/09/21/husky-lint-staged/
HARVARD
Edson Junior de Andrade | Sciencx Tuesday September 21, 2021 » Husky + lint-staged., viewed ,<https://www.scien.cx/2021/09/21/husky-lint-staged/>
VANCOUVER
Edson Junior de Andrade | Sciencx - » Husky + lint-staged. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/09/21/husky-lint-staged/
CHICAGO
" » Husky + lint-staged." Edson Junior de Andrade | Sciencx - Accessed . https://www.scien.cx/2021/09/21/husky-lint-staged/
IEEE
" » Husky + lint-staged." Edson Junior de Andrade | Sciencx [Online]. Available: https://www.scien.cx/2021/09/21/husky-lint-staged/. [Accessed: ]
rf:citation
» Husky + lint-staged | Edson Junior de Andrade | Sciencx | https://www.scien.cx/2021/09/21/husky-lint-staged/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.