From 7aeff60ca498d185480a84ce141e82bc49a1eb08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Banaszewski?= Date: Tue, 21 Apr 2026 14:20:24 +0000 Subject: [PATCH 1/2] feat: add option to exclude prefixes from scripts/check_emdash.sh --- scripts/check_emdash.sh | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/scripts/check_emdash.sh b/scripts/check_emdash.sh index c41bf34111c1a..e56c82054cdb9 100755 --- a/scripts/check_emdash.sh +++ b/scripts/check_emdash.sh @@ -20,9 +20,20 @@ emdash=$'\xE2\x80\x94' endash=$'\xE2\x80\x93' pattern="${emdash}|${endash}" +# Path prefixes excluded from the check. These contain captured upstream +# content where emdash/endash come from the provider. +exclude_prefixes=( + "aibridge/fixtures/" +) + scan_all_files() { + local pathspecs=() + local prefix + for prefix in "${exclude_prefixes[@]}"; do + pathspecs+=(":(exclude)${prefix}**") + done local output - output=$(git ls-files -z | xargs -0 grep -IEn "$pattern" 2>/dev/null || true) + output=$(git ls-files -z -- "${pathspecs[@]}" | xargs -0 grep -IEn "$pattern" 2>/dev/null || true) if [[ -n "$output" ]]; then echo "$output" found=1 @@ -72,9 +83,17 @@ else # Parse the diff to check only added lines for emdash/endash. current_file="" current_line=0 + file_excluded=0 while IFS= read -r diff_line; do if [[ "$diff_line" =~ ^\+\+\+\ b/(.*) ]]; then current_file="${BASH_REMATCH[1]}" + file_excluded=0 + for prefix in "${exclude_prefixes[@]}"; do + if [[ "$current_file" == "$prefix"* ]]; then + file_excluded=1 + break + fi + done fi # Anchored to hunk header structure to avoid matching # digits from trailing function context. @@ -83,7 +102,7 @@ else continue fi if [[ "$diff_line" =~ ^\+ ]] && [[ ! "$diff_line" =~ ^\+\+\+\ [ab/] ]]; then - if echo "$diff_line" | grep -Eq "$pattern"; then + if [[ "$file_excluded" -eq 0 ]] && echo "$diff_line" | grep -Eq "$pattern"; then echo "${current_file}:${current_line}:${diff_line:1}" found=1 fi From 58083df46db8bc665c9cba3c2b19f1587df442a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Banaszewski?= Date: Tue, 21 Apr 2026 17:37:48 +0000 Subject: [PATCH 2/2] review 1: reused exclude pattern in both ls-files and diff comparison --- scripts/check_emdash.sh | 26 ++++++-------------------- 1 file changed, 6 insertions(+), 20 deletions(-) diff --git a/scripts/check_emdash.sh b/scripts/check_emdash.sh index e56c82054cdb9..4001ac24087dd 100755 --- a/scripts/check_emdash.sh +++ b/scripts/check_emdash.sh @@ -20,20 +20,14 @@ emdash=$'\xE2\x80\x94' endash=$'\xE2\x80\x93' pattern="${emdash}|${endash}" -# Path prefixes excluded from the check. These contain captured upstream -# content where emdash/endash come from the provider. -exclude_prefixes=( - "aibridge/fixtures/" +# Git exclude_pathspecs excluded from the check. Used in both ls-files and diff comparison. +exclude_pathspecs=( + ":(exclude)aibridge/fixtures/**/*.txtar" ) scan_all_files() { - local pathspecs=() - local prefix - for prefix in "${exclude_prefixes[@]}"; do - pathspecs+=(":(exclude)${prefix}**") - done local output - output=$(git ls-files -z -- "${pathspecs[@]}" | xargs -0 grep -IEn "$pattern" 2>/dev/null || true) + output=$(git ls-files -z -- "${exclude_pathspecs[@]}" | xargs -0 grep -IEn "$pattern" 2>/dev/null || true) if [[ -n "$output" ]]; then echo "$output" found=1 @@ -69,7 +63,7 @@ else fi found=0 - if ! diff_output=$(git diff "$base" -U0 -- . 2>&1); then + if ! diff_output=$(git diff "$base" -U0 -- . "${exclude_pathspecs[@]}" 2>&1); then echo "ERROR: git diff against $base failed:" echo "$diff_output" exit 1 @@ -83,17 +77,9 @@ else # Parse the diff to check only added lines for emdash/endash. current_file="" current_line=0 - file_excluded=0 while IFS= read -r diff_line; do if [[ "$diff_line" =~ ^\+\+\+\ b/(.*) ]]; then current_file="${BASH_REMATCH[1]}" - file_excluded=0 - for prefix in "${exclude_prefixes[@]}"; do - if [[ "$current_file" == "$prefix"* ]]; then - file_excluded=1 - break - fi - done fi # Anchored to hunk header structure to avoid matching # digits from trailing function context. @@ -102,7 +88,7 @@ else continue fi if [[ "$diff_line" =~ ^\+ ]] && [[ ! "$diff_line" =~ ^\+\+\+\ [ab/] ]]; then - if [[ "$file_excluded" -eq 0 ]] && echo "$diff_line" | grep -Eq "$pattern"; then + if echo "$diff_line" | grep -Eq "$pattern"; then echo "${current_file}:${current_line}:${diff_line:1}" found=1 fi