Skip to content

Commit cda554c

Browse files
authored
Provide list of files to link linters if desired (#10556)
1 parent c991de4 commit cda554c

File tree

2 files changed

+37
-26
lines changed

2 files changed

+37
-26
lines changed

scripts/lint_urls.sh

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ running_jobs() {
1818
}
1919

2020
while IFS=: read -r filepath url; do
21-
fpath="$filepath"
2221
(
2322
code=$(curl -k -gsLm30 --retry 3 --retry-delay 3 --retry-connrefused -o /dev/null -w "%{http_code}" -I "$url") || code=000
2423
if [ "$code" -lt 200 ] || [ "$code" -ge 400 ]; then
@@ -47,30 +46,35 @@ while IFS=: read -r filepath url; do
4746
fi
4847
fi
4948
if [ "$code" -lt 200 ] || [ "$code" -ge 400 ]; then
50-
printf "${red}%s${reset} ${yellow}%s${reset} %s\n" "$code" "$url" "$fpath" >&2
49+
printf "${red}%s${reset} ${yellow}%s${reset} %s\n" "$code" "$url" "$filepath" >&2
5150
exit 1
5251
else
53-
printf "${green}%s${reset} ${cyan}%s${reset} %s\n" "$code" "$url" "$fpath"
52+
printf "${green}%s${reset} ${cyan}%s${reset} %s\n" "$code" "$url" "$filepath"
5453
exit 0
5554
fi
5655
) &
5756
pids+=($!)
5857
while [ "$(running_jobs)" -ge "$max_jobs" ]; do
5958
sleep 1
6059
done
61-
done < <(
62-
git --no-pager grep --no-color -I -P -o \
63-
'(?!.*@lint-ignore)(?<!git\+)(?<!\$\{)https?://(?![^\s<>\")]*[<>\{\}\$])[^[:space:]<>\")\[\]\(\\]+' \
64-
-- '*' \
65-
':(exclude).*' \
66-
':(exclude,glob)**/.*' \
67-
':(exclude,glob)**/*.lock' \
68-
':(exclude,glob)**/*.svg' \
69-
':(exclude,glob)**/*.xml' \
70-
':(exclude,glob)**/*.gradle*' \
71-
':(exclude,glob)**/*gradle*' \
72-
':(exclude,glob)**/third-party/**' \
73-
':(exclude,glob)**/third_party/**' \
60+
done < <(
61+
pattern='(?!.*@lint-ignore)(?<!git\+)(?<!\$\{)https?://(?![^\s<>\")]*[<>\{\}\$])[^[:space:]<>")\[\]\\]+'
62+
excludes=(
63+
':(exclude,glob)**/.*'
64+
':(exclude,glob)**/*.lock'
65+
':(exclude,glob)**/*.svg'
66+
':(exclude,glob)**/*.xml'
67+
':(exclude,glob)**/*.gradle*'
68+
':(exclude,glob)**/*gradle*'
69+
':(exclude,glob)**/third-party/**'
70+
':(exclude,glob)**/third_party/**'
71+
)
72+
if [ $# -gt 0 ]; then
73+
paths=("$@")
74+
else
75+
paths=('*')
76+
fi
77+
git --no-pager grep --no-color -I -P -o "$pattern" -- "${paths[@]}" "${excludes[@]}" \
7478
| sed -E 's/[^/[:alnum:]]+$//' \
7579
| grep -Ev '://(0\.0\.0\.0|127\.0\.0\.1|localhost)([:/])' \
7680
| grep -Ev 'fwdproxy:8080' \

scripts/lint_xrefs.sh

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,23 @@ while IFS=: read -r filepath link; do
2323
status=1
2424
fi
2525
done < <(
26-
git --no-pager grep --no-color -I -P -o \
27-
'(?!.*@lint-ignore)(?:\[[^]]+\]\([^[:space:])]*/[^[:space:])]*\)|href="[^"]*/[^"]*"|src="[^"]*/[^"]*")' \
28-
-- '*' \
29-
':(exclude).*' \
30-
':(exclude)**/.*' \
31-
':(exclude)**/*.lock' \
32-
':(exclude)**/*.svg' \
33-
':(exclude)**/*.xml' \
34-
':(exclude,glob)**/third-party/**' \
35-
':(exclude,glob)**/third_party/**' \
26+
pattern='(?!.*@lint-ignore)(?:\[[^]]+\]\([^[:space:]\)]+/[^[:space:]\)]+\)|href="[^"]*/[^"]*"|src="[^"]*/[^"]*")'
27+
excludes=(
28+
':(exclude,glob)**/.*'
29+
':(exclude,glob)**/*.lock'
30+
':(exclude,glob)**/*.svg'
31+
':(exclude,glob)**/*.xml'
32+
':(exclude,glob)**/*.gradle*'
33+
':(exclude,glob)**/*gradle*'
34+
':(exclude,glob)**/third-party/**'
35+
':(exclude,glob)**/third_party/**'
36+
)
37+
if [ $# -gt 0 ]; then
38+
paths=("$@")
39+
else
40+
paths=('*')
41+
fi
42+
git --no-pager grep --no-color -I -P -o "$pattern" -- "${paths[@]}" "${excludes[@]}" \
3643
| grep -Ev 'https?://' \
3744
| sed -E \
3845
-e 's#([^:]+):\[[^]]+\]\(([^)]+)\)#\1:\2#' \

0 commit comments

Comments
 (0)