-
Notifications
You must be signed in to change notification settings - Fork 394
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: link-check: trim and manage exclusions (#1189)
* link-check: abstract away finder * link-check: add exclude-links-check.sh * link-check: purge unused exclusions * test: add link-check-exclude * link-check: exclude *.test.js also ensure link-check-git-all follows exclusions * link-check: exclude more missing * link-check: final exclude purge
- Loading branch information
Showing
8 changed files
with
43 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#!/usr/bin/env bash | ||
# Checks that `exclude-links.txt` contains only used links. | ||
set -euo pipefail | ||
|
||
source "$(dirname "$0")"/utils.sh | ||
exclude="${CHECK_LINKS_EXCLUDE_LIST:-$(dirname "$0")/exclude-links.txt}" | ||
[ -f "$exclude" ] && exclude="$(cat "$exclude")" | ||
|
||
missing="$( | ||
urlfinder $(git ls-files '*.css' '*.js' '*.jsx' '*.md' '*.tsx' '*.ts' '*.json' ':!redirects-list.json' ':!*.test.js') \ | ||
| sed 's/#.*//g' | sort -u \ | ||
| comm -13 - <(echo "$exclude" | sort -u) | ||
)" | ||
|
||
if [[ -n "$missing" ]]; then | ||
echo "ERROR:Exclusions not found in codebase:" >&2 | ||
echo "$missing" | sed 's/^/ /' >&2 | ||
exit 1 | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#!/usr/bin/env bash | ||
|
||
urlfinder(){ # expects <base_url> <files>... | ||
base_url="$1" | ||
content="$(cat "${@:2}")" # read once (could be file descriptors) | ||
# explicit links not in markdown | ||
echo "$content" | pcregrep -o '(?<!\]\()https?://[^\s<>{}"'"'"'`]+' | ||
# explicit links in markdown | ||
echo "$content" | pcregrep -o '(?<=\])\(https?://[^[\]\s]+\)' | pcregrep -o '\((?:[^)(]*(?R)?)*+\)' | pcregrep -o '(?<=\().*(?=\))' | ||
# relative links in markdown | ||
echo "$content" | sed -nE 's/.*]\((\/[^)[:space:]]+).*/\1/p' | xargs -n1 -II echo ${base_url}I | ||
# relative links in html | ||
echo "$content" | sed -nE 's/.*href=["'"'"'](\/[^"'"'"']+)["'"'"'].*/\1/p' | xargs -n1 -II echo ${base_url}I | ||
} |