forked from cesium-ml/baselayer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.git-pre-commit
executable file
·25 lines (22 loc) · 929 Bytes
/
.git-pre-commit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#!/bin/bash
# Based on https://gist.github.com/dahjelle/8ddedf0aebd488208a9a7c829f19b9e8
for file in $(git diff --diff-filter=d --cached --name-only | grep -E '\.(js|jsx)$')
do
git show ":$file" | npx eslint -c .eslintrc.yaml --stdin --stdin-filename "$file" # we only want to lint the staged changes, not any un-staged changes
if [ $? -ne 0 ]; then
echo "ESLint failed on staged file '$file'. Please check your code and try again. You can run ESLint manually via make lint."
exit 1 # exit with failure status
fi
done
echo "-> Javascript code passed linter"
UNPINNED=$(cat package.json | grep '\^\|~' | sed 's/,*$//g')
if [[ -n $UNPINNED ]]; then
echo "Some Javascript packages are not pinned to a specific version:"
echo
echo "$UNPINNED"
echo
echo Please pin their versions by, e.g., removing operators such as \~ and ^.
exit 1
else
echo "-> Javascript versions correctly pinned"
fi