Skip to content

Commit

Permalink
post-commit: strip color from linter output
Browse files Browse the repository at this point in the history
  • Loading branch information
raineorshine committed Dec 22, 2022
1 parent e8f0c3e commit cecce57
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions .husky/post-commit
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@
. "$(dirname "$0")/_/husky.sh"

SHORT_SHA=$(git rev-parse HEAD)
LINT_LOG="$TMPDIR"/ncu.lint."$SHORT_SHA".log
LINT_LOG="$TMPDIR"/lint."$SHORT_SHA".log

# strip color
strip() {
sed -r "s/\x1B\[([0-9]{1,3}(;[0-9]{1,2};?)?)?[mGK]//g"
}

# display a notification
notify() {
Expand All @@ -26,8 +31,8 @@ notify() {
# ensure failed lint exit code passes through sed
set -o pipefail

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

0 comments on commit cecce57

Please sign in to comment.