chore(i18n): add checker for t shadowing in svelte files
cx
This commit is contained in:
1 parent
3baa167d54
commit
ff15efde39
2 files changed
+45
No files matched your search
@@ -10,6 +10,7 @@
|
||||
"preview": "vite preview",
|
||||
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
|
||||
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
|
||||
"check:no-t-shadow": "bash ./scripts/check-no-t-shadow.sh",
|
||||
"test": "vitest",
|
||||
"test:run": "vitest run",
|
||||
"tauri": "tauri"
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
||||
SRC_DIR="${ROOT_DIR}/src"
|
||||
|
||||
echo "Checking for forbidden i18n 't' shadowing patterns in .svelte files..."
|
||||
|
||||
had_issues=0
|
||||
|
||||
check_pattern() {
|
||||
local label="$1"
|
||||
local pattern="$2"
|
||||
if rg -n --glob '*.svelte' "${pattern}" "${SRC_DIR}" >/tmp/qbz_t_shadow_check.out 2>/dev/null; then
|
||||
echo
|
||||
echo "Found ${label}:"
|
||||
cat /tmp/qbz_t_shadow_check.out
|
||||
had_issues=1
|
||||
fi
|
||||
}
|
||||
|
||||
# Template loop variable shadowing.
|
||||
check_pattern "template each-loop shadowing (as t)" '\{#each[^\n]* as t\b'
|
||||
|
||||
# Dangerous callbacks in files using $t(...).
|
||||
while IFS= read -r file; do
|
||||
if rg -q '\b(map|forEach|filter|find|some|every|reduce)\(\s*t\s*=>' "${file}"; then
|
||||
echo
|
||||
echo "Found callback shadowing in file using \$t(...): ${file}"
|
||||
rg -n '\b(map|forEach|filter|find|some|every|reduce)\(\s*t\s*=>' "${file}"
|
||||
had_issues=1
|
||||
fi
|
||||
done < <(rg -l --glob '*.svelte' '\$t\(' "${SRC_DIR}")
|
||||
|
||||
# Any $derived expression using variable name t.
|
||||
check_pattern "usage of t inside \$derived" '\$derived\([^)]*\bt\b'
|
||||
|
||||
if [[ "${had_issues}" -ne 0 ]]; then
|
||||
echo
|
||||
echo "check-no-t-shadow: FAIL"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "check-no-t-shadow: OK"
|
||||
Reference in new issue
Block a user