Files
claude-skills/scripts/validate.sh
T
2026-10-19 14:59:33 +02:00

84 lines
2.6 KiB
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env bash
# Prüft alle Skills (oder nur den angegebenen) auf die Regeln aus CONTRIBUTING.md.
# Aufruf: scripts/validate.sh [<skill-name>]
set -euo pipefail
source "$(dirname "$0")/lib.sh"
validate_skill() {
local name="$1" dir="$SKILLS_DIR/$1" fm fm_name desc raw heading
local -a errs=()
if [[ ! -d "$dir" ]]; then
echo " - Ordner skills/$name existiert nicht"
return
fi
mapfile -t errs < <(name_errors "$name")
if [[ ! -f "$dir/SKILL.md" ]]; then
errs+=("SKILL.md fehlt")
else
if [[ "$(head -c3 "$dir/SKILL.md" | od -An -tx1 | tr -d ' \n')" == "efbbbf" ]]; then
errs+=("SKILL.md beginnt mit einem BOM – als UTF-8 ohne BOM speichern")
elif ! fm="$(frontmatter "$dir/SKILL.md")"; then
errs+=("SKILL.md hat kein Frontmatter (erste Zeile '---', danach schließendes '---')")
else
if ! fm_name="$(fm_value "$fm" name)" || [[ -z "$fm_name" ]]; then
errs+=("Frontmatter: 'name' fehlt")
elif [[ "$fm_name" != "$name" ]]; then
errs+=("Frontmatter: name '$fm_name' passt nicht zum Ordnernamen '$name'")
fi
if ! desc="$(fm_value "$fm" description)" || [[ -z "$desc" ]]; then
errs+=("Frontmatter: 'description' fehlt oder ist leer")
else
(( ${#desc} <= 1024 )) || errs+=("Frontmatter: description ist länger als 1024 Zeichen (${#desc})")
[[ "$desc" == *"<"* || "$desc" == *">"* ]] && errs+=("Frontmatter: description darf keine spitzen Klammern < > enthalten")
raw="$(fm_raw "$fm" description)"
if [[ "$raw" != \"* && "$raw" != \'* && "$raw" == *": "* ]]; then
errs+=("Frontmatter: description enthält ': ' – in Anführungszeichen setzen, sonst ist das YAML ungültig")
fi
fi
fi
fi
if [[ ! -f "$dir/CHANGELOG.md" ]]; then
errs+=("CHANGELOG.md fehlt")
else
heading="$(changelog_heading "$dir")"
if [[ -z "$heading" ]]; then
errs+=("CHANGELOG.md hat keinen Eintrag '## x.y.z (YYYY-MM-DD)'")
elif [[ -z "$(skill_version "$dir")" ]]; then
errs+=("CHANGELOG.md: oberster Eintrag '$heading' hat nicht das Format '## x.y.z (YYYY-MM-DD)'")
fi
fi
local e
for e in "${errs[@]+"${errs[@]}"}"; do echo " - $e"; done
}
if [[ $# -gt 0 && -n "$1" ]]; then
names=("$1")
else
mapfile -t names < <(skill_names)
fi
if [[ ${#names[@]} -eq 0 ]]; then
echo "Keine Skills unter skills/ gefunden."
exit 0
fi
failed=0
for name in "${names[@]}"; do
out="$(validate_skill "$name")"
if [[ -z "$out" ]]; then
echo "OK $name ($(skill_version "$SKILLS_DIR/$name"))"
else
echo "FEHLER $name"
echo "$out"
failed=1
fi
done
exit "$failed"