Created
January 18, 2025 00:02
-
-
Save n3rio/4e8e40396a28be8079821b9e79685935 to your computer and use it in GitHub Desktop.
NPX Eslint pre hood
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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