summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xcustom-checks58
1 files changed, 21 insertions, 37 deletions
diff --git a/custom-checks b/custom-checks
index 0a1c96f7..bdf37164 100755
--- a/custom-checks
+++ b/custom-checks
@@ -42,48 +42,32 @@ if [ $# -eq 0 ] || [ -z "$1" ]; then
print_help
fi
-# Called to output an error.
-# If called at least one, the return code for this script will be 1.
-output_error() {
- echo "$FILENAME:$LINE_NUMBER $1"
- RETURN_CODE=1
-}
-
-# This function is called for each line in each file to check syntax.
-check_line() {
- line="$1"
-
- if [[ "$line" =~ ^function ]]; then
- if ! [[ "$line" =~ abort$ ]]; then
- if ((FIX_ERRORS)); then
- # Use sed to add the 'abort' flag
- sed -i "${LINE_NUMBER}s/$/ abort/" "$FILENAME"
- else
- output_error 'Function without abort keyword (See :help except-compat)'
- fi
- fi
- fi
+shopt -s globstar
- if [[ "$line" =~ ' '+$ ]]; then
- output_error 'Trailing whitespace'
- fi
+directory="$1"
- endif_regex='^ * end?i? *$'
+check_errors() {
+ regex="$1"
+ message="$2"
- if [[ "$line" =~ $endif_regex ]]; then
- output_error 'Write endif, not en, end, or endi'
- fi
+ for match in $(
+ grep --color=never -Pn "$regex" "$directory"/**/*.vim \
+ | grep --color=never -Po '^[^:]+:[0-9]+' \
+ | sed 's:^\./::'
+ ); do
+ RETURN_CODE=1
+ echo "$match $message"
+ done
}
-# Loop through all of the vim files and keep track of the file line numbers.
-for FILENAME in $(find "$1" -name '*.vim'); do
- LINE_NUMBER=0
-
- while read; do
- LINE_NUMBER=$(expr $LINE_NUMBER + 1)
+if (( FIX_ERRORS )); then
+ sed -i "s/^\(function.*)\) *$/\1 abort/" "$directory"/**/*.vim
+fi
- check_line "$REPLY"
- done < "$FILENAME"
-done
+check_errors \
+ '^function.*\) *$' \
+ 'Function without abort keyword (See :help except-compat)'
+check_errors ' +$' 'Trailing whitespace'
+check_errors '^ * end?i? *$' 'Write endif, not en, end, or endi'
exit $RETURN_CODE