forked from instructure/canvas-lms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pre-commit
executable file
·46 lines (37 loc) · 1.2 KB
/
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/usr/bin/env bash
ORANGE='\033[0;33m'
NC='\033[0m' # No Color
if [[ "$SKIP_CANVAS_PRECOMMIT_HOOK" == "1" ]]; then
exit 0
fi
SCRIPTPATH="$(
cd -- "$(dirname "$0")" >/dev/null 2>&1
pwd -P
)"
CANVAS=$(dirname $SCRIPTPATH)
NEW_JS_FILES=$(git diff --cached --name-only --diff-filter=A | grep -E "ui/.*\.(js|jsx)$")
if [ -n "$NEW_JS_FILES" ]; then
echo -e "${ORANGE}Warning: Found new .js or .jsx files. Please use TypeScript for new files:${NC}"
echo "$NEW_JS_FILES"
fi
if [ $(pwd -P) = $CANVAS ]; then
# if .js, .ts, or .tsx files have changed, run eslint
if [ -f node_modules/.bin/lint-staged ]; then
echo 'Running ESLint...'
yarn run --silent lint:staged
if [ $? -ne 0 ]; then
echo 'ESLint errors found, aborting commit'
exit 1
fi
else
echo 'Trying to run lint:staged inside Docker. If you want things quicker yarn install locally.'
docker-compose exec -T web yarn run lint:staged ||
echo "You should run yarn locally or check to make sure docker is running."
fi
if git diff --cached --name-only | grep -q 'Gemfile\S*.lock'; then
echo "Checking lockfiles..."
bundle check
fi
fi
$CANVAS/script/rlint ${RLINT_ARGUMENTS:- --auto-correct-all}
exit 0