Skip to main content

lint-staged

lint-staged is a tool that allows to easily run linters against staged git files. We use it in our pre-commit hook usually in combination with Husky.

Use cases​

For example to run the linter (Oxlint) and formatter (Oxfmt) on all staged typescript or javascript files and the formatter on all json or md files, before committing, a configuration like the following can be used:

  • in .husky/pre-commit:
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

npx lint-staged --allow-empty
  • and in package.json:
{
"lint-staged": {
"*.{js,jsx,ts,tsx}": ["oxlint --fix", "oxfmt"],
"*.{json,md}": ["oxfmt"]
}
}

Reference of usage in our organization​

A non exhaustive list of our projects that use Husky: