Skip to content

Instantly share code, notes, and snippets.

@mholtzhausen
Forked from dahjelle/pre-commit.sh
Last active February 12, 2022 16:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mholtzhausen/0d7bd7e72976fbfa82a4933cf25b3a0d to your computer and use it in GitHub Desktop.
Save mholtzhausen/0d7bd7e72976fbfa82a4933cf25b3a0d to your computer and use it in GitHub Desktop.
Pre-commit hook for eslint, linting *only* staged changes.
#!/bin/bash
clear
fileList=$(git diff --diff-filter=d --cached --name-only | grep -E '\.(js|vue)$')
if [ ${#fileList} -lt 1 ]; then
echo -e "You have no staged .js or .vue files to test\n"
exit
fi
npx eslint ${fileList[*]} "$@"
if [ $? -ne 0 ]; then
echo -e "\nPlease fix the above linting issues before committing.\n"
exit 1
fi
@patrickkabwe
Copy link

@mholtzhausen do you know why when a lot of files are checked it complaints?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment