Now, every time you commit, your tests will run automatically. If they fail, the commit won’t go through, protecting your main branch from broken code.

You can also use tools like ESLint, Prettier, or lint-staged to format and lint your code before commits.

For example: npx husky add .husky/pre-commit "npx lint-staged"

And in your package.json:

{
"lint-staged": {
"*.{js,ts,jsx,tsx}": ["eslint --fix", "prettier --write"]
}
}

This ensures only the staged files are linted and formatted, making the process faster. Other Pre-Commit Tools You Should Know

Different languages and ecosystems have their own pre-commit tools. Here are a few popular ones:

  • JavaScript/TypeScript: Husky, Lefthook, Yorkie
  • Python: pre-commit
  • Ruby: Overcommit
  • Go: pre-commit-go
  • Java: Spotle…

Similar Posts

Loading similar posts...

Keyboard Shortcuts

Navigation
Next / previous item
j/k
Open post
oorEnter
Preview post
v
Post Actions
Love post
a
Like post
l
Dislike post
d
Undo reaction
u
Recommendations
Add interest / feed
Enter
Not interested
x
Go to
Home
gh
Interests
gi
Feeds
gf
Likes
gl
History
gy
Changelog
gc
Settings
gs
Browse
gb
Search
/
General
Show this help
?
Submit feedback
!
Close modal / unfocus
Esc

Press ? anytime to show this help