Skip to content

Instantly share code, notes, and snippets.

@fazlurr
Created January 9, 2025 16:08
Show Gist options
  • Save fazlurr/66a6a7580b54d6a795fe2bb9d396a333 to your computer and use it in GitHub Desktop.
Save fazlurr/66a6a7580b54d6a795fe2bb9d396a333 to your computer and use it in GitHub Desktop.
Precommit Lint Staged File
#!/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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment