chore: delete code comments, add ratchet lint and ADRs

Classify every comment as tautology, stale, excuse or decision record.
Tautology/stale/excuse comments are deleted (excuses filed as issues
#196-#236), decisions moved to docs/adr/0001-0034.

- scripts/lint-comments.sh + .comment-baseline: per-file comment count
  may only go down; wired into tests/all.sh
- .claude/skills/delete-comment: repeatable audit workflow
- cargo fmt applied to touched crates

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
johannesandClaude Sonnet 5.5 committed 2026-11-21 13:37:32 +01:00
1 parent 0545702fe0
commit a94632ea3d
131 files changed
+1051 -1746

No files matched your search

+61
View File
@@ -0,0 +1,61 @@
#!/usr/bin/env bash
# Ratchet lint: comments are banned. Each file may hold at most the number of
# comment lines recorded in .comment-baseline; the number can only go down.
# scripts/lint-comments.sh check (CI)
# scripts/lint-comments.sh --update rewrite the baseline from the tree
set -euo pipefail
cd "$(git rev-parse --show-toplevel)"
baseline=.comment-baseline
rust='^[[:space:]]*//|[;{},)][[:space:]]+//[[:space:]]'
rust_ok='^[[:space:]]*// (SAFETY:|rustfmt::|clippy::)'
hash='^[[:space:]]*#'
hash_ok='^[[:space:]]*#(!|[[:space:]]*(shellcheck|yaml-language-server|nolint))'
count() {
case "$1" in
*.rs) grep -E "$rust" "$1" | grep -vEc "$rust_ok" || true ;;
*) grep -E "$hash" "$1" | grep -vEc "$hash_ok" || true ;;
esac
}
current=$(
git ls-files '*.rs' '*.sh' '*.py' '*.nix' '*.yml' '*.yaml' | while read -r f; do
[ -f "$f" ] || continue
n=$(count "$f")
if [ "$n" -gt 0 ]; then echo "$n $f"; fi
done | sort -k2
)
if [ "${1:-}" = "--update" ]; then
printf '%s\n' "$current" | sed '/^$/d' > "$baseline"
echo "baseline written: $(wc -l < "$baseline") files, $(awk '{s+=$1} END {print s+0}' "$baseline") comment lines"
exit 0
fi
touch "$baseline"
fail=0
while read -r n f; do
[ -n "${f:-}" ] || continue
allowed=$(awk -v f="$f" '$2 == f {print $1}' "$baseline")
allowed=${allowed:-0}
if [ "$n" -gt "$allowed" ]; then
echo "FAIL $f: $n comment lines, allowed $allowed. Delete the comment; if it records a decision, write an ADR in docs/adr/."
fail=1
elif [ "$n" -lt "$allowed" ]; then
echo "FAIL $f: $n comment lines, baseline says $allowed. Run scripts/lint-comments.sh --update to lock in the cleanup."
fail=1
fi
done <<< "$current"
while read -r n f; do
[ -n "${f:-}" ] || continue
if ! printf '%s\n' "$current" | awk -v f="$f" '$2 == f {found=1} END {exit !found}'; then
echo "FAIL $f: baseline lists $n comment lines but the file has none. Run scripts/lint-comments.sh --update."
fail=1
fi
done < "$baseline"
[ "$fail" -eq 0 ] && echo "comment lint ok"
exit "$fail"