Audit: catch hand-rolled link resolution (hardcoded homepage slug, URL built from a slug); comment filter fix
Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
@@ -41,7 +41,8 @@ report() {
|
||||
|
||||
g() { grep -rnE "$@" 2>/dev/null || true; }
|
||||
# drop matches that sit inside a // or /* comment (keeps http:// URLs)
|
||||
nc() { grep -vE "(^|[^:])//.*$1|/\*.*$1" || true; }
|
||||
# (also a whole-line comment right after grep's "file:line:" prefix)
|
||||
nc() { grep -vE "^[^:]+:[0-9]+:[[:space:]]*(//|/?\*)|(^|[^:])//.*$1|/\*.*$1" || true; }
|
||||
dirs() { for d in "$@"; do [ -d "$d" ] && printf '%s ' "$d"; done; }
|
||||
|
||||
BLOCKS=$(dirs src/blocks)
|
||||
@@ -189,6 +190,15 @@ report WARNING "files that usually duplicate the plugin" "§3 plugin has resolve
|
||||
"$(ls src/lib/pages.ts src/lib/locales.ts 2>/dev/null)"
|
||||
report ERROR "project copy of link fields" "links.md — use buildLinkField / buildLinksField / resolveLinkHref from the plugin" \
|
||||
"$(ls src/fields/link.ts src/lib/links.ts 2>/dev/null; g "from '@/fields/link'|from '@/lib/links'" src --include=*.ts --include=*.tsx)"
|
||||
# Hand-rolled link resolution under another name (resolveHref, getHref…): the plugin knows the
|
||||
# homepage from Site Settings, adds the locale prefix, drops unsafe URLs and dead links.
|
||||
FRONT=$(dirs src/app src/blocks src/components src/lib src/globals src/collections)
|
||||
if [ -n "$FRONT" ]; then
|
||||
report ERROR "hardcoded homepage slug" "links.md — the homepage comes from Site Settings: resolveLink(link, locale) / getHomeSlug(locale), never a slug name in code" \
|
||||
"$(g "(===|!==|==|!=) *['\"](home|homepage|strona-glowna|glowna|start|index)['\"]|['\"](home|homepage|strona-glowna|glowna|start|index)['\"] *(===|!==|==|!=)" $FRONT --include=*.ts --include=*.tsx | grep -v '/(payload)/' | grep -vE "[Tt]ype *[!=]==? *['\"]home|['\"]home['\"] *[!=]==? *[A-Za-z_.]*[Tt]ype" | nc '=')"
|
||||
report ERROR "URL built from a slug by hand" "links.md — resolveLink / resolveNav (lib/content) or buildLocalizedPath: locale prefix, homepage, unsafe and dead links" \
|
||||
"$(g '`/\$\{[^}]*[Ss]lug|['"'"'"]/['"'"'"] *\+ *[A-Za-z_.?]*[Ss]lug' $FRONT --include=*.ts --include=*.tsx | grep -v '/(payload)/' | nc '[Ss]lug')"
|
||||
fi
|
||||
report ERROR "manual Lexical rendering" "§7 use RenderRichText" \
|
||||
"$(g 'node\.type *===' src --include=*.tsx | nc 'node')"
|
||||
HTML=$(node "$(dirname "$0")/html-check.mjs" src)
|
||||
|
||||
Reference in New Issue
Block a user