lefthook.yml in n8n codebase.
In this article, we review lefthook.yml in n8n codebase.
But what is lefthook?
LeftHook
LeftHook is a fast and powerful Git hooks manager for any type of projects.
Install
npm install lefthook --save-dev
Usage
Configure your hooks, install them once and forget about it: rely on the magic underneath.
# Configure your hooks
vim lefthook.yml
# Install them to the git project
lefthook install
# Enjoy your work with git
git add -A && git commit -m '...'
I picked the installation and usage from the lefthook documentation.
So obviously there is a lot of information in the documentation. We want to focus only on the options used in n8n lefthook.yml file.
n8n/lefthook.yml
pre-commit:
commands:
biome_check:
glob: 'packages/**/*.{js,ts,json}'
run: pnpm biome check --write --no-errors-on-unmatched --files-ignore-unknown=true --colors=off {staged_files}
stage_fixed: true
skip:
- merge
- rebase
prettier_check:
glob: 'packages/**/*.{vue,yml,md,css,scss}'
run: pnpm prettier --write --ignore-unknown --no-error-on-unmatched-pattern {staged_files}
stage_fixed: true
skip:
- merge
- rebase
This above code is picked from n8n/lefthook.yml.
pre-commit
In a lefthook.yml
file, the pre-commit
block defines Git hooks that run before a commit is created.
Before your commit is created, there are two commands run:
- biome_check
This runs the below command
pnpm biome check --write --no-errors-on-unmatched --files-ignore-unknown=true --colors=off {staged_files}
2. prettier_check
This runs the below command
pnpm prettier --write --ignore-unknown --no-error-on-unmatched-pattern {staged_files}
This is a common practice to lint and apply pettier to your code before your code is committed.
About me:
Hey, my name is Ramu Narasinga. I study large open-source projects and create content about their codebase architecture and best practices, sharing it through articles, videos.
Configure features such as Changesets in your Next.js project using Think Throo CLI.
Email — ramu@thinkthroo.com
My Github — https://github.com/ramu-narasinga
My website — https://ramunarasinga.com
My YouTube channel — https://www.youtube.com/@ramu-narasinga
Learning platform — https://thinkthroo.com
Codebase Architecture — https://app.thinkthroo.com/architecture
Best practices — https://app.thinkthroo.com/best-practices
Production-grade projects — https://app.thinkthroo.com/production-grade-projects