Skip to content

Instantly share code, notes, and snippets.

@airglow923
Last active April 17, 2021 14:16
Show Gist options
  • Save airglow923/5059459d2961695f0b3373e99aca58ec to your computer and use it in GitHub Desktop.
Save airglow923/5059459d2961695f0b3373e99aca58ec to your computer and use it in GitHub Desktop.
Run clang-tidy given directories and regex pattern.
#!/bin/bash
usage() {
# additional error messages
if [ "$#" -ne 0 ]; then
printf "$@\n" >&2;
fi
printf "Usage: $0 [ -e REGEX_PATTERN ] DIRECTORY [DIRECTORIES...]\n" >&2;
}
if [ "${#@}" -eq 0 ]; then
usage
exit 1;
fi
DIRECTORIES=""
# default regex pattern
REGEX_PATTERN='.*\.(h|hpp|hxx|c|cc|cpp|cxx)$'
while [ "$#" -gt 0 ]; do
key="$1"
case "$key" in
-h|--help)
usage
exit 0
;;
-e)
REGEX_PATTERN="$2"
shift
shift
;;
*)
DIRECTORIES+="$1 "
shift
;;
esac
done
if [ -z "$DIRECTORIES" ]; then
usage "No directories are provided."
exit 1;
fi
CLANG_TIDY_FILES=$(
find $DIRECTORIES -type f -regextype posix-extended -regex "$REGEX_PATTERN"
)
for file in ${CLANG_TIDY_FILES}; do
clang-tidy "$file"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment