From e43aadfb42937feb10ec8073afd663c8ccad702a Mon Sep 17 00:00:00 2001 From: Pierre Pronchery Date: Fri, 9 Dec 2016 00:13:20 +0100 Subject: [PATCH] Try to detect invalid use of return --- doc/scripts/shlint.sh | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/doc/scripts/shlint.sh b/doc/scripts/shlint.sh index 93a9af7..ef8fd97 100755 --- a/doc/scripts/shlint.sh +++ b/doc/scripts/shlint.sh @@ -73,7 +73,24 @@ _shlint() _shlint_file() { - $DEBUG $SHLINT "$filename" 2>&1 + $DEBUG $SHLINT "$filename" 2>&1 || return 2 + #try to detect invalid use of return + #XXX this test is not accurate (therefore a warning) + warn=0 + while read line; do + case "$line" in + *return*) + warn=1 + ;; + *) + warn=0 + ;; + esac + done < "$filename" + if [ $warn -ne 0 ]; then + _warning "$filename: return instead of exit in the global scope" + fi + return 0 } @@ -97,6 +114,14 @@ _usage() } +#warning +_warning() +{ + echo "$PROGNAME: $@" 1>&2 + return 2 +} + + #main clean=0 while getopts "cP:" name; do