Skip to content

Commit b3cea66

Browse files
committed
chore: show lint output in pre-commit hook
1 parent 486177f commit b3cea66

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

.githooks/pre-commit

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,20 @@ for pkg in $pkgs; do
1414

1515
echo "[pre-commit] $dir"
1616

17-
out="$(npm --prefix "$dir" run -s lint:fix 2>&1)" && { git add -u "$dir"; continue; }
18-
19-
echo "$out" | grep -qi 'missing script:.*lint:fix' && {
20-
out2="$(npm --prefix "$dir" run -s lint -- --fix 2>&1)" && { git add -u "$dir"; continue; }
21-
echo "$out2" | grep -qi 'missing script:.*lint' && { echo "[pre-commit] no lint script, skipping"; continue; }
22-
echo "$out2" >&2
23-
exit 1
24-
}
25-
26-
echo "$out" >&2
17+
tmp="$(mktemp)"
18+
if npm --prefix "$dir" run lint:fix 2>&1 | tee "$tmp"; then
19+
rm -f "$tmp"
20+
git add -u "$dir"
21+
continue
22+
fi
23+
24+
if grep -qi 'missing script:.*lint:fix' "$tmp"; then
25+
rm -f "$tmp"
26+
npm --prefix "$dir" run lint -- --fix
27+
git add -u "$dir"
28+
continue
29+
fi
30+
31+
rm -f "$tmp"
2732
exit 1
28-
done
33+
done

0 commit comments

Comments
 (0)