Skip to content

Instantly share code, notes, and snippets.

@eaigner
Last active August 29, 2015 14:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eaigner/82909602899f8588f0fc to your computer and use it in GitHub Desktop.
Save eaigner/82909602899f8588f0fc to your computer and use it in GitHub Desktop.
vet.bash
#!/bin/bash
# vet.bash
function check_dir() {
egrep -rn -e "$2" "$1"
if [[ $? != 1 ]] ; then
echo "$3"
exit $rc
fi
}
function check() {
for dir in include src test
do
check_dir "$dir" "$1" "$2"
done
}
check "^ " "no leading spaces allowed, use tabs"
check "[^g(](m|c|re)alloc\(" "use guarded allocator"
check "str[nl]?cpy" "use memcpy"
check "sprintf" "sprintf functions are insecure, use the snprintf version instead"
check "for\(" "expected space after 'for' keyword"
check "if\(" "expected space after 'if' keyword"
check "while\(" "expected space after 'while' keyword"
check "switch\(" "expected space after 'swich' keyword"
check "[\[\(] " "remove space after bracket"
check " [\]\)]" "remove space before bracket"
check "[[:space:]]$" "trailing whitespace"
check "} ?(else|while)" "expected newline before (else|while)"
check "(do|for|if|else|while|switch) (.*)?{" "move opening curly brace to next line"
check ".{81,}$" "line exceeds 80 characters"
check "^\t{4,}(if|else|for|while|case|switch|do)" "excessive indent level"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment