Skip to content

Commit

Permalink
✨ (#51) Add new hugdoc docstring linter
Browse files Browse the repository at this point in the history
Fix: #51
  • Loading branch information
MicahElliott committed Nov 8, 2024
1 parent fadd566 commit a2836b5
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
4 changes: 3 additions & 1 deletion bin/capt
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ typeset -A builtin_cannons=(
cljfmt '(clj)cljfmt check $CAPT_FILES_CHANGED'
cljtest '(clj)cljtest $CAPT_FILES_CHANGED'
huglint '(sql)huglint $CAPT_FILES_CHANGED'
hugdoc '(sql)hugdoc $CAPT_FILES_CHANGED'
wscheck 'wscheck $CAPT_FILES_CHANGED'
fixcheck 'fixcheck $CAPT_FILES_CHANGED'
msglint 'msglint "$(cat $GITARG1)"'
Expand All @@ -99,6 +100,7 @@ typeset -A builtin_helps=(
cljfmt 'Format clojure files (pre-commit)'
cljtest 'Run test NSs with existing nrepl conn (pre-commit)'
huglint 'Detect an error in a HugSQL file using ecpg (pre-commit)'
hugdoc 'Detect an missing docstring in a HugSQL file (pre-commit)'
msglint 'Ensure a commit message adheres to a specied standard format (commit-msg)'
wscheck 'Detect whitespace issues: newlines, BOM, tabs, etc (pre-commit)'
fixcheck 'Detect FIXMEs, TODOs, etc (pre-commit)'
Expand Down Expand Up @@ -257,7 +259,7 @@ list_available_hooks () {
then printf ' %-32s (file and capt)\n' $fg_bold[green]$suphook$reset_color
else printf ' %-32s (missing capt call in file)\n' $fg_bold[yellow]$suphook$reset_color
fi
else printf ' %-32s (missing file: $gf)\n' $fg_bold[magenta]$suphook$reset_color
else printf " %-32s (missing file: $gf)\n" $fg_bold[magenta]$suphook$reset_color
fi
else printf ' %-32s (not in capt)\n' $fg_bold[gray]$suphook$reset_color
fi
Expand Down
19 changes: 19 additions & 0 deletions bin/hugdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#! /bin/zsh

# Detect missing docstrings from hugsql files

# This linter could do a lot better with collecting line numbers and putting
# into error-friendly format. This was a quick POC.

# Look for occurrences of `-- :name ...\nNOT-- :doc`

missings=(
$(grep -Pzo -- '-- :name .*?\n[^-]' $1 | while read -r l; do
sed -r 's/.*:name ([a-z<>?!-]+).*/\1/' ; done)
)
if (( $#missings > 0 ))
then print "The following functions are missing docstrings:"
print -l -- ${missings[1,-3]}
exit 1
fi
10 changes: 10 additions & 0 deletions install-deps.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,13 @@ brew install coreutils findutils gnu-tar gnu-sed gawk gnutls gnu-indent gnu-geto
# sqllint
print 'Installing postgres libpq for ecpg sql linting'
brew install libpq

# https://github.com/babashka/bbin (for splint)
print 'Installing babashka bbin (for splint)'
brew install babashka/brew/bbin

# https://cljdoc.org/d/io.github.noahtheduke/splint/1.10.1/doc/installation
print 'Installing splint'
bbin install io.github.noahtheduke/splint

print 'Add to your path for splint: path+=~/.local/bin'

0 comments on commit a2836b5

Please sign in to comment.