Skip to content

lint-staged/lint-staged.sh

Repository files navigation

lint-staged.sh

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.

Example

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.md

If the command edits any staged files, you can add the new changes by running:

git update-index --again

Installation

Agent usage

Install via skills.sh:

npx skills install https://github.com/lint-staged/lint-staged.sh

Alternatively, add the SKILL.md to your knowledge.

Manual usage

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 --again

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

About

Run linters against files staged in Git

Topics

Resources

License

Stars

7 stars

Watchers

0 watching

Forks

Contributors

Languages