Skip to content

Commit

Permalink
test(pre-commit): apply shfmt+shellcheck to test/runLint
Browse files Browse the repository at this point in the history
  • Loading branch information
akinomyoga committed Nov 27, 2023
1 parent a1c5c30 commit bae5ee8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ repos:
hooks:
- id: shfmt
types: [text]
files: ^(bash_completion(\.d/[^/]+\.bash)?|completions/.+|test/(config/bashrc|fallback/update-fallback-links|update-test-cmd-list)|.+\.sh(\.in)?)$
files: ^(bash_completion(\.d/[^/]+\.bash)?|completions/.+|test/(config/bashrc|fallback/update-fallback-links|runLint|update-test-cmd-list)|.+\.sh(\.in)?)$
exclude: ^completions/(\.gitignore|Makefile.*)$

- repo: https://github.com/shellcheck-py/shellcheck-py
Expand All @@ -22,7 +22,7 @@ repos:
- id: shellcheck
args: [-f, gcc]
types: [text]
files: ^(bash_completion(\.d/[^/]+\.bash)?|completions/.+|test/(config/bashrc|fallback/update-fallback-links|update-test-cmd-list)|.+\.sh(\.in)?)$
files: ^(bash_completion(\.d/[^/]+\.bash)?|completions/.+|test/(config/bashrc|fallback/update-fallback-links|runLint|update-test-cmd-list)|.+\.sh(\.in)?)$
exclude: ^completions/(\.gitignore|Makefile.*)$
require_serial: false # We disable SC1090 anyway, so parallel is ok

Expand Down
25 changes: 14 additions & 11 deletions test/runLint
Original file line number Diff line number Diff line change
Expand Up @@ -6,52 +6,55 @@ gitgrep()
local out=$(git grep -I -P -n "$1" |
grep -E '^(bash_completion|completions/|test/)' |
grep -Ev "^test/runLint\>${filter_out:+|$filter_out}")
if [ "$out" ]; then
if [[ $out ]]; then
printf '***** %s\n' "$2"
printf '%s\n\n' "$out"
fi
}

unset -v CDPATH
cd $(dirname "$0")/..
if ! cd "$(dirname "$0")/.."; then
echo 'test/runLint: failed to cd into the working tree of bash-completion' >&2
exit 2
fi

cmdstart='(^|[[:space:];&|]|\()'
filter_out=

gitgrep $cmdstart"awk\b.*-F([[:space:]]|[[:space:]]*[\"'][^\"']{2,})" \
gitgrep "${cmdstart}awk\b.*-F([[:space:]]|[[:space:]]*[\"'][^\"']{2,})" \
'awk with -F char or -F ERE, use -Fchar instead (Solaris)'

gitgrep $cmdstart"(_comp_)?awk\b.*\[:[a-z]*:\]" \
gitgrep "${cmdstart}(_comp_)?awk\b.*\[:[a-z]*:\]" \
'awk with POSIX character class not supported in mawk-1.3.3-20090705 (Debian/Ubuntu)'

gitgrep $cmdstart'sed\b.*\\[?+]' \
gitgrep "$cmdstart"'sed\b.*\\[?+]' \
'sed with ? or +, use POSIX BRE instead (\{m,n\})'

gitgrep $cmdstart'sed\b.*\\\|' \
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]' \
gitgrep "$cmdstart"'sed\b.*[[:space:]]-[^[:space:]]*[rE]' \
'sed with -r or -E, drop and use POSIX BRE instead'

gitgrep $cmdstart'[ef]grep\b' \
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|cd|awk)(\s|$)' \
gitgrep '(?<!command)'"$cmdstart"'(grep|ls|sed|cd|awk)(\s|$)' \
'invoke grep, ls, sed, cd, and awk 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 [ ]'

gitgrep $cmdstart'unset [^-]' 'Explicitly specify "unset -v/-f"'
gitgrep "$cmdstart"'unset [^-]' 'Explicitly specify "unset -v/-f"'

gitgrep $cmdstart'((set|shopt)\s+[+-][a-z]+\s+posix\b|(local\s+)?POSIXLY_CORRECT\b)' \
gitgrep "$cmdstart"'((set|shopt)\s+[+-][a-z]+\s+posix\b|(local\s+)?POSIXLY_CORRECT\b)' \
'fiddling with posix mode breaks keybindings with some bash versions'

0 comments on commit bae5ee8

Please sign in to comment.