-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathpre-commit
More file actions
executable file
·27 lines (21 loc) · 1.03 KB
/
pre-commit
File metadata and controls
executable file
·27 lines (21 loc) · 1.03 KB
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
# Auto-formats any changelog fragments present in this commit,
# using "markdownlint --fix" and forced rewrapping. Adds the edits
# to the commit. Does not support partially staged changelog files.
# It is more expensive to run the full `make lint-changelog` (and possibly
# skip reformatting) than it is to just reformat no matter what.
# make lint-changelog >/dev/null 2>&1 && exit 0
# Find the list of files in .changelog/ that are staged.
staged_fragments="$(git diff --cached --name-only -- .changelog/*.md)"
# Re-wraps file $1 to 80 characters per line, using prettier, in-place.
rewrap() {
# Suppress the output of prettier, as it's overly verbose. Show only on errors.
prettier --no-config --no-editorconfig --prose-wrap always --print-width 78 --write "$f" >/tmp/prettier.out \
|| { cat /tmp/prettier.out; exit 1; }
}
for f in $staged_fragments; do
echo "Auto-formatting $f"
markdownlint --fix "$f" >/dev/null 2>&1 # any non-fixable errors will be re-shown when linting later
rewrap "$f"
git add "$f"
done