lint-staged.sh
v0.1.2
Published
Run linters against Git staged files
Readme
lint-staged.sh
Run linters against Git staged files
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 to check if staged files are valid — but not automatically fix them — you might be interested in this simpler shell script.
Example
Run prettier --check with all staged JS, JSON and MD files as its arguments:
lint-staged.sh "prettier --check" "*.js" "*.json" "*.md"Given staged files index.js and README.md, this will essentially run:
prettier --check index.js README.mdInstallation
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 "prettier --check" "*.js" "*.json" "*.md"If 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