summaryrefslogtreecommitdiffstats
path: root/test/runLint
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-15 16:24:27 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-15 16:24:27 +0000
commit6c18848a903eb3ee06dccd915859ce64195c257c (patch)
treeea0fe36eb5e6f40e0a1f765d44c4b0c0b2bfb089 /test/runLint
parentInitial commit. (diff)
downloadbash-completion-6c18848a903eb3ee06dccd915859ce64195c257c.tar.xz
bash-completion-6c18848a903eb3ee06dccd915859ce64195c257c.zip
Adding upstream version 1:2.11.upstream/1%2.11
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'test/runLint')
-rwxr-xr-xtest/runLint51
1 files changed, 51 insertions, 0 deletions
diff --git a/test/runLint b/test/runLint
new file mode 100755
index 0000000..95c3887
--- /dev/null
+++ b/test/runLint
@@ -0,0 +1,51 @@
+#!/bin/bash -u
+
+gitgrep()
+{
+ local out=$(git grep -I -P -n "$1" |
+ grep -E '^(bash_completion|completions/|test/)' |
+ grep -Ev "^test/runLint\>${filter_out:+|$filter_out}")
+ if [ -n "$out" ]; then
+ printf '***** %s\n' "$2"
+ printf '%s\n\n' "$out"
+ fi
+}
+
+unset CDPATH
+cd $(dirname "$0")/..
+
+cmdstart='(^|[[:space:]]|\()'
+filter_out=
+
+gitgrep $cmdstart"awk\b.*-F([[:space:]]|[[:space:]]*[\"'][^\"']{2,})" \
+ 'awk with -F char or -F ERE, use -Fchar instead (Solaris)'
+
+gitgrep $cmdstart"awk\b.*\[:[a-z]*:\]" \
+ 'awk with POSIX character class not supported in mawk (Debian/Ubuntu)'
+
+gitgrep $cmdstart'sed\b.*\\[?+]' \
+ 'sed with ? or +, use POSIX BRE instead (\{m,n\})'
+
+gitgrep $cmdstart'sed\b.*\\\|' \
+ "sed with \|, use POSIX BRE (possibly multiple sed invocations) or another tool instead"
+
+# TODO: really nonportable? appears to work fine in Linux, FreeBSD, Solaris
+#gitgrep $cmdstart'sed\b.*;' \
+# 'sed with ;, use multiple -e options instead (POSIX?) (false positives?)'
+
+gitgrep $cmdstart'sed\b.*[[:space:]]-[^[:space:]]*[rE]' \
+ 'sed with -r or -E, drop and use POSIX BRE instead'
+
+gitgrep $cmdstart'[ef]grep\b' \
+ '[ef]grep, use grep -[EF] instead (historical/deprecated)'
+
+# TODO: $ in sed subexpression used as an anchor (POSIX BRE optional, not in
+# Solaris/FreeBSD)
+
+gitgrep '(?<!command)'$cmdstart'(grep|ls|sed)(\s|$)' \
+ 'invoke grep, ls, and sed through "command", e.g. "command grep"'
+
+gitgrep '<<<' 'herestrings use temp files, use some other way'
+
+filter_out='^(test/|bash_completion\.sh)' gitgrep ' \[ ' \
+ 'use [[ ]] instead of [ ]'