Skip to content

Instantly share code, notes, and snippets.

@tuliofaria
Created March 25, 2025 14:09
Show Gist options
  • Save tuliofaria/8d9c0fc70a9c64f7f3c4d985f8c85461 to your computer and use it in GitHub Desktop.
Save tuliofaria/8d9c0fc70a9c64f7f3c4d985f8c85461 to your computer and use it in GitHub Desktop.
lint
#!/bin/sh
STAGED_FILES=$(git diff-index HEAD --name-only --cached | grep -E '\.(js|jsx|ts|tsx)$' || true)
if [[ -z $STAGED_FILES ]]
then
echo 'No relevant staged files, no need to run eslint.'
exit # no relevant staged files, no need to run eslint
fi
# Checks if any staged files have unstaged changes
# otherwise eslint isn't running on what is actually
# going to be committed.
WARN_FILES=$(git diff-files --stat -- $STAGED_FILES)
if [[ -n $WARN_FILES ]]
then
echo 'There are unstaged changes to files (git stash --keep-index to commit safely):'
echo "$WARN_FILES\n"
exit 1
fi
echo "Running eslint..."
exec git diff --cached --name-only --relative --diff-filter=ACMR | grep -E '\.(js|jsx|ts|tsx)$' | xargs \
docker compose run --no-TTY re-store-tools eslint \
--ext js,ts,tsx \
--fix \
--quiet
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment