Skip to content

Commit eaef89e

Browse files
yedayakscop
authored andcommitted
test(runLint): Use git pathspecs instead of regex
This also makes it easier to exclude files, you just put the paths space separated, without any regex in `filter_out`. Also add files to general exceptions and for specific checks.
1 parent 1309562 commit eaef89e

1 file changed

Lines changed: 10 additions & 6 deletions

File tree

test/runLint

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,13 @@ set -u
33

44
gitgrep()
55
{
6-
local out=$(git grep -I -P -n "$1" |
7-
grep -E '^(bash_completion|completions(-fallback|-core)?/|test/)' |
8-
grep -Ev "^test/runLint\>${filter_out:+|$filter_out}")
6+
local pathspecs=('bash_completion' 'completions-fallback/'
7+
'completions-core/' 'test/' 'bash_completion.d/' ':!:test/runLint'
8+
':!:test/docker/' ':!:test/test-cmd-list.txt')
9+
local filter_list
10+
read -ra filter_list <<<"$filter_out"
11+
pathspecs+=("${filter_list[@]/#/":!:"}")
12+
local out=$(git grep -I -P -n "$1" -- "${pathspecs[@]}")
913
if [[ $out ]]; then
1014
printf '***** %s\n' "$2"
1115
printf '%s\n\n' "$out"
@@ -53,7 +57,7 @@ gitgrep "$cmdstart"'[ef]grep\b' \
5357
# TODO: $ in sed subexpression used as an anchor (POSIX BRE optional, not in
5458
# Solaris/FreeBSD)
5559

56-
gitgrep '(?<!command)'"$cmdstart"'(grep|ls|sed|cd)(\s|$)' \
60+
filter_out="test/fixtures/_longopt/grep--help.txt" gitgrep '(?<!command)'"$cmdstart"'(grep|ls|sed|cd)(\s|$)' \
5761
'invoke grep, ls, sed, and cd through "command", e.g. "command grep"'
5862

5963
gitgrep '(?<!command)'"$cmdstart"'(?:awk|tail)(\s|$)' \
@@ -67,12 +71,12 @@ gitgrep '@\([^()|$]+\)' \
6771

6872
gitgrep '<<<' 'herestrings use temp files, use some other way'
6973

70-
filter_out='^(test/|bash_completion\.sh)' gitgrep ' \[ ' \
74+
filter_out='test/ bash_completion.sh.in' gitgrep ' \[ ' \
7175
'use [[ ]] instead of [ ]'
7276

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

75-
gitgrep "$cmdstart"'((set|shopt)\s+[+-][a-z]+\s+posix\b|(local\s+)?POSIXLY_CORRECT\b)' \
79+
filter_out="test/config/bashrc" gitgrep "$cmdstart"'((set|shopt)\s+[+-][a-z]+\s+posix\b|(local\s+)?POSIXLY_CORRECT\b)' \
7680
'fiddling with posix mode breaks keybindings with some bash versions'
7781

7882
gitgrep '\$\{([^{}\n]|\{.*\})+/([^{}\n]|\{.*\})+/([^{}"\n]|\{.*\})*\$.*\}' \

0 commit comments

Comments
 (0)