Skip to content

Commit e617d17

Browse files
committed
fix hanging lint xref
1 parent f7df6b1 commit e617d17

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

scripts/lint_xrefs.sh

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,27 +23,44 @@ while IFS=: read -r filepath link; do
2323
status=1
2424
fi
2525
done < <(
26-
pattern='(?!.*@lint-ignore)(?:\[[^]]+\]\([^[:space:]\)]+/[^[:space:]\)]+\)|href="[^"]*/[^"]*"|src="[^"]*/[^"]*")'
26+
# Removed negative lookahead from regex
27+
pattern='(?:\[[^]]+\]\([^[:space:]\)]+/[^[:space:]\)]+\)|href="[^"]*/[^"]*"|src="[^"]*/[^"]*")'
28+
2729
excludes=(
2830
':(exclude,glob)**/.*'
2931
':(exclude,glob)**/*.lock'
3032
':(exclude,glob)**/*.svg'
3133
':(exclude,glob)**/*.xml'
34+
':(exclude,glob)**/*.json' # exclude JSON (e.g., vocab files)
3235
':(exclude,glob)**/*.gradle*'
3336
':(exclude,glob)**/*gradle*'
3437
':(exclude,glob)**/third-party/**'
3538
':(exclude,glob)**/third_party/**'
3639
)
40+
3741
if [ $# -eq 2 ]; then
3842
for filename in $(git diff --name-only --unified=0 "$1...$2"); do
3943
git diff --unified=0 "$1...$2" -- "$filename" "${excludes[@]}" \
4044
| grep -E '^\+' \
4145
| grep -Ev '^\+\+\+' \
46+
| grep -Ev '@lint-ignore' \
4247
| perl -nle 'print for m#'"$pattern"'#g' \
4348
| sed 's|^|'"$filename"':|'
4449
done
4550
else
46-
git --no-pager grep --no-color -I -P -o "$pattern" -- . "${excludes[@]}"
51+
# Dumps all text lines in the repo (ignoring binary + excludes).
52+
# Drops any line with @lint-ignore.
53+
# Extracts only the cross-reference substrings (markdown links, href="…", src="…") and prints them with their filename.
54+
git --no-pager grep --no-color -I -n . "${excludes[@]}" \
55+
| grep -Ev '@lint-ignore' \
56+
| perl -ne '
57+
if (m/^([^:]+):\d+:(.*)$/) {
58+
my ($file, $line) = ($1, $2);
59+
while ($line =~ m#'"$pattern"'#g) {
60+
print "$file:$&\n";
61+
}
62+
}
63+
'
4764
fi \
4865
| grep -Ev 'https?://' \
4966
| sed -E \

0 commit comments

Comments
 (0)