Skip to content

Commit

Permalink
feat: add pre-comit check check-title-initial
Browse files Browse the repository at this point in the history
  • Loading branch information
CodeChenL committed Feb 28, 2024
1 parent 1985d9a commit 66eff17
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .pre-commit-hooks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,8 @@
entry: pre_commit_hooks/main.sh check-chinese
language: script
types_or: [markdown]
- id: check-title-initial
name: Check if the first letter of the title is capitalized
entry: pre_commit_hooks/main.sh check-title-initial
language: script
types_or: [markdown]
18 changes: 18 additions & 0 deletions pre_commit_hooks/check-title-initial.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/usr/bin/env bash

check() {
local ret=0

# Check if the first letter of the title is capitalized
if grep -qE '^# [a-z]' "$1" >/dev/null
then
ret=1
echo "$1: First letter of the title should be capitalized" >&2
if ! $DRY_RUN
then
sed -i -E 's/^# ([a-z])/# \U\1/' "$1"
fi
fi

return $ret
}

0 comments on commit 66eff17

Please sign in to comment.