Skip to content

Commit cecce57

Browse files
committed
post-commit: strip color from linter output
1 parent e8f0c3e commit cecce57

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

.husky/post-commit

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@
22
. "$(dirname "$0")/_/husky.sh"
33

44
SHORT_SHA=$(git rev-parse HEAD)
5-
LINT_LOG="$TMPDIR"/ncu.lint."$SHORT_SHA".log
5+
LINT_LOG="$TMPDIR"/lint."$SHORT_SHA".log
6+
7+
# strip color
8+
strip() {
9+
sed -r "s/\x1B\[([0-9]{1,3}(;[0-9]{1,2};?)?)?[mGK]//g"
10+
}
611

712
# display a notification
813
notify() {
@@ -26,8 +31,8 @@ notify() {
2631
# ensure failed lint exit code passes through sed
2732
set -o pipefail
2833

29-
branch=$(git branch --show-current)
3034
# Do NOT run this when rebasing or we can't get the branch
35+
branch=$(git branch --show-current)
3136
if [ -z "$branch" ]; then
3237
exit 0
3338
fi
@@ -37,4 +42,4 @@ fi
3742
# first error shown.
3843
# We pipe output so that the terminal (tmux, vim, emacs etc.) isn't borked by
3944
# stray output.
40-
npm run lint:src &> "$LINT_LOG" || notify "Lint Error" &
45+
npm run lint:src | strip &> "$LINT_LOG" || notify "Lint Error" &

0 commit comments

Comments
 (0)