-
-
Save s-m-i-t-a/41e3295c6cf85fe7341c to your computer and use it in GitHub Desktop.
Pre-commit to check tracked/commited js/jsx/py files with ESlint and pep8
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
#!/usr/bin/env bash | |
# MIT © Sindre Sorhus - sindresorhus.com | |
# git hook to run a command after `git pull` if a specified file was changed | |
# Run `chmod +x post-merge` to make it executable then put it into `.git/hooks/`. | |
changed_files="$(git diff-tree -r --name-only --no-commit-id ORIG_HEAD HEAD)" | |
check_run() { | |
echo "$changed_files" | grep --quiet "$1" && eval "$2" | |
} | |
# Example usage | |
# In this example it's used to run `npm install` if package.json changed and `bower install` if `bower.json` changed. | |
check_run package.json "npm install" |
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 | |
# use eslint set from environment, otherwise use default | |
ESLINT=${ESLINT:-"node_modules/eslint/bin/eslint.js"} | |
if [ ! -f "$ESLINT" ]; then | |
exit 0 | |
fi | |
files=$(git diff --diff-filter=ACMRT --cached --name-only | grep '\.jsx\|\.js\?$') | |
# Prevent ESLint help message if no files matched | |
if [[ $files = "" ]] ; then | |
exit 0 | |
fi | |
failed=0 | |
for file in ${files}; do | |
git show :$file | $ESLINT --stdin --stdin-filename $file | |
if [[ $? != 0 ]] ; then | |
failed=1 | |
fi | |
done; | |
if [[ $failed != 0 ]] ; then | |
echo "ESLint check failed, commit denied" | |
exit $failed | |
fi |
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/sh | |
.git/hooks/ctags >/dev/null 2>&1 & |
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/sh | |
.git/hooks/ctags >/dev/null 2>&1 & |
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/sh | |
.git/hooks/check.sh | |
.git/hooks/ctags >/dev/null 2>&1 & |
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/sh | |
case "$1" in | |
rebase) exec .git/hooks/post-merge ;; | |
esac |
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/sh | |
# for python | |
.git/hooks/pylint.sh | |
# for javascript | |
.git/hooks/eslint.sh | |
.git/hooks/tslint.sh |
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/sh | |
FILES=$(git diff --cached --name-status | grep -v ^D | awk '$1 $2 { print $2}' | grep -e .py$ | grep -v migrations) | |
if [ -n "$FILES" ]; then | |
for f in $FILES; do | |
pep8 -r $f | |
done | |
fi |
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 | |
# use tslint set from environment, otherwise use default | |
TSLINT=${TSLINT:-"node_modules/tslint/bin/tslint"} | |
if [ ! -f "$TSLINT" ]; then | |
exit 0 | |
fi | |
files=$(git diff --diff-filter=ACMRT --cached --name-only | grep '\.tsx\|\.ts\?$') | |
# Prevent TSlint help message if no files matched | |
if [[ $files = "" ]] ; then | |
exit 0 | |
fi | |
failed=0 | |
for file in ${files}; do | |
$TSLINT $file | |
if [[ $? != 0 ]] ; then | |
failed=1 | |
fi | |
done; | |
if [[ $failed != 0 ]] ; then | |
echo "TSLint check failed, commit denied" | |
exit $failed | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment