Hi Friends,
Reducing friction is one of the best long-term investments you can make in your team.
In this newsletter, I’m giving practical tips on achieving this in NodeJS projects.
It might take some time for everyone to get used to these tools and conventions, but once that happens, it eliminates a lot of thinking, and your brain starts working on autopilot.
Why It Matters
Nobody likes to point out missing newlines or inconsistent formatting in Pull Requests when they could be focusing on critical issues like functionality, architecture, or maintainability. Yet these are also crucial and should be addressed.
Here’s how:
Consistency:
.editorconfig
ensures uniform file formatting (e.g., line endings, final newlines).Automation: Git hooks (via Husky) automate tasks like linting, formatting, and enforcing commit standards. Volta to set environments like npm.
Quality Control: Prettier and semantic commit checks improve code clarity and maintainability.
Let’s see how we can achieve these on autopilot. 🧑✈️
Tools & Configurations
.editorconfig
for Formatting
Define consistent file formatting rules across editors:
[*]
insert_final_newline = true
end_of_line = lf
Drawback: Requires the EditorConfig plugin in your IDE.
.gitattributes
for Line Endings in Git
Normalize line endings to avoid cross-platform issues:
* text=auto eol=lf
Git Hooks with Husky
Automate pre-commit checks and enforce standards:
Install Husky:
npm install --save-dev husky
Add a pre-commit hook for formatting:
npx husky init
Example
package.json
scripts:
{
"scripts": {
"prepare": "husky"
"lint:fix": "turbo lint:fix --parallel"
}
}
Semantic Commit Messages
Enforce conventional commit messages using a custom Husky hook. Simply create this file .husky/commit-check
, and husky will run the new check:
#!/bin/sh
if ! head -1 "$1" | grep -qE "^(feat|fix|chore|docs|test|style|refactor|perf|build|ci|revert)(\(.+?\))?: .{1,}$"; then
echo "Aborting commit. Your commit message is invalid." >&2
exit 1
fi
if ! head -1 "$1" | grep -qE "^.{1,88}$"; then
echo "Aborting commit. Your commit message is too long." >&2
exit 1
fi
Prettier for Code Formatting
Install Prettier for consistent code style:
npm install prettier --save-dev
Integrate it with Husky to format staged files:
{
"lint-staged": {
"*": "prettier --write"
}
}
Also, make sure to set up formatting on save with Prettier inside your editor. For this to work, you’ll also need the Prettier plugin for your editor.
Enforce Semantic PR Titles
Use GitHub Actions to validate PR titles with action-semantic-pull-request.
I rarely write technical articles in my newsletter and keep those for my blog instead, but I was wondering if you like this type of content, so please share your thoughts:
How to Take Action Now
Add
.editorconfig
and.gitattributes
to your project.Install Husky and configure pre-commit hooks for formatting and linting.
Set up semantic commit validation to enforce clear message conventions.
Use Prettier to ensure consistent code style.
Automate PR title checks with GitHub Actions.
These steps will help you maintain high-quality code, streamline collaboration, and prevent common pitfalls in multi-developer projects!
Do you use any of these tools in your day job?
Take It To The Next Level
You can have the best automation, but your tests prevent you from shipping broken stuff on a Friday. Luckily, my latest book covers this.
Become the Engineer at your organization who not only knows the theory of testing but also puts everything into practice right now (be careful, your actions might involve a promotion)
📰 Weekly shoutout
📣 Share
There’s no easier way to help this newsletter grow than by sharing it with the world. If you liked it, found something helpful, or you know someone who knows someone to whom this could be helpful, share it:
🏆 Subscribe
Actually, there’s one easier thing you can do to grow and help grow: subscribe to this newsletter. I’ll keep putting in the work and distilling what I learn/learned as a software engineer/consultant. Simply sign up here:
Some great tips Akos.
Husky sounds interesting. Will definitely check it out.
Also, thanks for the mention!
I haven't used Husky a lot, to be honest. I'm using auto-saving to format and lint the files. Then, I'd have a check in the CI for the formatting and linting. But at my current job, we use Husky so I started to see its benefits.
Thank you for the shoutout, Akos!