Run linters against files staged in Git
lint-staged.sh is a shell script to evaluate a command with the list of Git staged files as its arguments, filtered by globs. There are no additional features.
Tip
If you use lint-staged but do need backup or resetting to the original state in case of errors, you might be interested in this simpler shell script.
Format all staged JS, JSON and MD files with oxfmt:
lint-staged.sh "oxfmt --write" "*.js" "*.json" "*.md"Given staged files index.js and README.md, this will essentially run:
oxfmt --write index.js README.mdIf the command edits any staged files, you can add the new changes by running:
git update-index --againInstall via skills.sh:
npx skills install https://github.com/lint-staged/lint-staged.shAlternatively, add the SKILL.md to your knowledge.
Copy the lint-staged.sh file from this repo somewhere and run it. It should work in the Bourne shell (sh).
You probably want to run lint-staged.sh in a Git pre-commit hook so that you can abort the commit if one of your commands fails.
For example, create the file .git/hooks/pre-commit (and make it executable):
#!/bin/sh
lint-staged.sh "oxfmt --write" "*.js" "*.json" "*.md"
git update-index --againIf you are using npm, you can install lint-staged.sh and Husky from there:
npm install --save-dev lint-staged.sh husky
npx husky init
# Adjust this file according to your needs
edit .husky/pre-commit