Skip to content

Instantly share code, notes, and snippets.

@n3rio
Created January 18, 2025 00:02
Show Gist options
  • Select an option

  • Save n3rio/4e8e40396a28be8079821b9e79685935 to your computer and use it in GitHub Desktop.

Select an option

Save n3rio/4e8e40396a28be8079821b9e79685935 to your computer and use it in GitHub Desktop.
NPX Eslint pre hood
#!/bin/bash
# Put this in .git/hooks/pre-push
# Exit immediately if any command fails
set -e
echo "Running pre-push checks..."
# Get the list of files to be pushed
files_to_push=$(git diff --name-only --cached --diff-filter=ACMRTUXB)
# Filter files by extension (JavaScript/TypeScript)
js_ts_files=$(echo "$files_to_push" | grep -E '\.(js|jsx|ts|tsx)$')
if [ -z "$js_ts_files" ]; then
echo "No JavaScript/TypeScript files to lint."
else
echo "Linting and fixing the following files:"
echo "$js_ts_files"
# Run ESLint on the files to be pushed
echo "$js_ts_files" | xargs npx eslint --fix
fi
echo "Pre-push checks passed. Pushing to remote..."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment