-
Notifications
You must be signed in to change notification settings - Fork 284
/
precommit.sh
executable file
·26 lines (20 loc) · 1.01 KB
/
precommit.sh
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
#!/bin/bash
# Precommit hook for formatting staged files.
# Formatting is slow. Linting is slow. That's not much fun in a precommit hook.
# We only run the formatter over staged files, and we parallelize with chunks of 10 files per prettier.
# Linting is run over everything, but we parallelize over projects directories, and use --cache to improve repeat runs.
# Optional env var: HOOKS_NO_LINT, disables linting to bypass requiring a bootstrapped yarn-project.
set -euo pipefail
cd $(dirname $0)
export FORCE_COLOR=true
staged_files_cmd="git diff-index --diff-filter=d --relative --cached --name-only HEAD"
function lint {
ls -d ./*/src | xargs dirname | parallel 'cd {} && ../node_modules/.bin/eslint --cache ./src'
}
export -f lint
parallel ::: \
'yarn prepare:check' \
"$staged_files_cmd | grep -E '\.(json|js|mjs|cjs|ts)$' | parallel -N10 ./node_modules/.bin/prettier --loglevel error --write"
# TODO(ci3) find a way to ensure the yarn-project state is ready for linting
# "lint"
$staged_files_cmd | xargs -r git add