DEV Community

Amitav Roy
Amitav Roy

Posted on

1

Setting up husky & lint-staged for code format and unit tests before git push

Having an automated code formatting and php unit runner is a great addition to your automation.

I work in a team where different developers have different habit when it comes to code formatting. Yes, they are small things I know. But, I spend a lot of time in code review. And, reading other's code is always difficult if the formatting is different. And hence, I want to ensure that the code formatting, structure etc are as much similar as possible. It reduces a lot of load from the code review process and speeds up things.

Plus, the aspect of automatically running the unit tests before every code commit is one check enforced for the developer to ensure that his new code is not breaking something which is running properly right now and was working before he / she made any code changes.

And, hence I looked at different options and this combination of husky to hook into the git hooks and lint-staged to get the context of the files which are staged are really helpful.

In this article, I will explain how I did the setup of these two npm modules to ensure code formatting and running php unit before every git push.

Hope you like it, and feel free to leave comments about your views.

https://www.amitavroy.com/justread/content/articles/setting-up-husky-lint-staged-for-code-format-and-unit-tests-before-git-push

Sentry image

Hands-on debugging session: instrument, monitor, and fix

Join Lazar for a hands-on session where you’ll build it, break it, debug it, and fix it. You’ll set up Sentry, track errors, use Session Replay and Tracing, and leverage some good ol’ AI to find and fix issues fast.

RSVP here →

Top comments (0)

Image of Datadog

The Essential Toolkit for Front-end Developers

Take a user-centric approach to front-end monitoring that evolves alongside increasingly complex frameworks and single-page applications.

Get The Kit

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay