Commit 047f4c2e authored by Pádraig Ó Conbhuí's avatar Pádraig Ó Conbhuí
Browse files

Cleaned format.sh. Added lint.sh and .clang-tidy.

parent 33256905
---
Checks: '*,-llvm-header-guard'
WarningsAsErrors: ''
HeaderFilterRegex: ''
AnalyzeTemporaryDtors: false
FormatStyle: none
User: poconbhui
CheckOptions:
...
......@@ -12,17 +12,22 @@ suffixes=( .cpp .hpp )
CLANG_FORMAT_EXECUTABLE=$(which clang-format)
VERBOSE=
# Options array to store all popped options
declare -a options
# Loop over arguments
while :
do
case "$1" in
--clang-format=*)
CLANG_FORMAT_EXECUTABLE="$(echo "$1" | sed 's/--clang-format=//')"
options=( "${options[@]}" "$1" )
shift
;;
--verbose)
VERBOSE="--verbose"
options=( "${options[@]}" "$1" )
shift
;;
......@@ -114,4 +119,4 @@ fi
# On some / no file arguments, run the formatter over all the files.
"${script_dir}"/list_files.sh "${suffixes[@]}" "$@" \
| xargs -n 1 "$0" --clang-format="${CLANG_FORMAT_EXECUTABLE}" ${VERBOSE}
| xargs -n 1 "$0" "${options[@]}"
#!/usr/bin/env bash
# List the suffixes that will be formatted in subdirectory recursion.
suffixes=( .cpp .hpp )
#
# Parse optional arguments
#
# Set defaults for the optional arguments
CLANG_TIDY_EXECUTABLE=$(which clang-tidy)
VERBOSE=
declare -a options
declare -a clang_tidy_options
# Loop over arguments
while :
do
case "$1" in
--clang-tidy=*)
CLANG_TIDY_EXECUTABLE="$(echo "$1" | sed 's/--clang-tidy=//')"
options=( "${options[@]}" "$1" )
shift
;;
--verbose)
VERBOSE="--verbose"
options=( "${options[@]}" "$1" )
shift
;;
--help)
echo
echo "Usage: lint.sh [OPTIONS] [CLANG_TIDY_OPTIONS] [FILE|DIRECTORY ...]"
echo
echo "Options:"
echo " --clang-tidy=CLANG_TIDY_EXECUTABLE"
echo " Set the clang-tidy executable to use."
echo
echo " --verbose"
echo " Enable verbose output"
echo
echo "Clang Tidy Options:"
echo " -p=BUILD_DIRECTORY"
echo
echo "Examples:"
echo " tidy.sh"
echo " tidy.sh /path/to/file.cpp"
echo " tidy.sh --clang-tidy=my-clang-tidy file.cpp"
echo " tidy.sh -p=/path/to/build /path/to/src"
echo " tidy.sh file_1.cpp file_2.cpp src/"
echo
echo "Arguments to be passed to clang-tidy must be of the form"
echo "\"--option\" or \"--option=value\". This script doesn't"
echo "check for 2-part arguments."
echo
exit 0
;;
-*)
clang_tidy_options=( "${clang_tidy_options[@]}" "$1" )
options=( "${options[@]}" "$1" )
shift
;;
*)
break
;;
esac
done
if [[ -z "${CLANG_TIDY_EXECUTABLE}" ]]
then
echo >&2 "Error: No clang-tidy executable found!"
exit 1
fi
echo_verbose() {
if [[ -n "${VERBOSE}" ]]
then
echo >&2 "$@"
fi
}
script_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
#
# If given exactly one file argument, parse it.
#
if [[ $# -eq 1 ]] && [[ -f "$1" ]]
then
target_file=$1
# Only lint files with the correct suffix
if [[ -z "$("${script_dir}"/list_files.sh "${suffixes[@]}" "${target_file}")" ]]
then
echo >&2 "Error: File suffix not one of: \"${suffixes[@]}\""
echo >&2 " File: ${target_file}"
exit 1
fi
echo_verbose "Linting: ${target_file}"
# Run clang-tidy!
"${CLANG_TIDY_EXECUTABLE}" "${clang_tidy_options[@]}" "${target_file}"
exit 0
fi
# On some / no file arguments, run the formatter over all the files.
"${script_dir}"/list_files.sh "${suffixes[@]}" "$@" \
| xargs -n 1 "$0" "${options[@]}"
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment