diff --git a/bin/capt b/bin/capt index 2442579..dceb616 100755 --- a/bin/capt +++ b/bin/capt @@ -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)"' @@ -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)' @@ -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 diff --git a/bin/hugdoc b/bin/hugdoc new file mode 100755 index 0000000..44b1f1c --- /dev/null +++ b/bin/hugdoc @@ -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 diff --git a/install-deps.zsh b/install-deps.zsh index 7e56895..0c79fc9 100755 --- a/install-deps.zsh +++ b/install-deps.zsh @@ -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'