Skip to content

Commit fe4e775

Browse files
committed
feat: add option to exclude prefixes from scripts/check_emdash.sh
1 parent 8be7bc5 commit fe4e775

1 file changed

Lines changed: 21 additions & 2 deletions

File tree

scripts/check_emdash.sh

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,20 @@ emdash=$'\xE2\x80\x94'
2020
endash=$'\xE2\x80\x93'
2121
pattern="${emdash}|${endash}"
2222

23+
# Path prefixes excluded from the check. These contain captured upstream
24+
# content where emdash/endash come from the provider.
25+
exclude_prefixes=(
26+
"aibridge/fixtures/"
27+
)
28+
2329
scan_all_files() {
30+
local pathspecs=()
31+
local prefix
32+
for prefix in "${exclude_prefixes[@]}"; do
33+
pathspecs+=(":(exclude)${prefix}**")
34+
done
2435
local output
25-
output=$(git ls-files -z | xargs -0 grep -IEn "$pattern" 2>/dev/null || true)
36+
output=$(git ls-files -z -- "${pathspecs[@]}" | xargs -0 grep -IEn "$pattern" 2>/dev/null || true)
2637
if [[ -n "$output" ]]; then
2738
echo "$output"
2839
found=1
@@ -72,9 +83,17 @@ else
7283
# Parse the diff to check only added lines for emdash/endash.
7384
current_file=""
7485
current_line=0
86+
file_excluded=0
7587
while IFS= read -r diff_line; do
7688
if [[ "$diff_line" =~ ^\+\+\+\ b/(.*) ]]; then
7789
current_file="${BASH_REMATCH[1]}"
90+
file_excluded=0
91+
for prefix in "${exclude_prefixes[@]}"; do
92+
if [[ "$current_file" == "$prefix"* ]]; then
93+
file_excluded=1
94+
break
95+
fi
96+
done
7897
fi
7998
# Anchored to hunk header structure to avoid matching
8099
# digits from trailing function context.
@@ -83,7 +102,7 @@ else
83102
continue
84103
fi
85104
if [[ "$diff_line" =~ ^\+ ]] && [[ ! "$diff_line" =~ ^\+\+\+\ [ab/] ]]; then
86-
if echo "$diff_line" | grep -Eq "$pattern"; then
105+
if [[ "$file_excluded" -eq 0 ]] && echo "$diff_line" | grep -Eq "$pattern"; then
87106
echo "${current_file}:${current_line}:${diff_line:1}"
88107
found=1
89108
fi

0 commit comments

Comments
 (0)