Skip to content

Commit adc34df

Browse files
committed
test(pre-commit): apply shfmt+shellcheck to test/runLint
1 parent 33c18ce commit adc34df

File tree

2 files changed

+17
-14
lines changed

2 files changed

+17
-14
lines changed

.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ repos:
1313
hooks:
1414
- id: shfmt
1515
types: [text]
16-
files: ^(bash_completion(\.d/[^/]+\.bash)?|completions/.+|test/(config/bashrc|fallback/update-fallback-links|update-test-cmd-list)|.+\.sh(\.in)?)$
16+
files: ^(bash_completion(\.d/[^/]+\.bash)?|completions/.+|test/(config/bashrc|fallback/update-fallback-links|runLint|update-test-cmd-list)|.+\.sh(\.in)?)$
1717
exclude: ^completions/(\.gitignore|Makefile.*)$
1818

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

test/runLint

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,55 +6,58 @@ gitgrep()
66
local out=$(git grep -I -P -n "$1" |
77
grep -E '^(bash_completion|completions/|test/)' |
88
grep -Ev "^test/runLint\>${filter_out:+|$filter_out}")
9-
if [ "$out" ]; then
9+
if [[ $out ]]; then
1010
printf '***** %s\n' "$2"
1111
printf '%s\n\n' "$out"
1212
fi
1313
}
1414

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

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

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

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

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

30-
gitgrep $cmdstart'sed\b.*\\\|' \
33+
gitgrep "$cmdstart"'sed\b.*\\\|' \
3134
"sed with \|, use POSIX BRE (possibly multiple sed invocations) or another tool instead"
3235

3336
# TODO: really nonportable? appears to work fine in Linux, FreeBSD, Solaris
3437
#gitgrep $cmdstart'sed\b.*;' \
3538
# 'sed with ;, use multiple -e options instead (POSIX?) (false positives?)'
3639

37-
gitgrep $cmdstart'sed\b.*[[:space:]]-[^[:space:]]*[rE]' \
40+
gitgrep "$cmdstart"'sed\b.*[[:space:]]-[^[:space:]]*[rE]' \
3841
'sed with -r or -E, drop and use POSIX BRE instead'
3942

40-
gitgrep $cmdstart'[ef]grep\b' \
43+
gitgrep "$cmdstart"'[ef]grep\b' \
4144
'[ef]grep, use grep -[EF] instead (historical/deprecated)'
4245

4346
# TODO: $ in sed subexpression used as an anchor (POSIX BRE optional, not in
4447
# Solaris/FreeBSD)
4548

46-
gitgrep '(?<!command)'$cmdstart'(grep|ls|sed|cd)(\s|$)' \
49+
gitgrep '(?<!command)'"$cmdstart"'(grep|ls|sed|cd)(\s|$)' \
4750
'invoke grep, ls, sed, and cd through "command", e.g. "command grep"'
4851

49-
gitgrep '(?<!command)'$cmdstart'awk(\s|$)' \
52+
gitgrep '(?<!command)'"$cmdstart"'awk(\s|$)' \
5053
'invoke awk through "_comp_awk"'
5154

5255
gitgrep '<<<' 'herestrings use temp files, use some other way'
5356

5457
filter_out='^(test/|bash_completion\.sh)' gitgrep ' \[ ' \
5558
'use [[ ]] instead of [ ]'
5659

57-
gitgrep $cmdstart'unset [^-]' 'Explicitly specify "unset -v/-f"'
60+
gitgrep "$cmdstart"'unset [^-]' 'Explicitly specify "unset -v/-f"'
5861

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

0 commit comments

Comments
 (0)