Skip to content

Commit 2f49dee

Browse files
refactor: Use guard clause for commit message
Using a guard clause allows us to whitelist multiple distinct formats. Instead of getting a large or-ed if statement or nested if-statements
1 parent 8add0bc commit 2f49dee

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

conventional-pre-commit.sh

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,12 @@ r_subject=" [\w][\s\S]+"
3030
pattern="^$r_types$r_scope$r_delim$r_subject$"
3131

3232
# check commit message
33-
if ! grep -Pq "$pattern" "$msg_file"; then
34-
echo "[Commit message] $( cat $msg_file )"
35-
echo "
33+
if grep -Pq "$pattern" "$msg_file"; then
34+
exit 0
35+
fi
36+
37+
echo "[Commit message] $( cat $msg_file )"
38+
echo "
3639
Your commit message does not follow Conventional Commits formatting
3740
https://www.conventionalcommits.org/
3841
@@ -53,5 +56,4 @@ Optionally, include a scope in parentheses after the type for more context:
5356
5457
fix(account): remove infinite loop
5558
"
56-
exit 1
57-
fi
59+
exit 1

0 commit comments

Comments
 (0)