testsAndMisc/linux_configuration/utils/lib/study_gen_docs.sh
Krzysztof kuhy Rudnicki 4f2b0ccdf7 Dissolve linux_configuration/scripts/ and single_use/
Two levels of pure taxonomy carrying no information, and a 2-directory
cap leaves no room for them. Categories now sit directly under
linux_configuration/: features, fixes, utils, misc, fresh-install,
installers, diagnostics, gaming, boot_recovery, periodic_background, lib,
meta, tests. A script's own lib/ and tests/ are exempt from the cap, so
those stay put.

Depth violations 248 -> 139; roughly 40 of the remainder are inside
digital_wellbeing and hosts, deferred until the guard-lib repoint.

The moves are the easy half. What breaks is every path that counted
levels, and three classes of it had to be found by resolving paths rather
than reading diffs:

  - 52 relative `source` lines for lib/common.sh and lib/android.sh. The
    correct prefix differs per file: 40 were ../../ and 12 were ../../../,
    so a blanket replace would have fixed one set and broken the other.
  - REPO_ROOT in 7 fixes/lib/tests harnesses and setup_syncyomi_guard.sh,
    each walking up four levels from a directory now two levels shallower.
    This caused a real regression -- the fixes suite went red with
    "log_warn: command not found" -- caught by running it and comparing
    against the pre-move baseline worktree.
  - conftest.py's sys.path entries, which took the pytest gate down with
    14 collection errors, and the `# shellcheck source=` directives, which
    took shellcheck down with SC1091.

16 symlinks in $HOME broke, including the entire i3blocks bar. All
repointed, and cpu_monitor/memory/disk/time/volume were run to confirm
they emit real output rather than merely resolving.

Verified: 1798 tests pass at 100% coverage, 8 of 9 lib/tests suites pass
(the ninth needs the coverage jail, identically at baseline), pre-commit
is clean, and the two untracked secret configs are still ignored after
their gitignore paths changed.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PJrqKERAo5QUeEHWS5Asgp
2026-08-23 18:53:30 +02:00

239 lines
7.2 KiB
Bash
Executable File

#!/usr/bin/env bash
# lib/study_gen_docs.sh — write documentation_links.md, the markdown index of
# every top keyword, function call and import the analysis found.
# Write the markdown documentation-link file covering every top keyword,
# function call and import in the analysis.
generate_doc_links() {
#==============================================================================
# Generate Documentation Links (Markdown)
#==============================================================================
echo -e "${YELLOW}Generating documentation links...${NC}"
cat >"$DOCS_FILE" <<'EOF'
# Documentation Links for Code Review
This document contains links to official documentation for the most commonly used
functions, keywords, and patterns found in the analyzed codebase.
**Note:** Items are grouped by language for accurate documentation links.
---
EOF
# Check for per-language files
PER_LANG_DIR="$RESULTS_DIR/per_language"
if [ -d "$PER_LANG_DIR" ]; then
echo -e "${GREEN}Using per-language analysis files${NC}"
# Map internal lang names to doc function names
lang_to_doc() {
case "$1" in
c_cpp) echo "cpp" ;;
javascript) echo "js" ;;
typescript) echo "ts" ;;
shell) echo "bash" ;;
*) echo "$1" ;;
esac
}
# Process keywords by language
{
echo "## Language Keywords"
echo ""
} >>"$DOCS_FILE"
for keyword_file in "$PER_LANG_DIR"/keywords_*.txt; do
[ ! -f "$keyword_file" ] && continue
[ ! -s "$keyword_file" ] && continue
# Extract language name from filename
lang=$(basename "$keyword_file" | sed 's/keywords_//; s/\.txt//')
doc_lang=$(lang_to_doc "$lang")
# Format language name for display
case "$lang" in
c_cpp) display_lang="C/C++" ;;
javascript) display_lang="JavaScript" ;;
typescript) display_lang="TypeScript" ;;
python) display_lang="Python" ;;
rust) display_lang="Rust" ;;
go) display_lang="Go" ;;
ruby) display_lang="Ruby" ;;
java) display_lang="Java" ;;
shell) display_lang="Shell/Bash" ;;
*) display_lang="$lang" ;;
esac
{
echo "### $display_lang Keywords"
echo ""
echo "| Keyword | Count | Documentation |"
echo "|---------|-------|---------------|"
} >>"$DOCS_FILE"
{ grep -v '^#' "$keyword_file" || true; } | head -n "$TOP_N" | while read -r count term; do
[ -z "$term" ] && continue
url=$(get_doc_url "$term" "$doc_lang")
echo "| \`$term\` | $count | [docs]($url) |" >>"$DOCS_FILE"
done
echo "" >>"$DOCS_FILE"
done
# Process functions by language
{
echo "## Function/Method Calls"
echo ""
} >>"$DOCS_FILE"
for func_file in "$PER_LANG_DIR"/functions_*.txt; do
[ ! -f "$func_file" ] && continue
[ ! -s "$func_file" ] && continue
lang=$(basename "$func_file" | sed 's/functions_//; s/\.txt//')
doc_lang=$(lang_to_doc "$lang")
case "$lang" in
c_cpp) display_lang="C/C++" ;;
javascript) display_lang="JavaScript" ;;
typescript) display_lang="TypeScript" ;;
python) display_lang="Python" ;;
rust) display_lang="Rust" ;;
go) display_lang="Go" ;;
ruby) display_lang="Ruby" ;;
java) display_lang="Java" ;;
shell) display_lang="Shell/Bash" ;;
*) display_lang="$lang" ;;
esac
{
echo "### $display_lang Functions"
echo ""
echo "| Function | Count | Documentation |"
echo "|----------|-------|---------------|"
} >>"$DOCS_FILE"
{ grep -v '^#' "$func_file" || true; } | head -n "$TOP_N" | while read -r count term; do
[ -z "$term" ] && continue
[[ $term =~ ^(if|for|while|switch|catch|elif)$ ]] && continue
url=$(get_doc_url "$term" "$doc_lang")
echo "| \`$term()\` | $count | [docs]($url) |" >>"$DOCS_FILE"
done
echo "" >>"$DOCS_FILE"
done
# Process imports by language
{
echo "## Imports/Includes"
echo ""
} >>"$DOCS_FILE"
for import_file in "$PER_LANG_DIR"/imports_*.txt; do
[ ! -f "$import_file" ] && continue
[ ! -s "$import_file" ] && continue
lang=$(basename "$import_file" | sed 's/imports_//; s/\.txt//')
doc_lang=$(lang_to_doc "$lang")
case "$lang" in
c_cpp) display_lang="C/C++ (#include)" ;;
javascript) display_lang="JavaScript (import/require)" ;;
typescript) display_lang="TypeScript (import)" ;;
python) display_lang="Python (import/from)" ;;
rust) display_lang="Rust (use)" ;;
go) display_lang="Go (import)" ;;
ruby) display_lang="Ruby (require)" ;;
java) display_lang="Java (import)" ;;
shell) display_lang="Shell (source)" ;;
*) display_lang="$lang" ;;
esac
{
echo "### $display_lang"
echo ""
echo "| Import | Count | Documentation |"
echo "|--------|-------|---------------|"
} >>"$DOCS_FILE"
{ grep -v '^#' "$import_file" || true; } | head -n "$TOP_N" | while read -r count import; do
[ -z "$import" ] && continue
# For offline lookup, pass the full import line for better context
url=$(get_doc_url "" "$doc_lang" "$import")
if [ -z "$url" ] || [[ $url == *"search.html"* ]]; then
# Fallback: extract module and try again
module=$(echo "$import" | sed -E 's/.*[<"]([^">]+)[">].*/\1/' | sed 's|.*/||' | sed 's/\..*$//')
url=$(get_doc_url "$module" "$doc_lang")
fi
import_escaped="${import//|/\\|}"
echo "| \`$import_escaped\` | $count | [docs]($url) |" >>"$DOCS_FILE"
done
echo "" >>"$DOCS_FILE"
done
else
# Fallback to combined files (old behavior)
echo -e "${YELLOW}No per-language files found, using combined analysis${NC}"
if [ -f "$RESULTS_DIR/grep_keywords.txt" ]; then
{
echo "## Language Keywords"
echo ""
echo "| Keyword | Count | Documentation |"
echo "|---------|-------|---------------|"
} >>"$DOCS_FILE"
{ grep -v '^#' "$RESULTS_DIR/grep_keywords.txt" || true; } | head -n "$TOP_N" | while read -r count term; do
[ -z "$term" ] && continue
url=$(get_doc_url "$term" "$PRIMARY_LANG")
echo "| \`$term\` | $count | [docs]($url) |" >>"$DOCS_FILE"
done
echo "" >>"$DOCS_FILE"
fi
if [ -f "$RESULTS_DIR/grep_function_calls.txt" ]; then
{
echo "## Function/Method Calls"
echo ""
echo "| Function | Count | Documentation |"
echo "|----------|-------|---------------|"
} >>"$DOCS_FILE"
{ grep -v '^#' "$RESULTS_DIR/grep_function_calls.txt" || true; } | head -n "$TOP_N" | while read -r count term; do
[ -z "$term" ] && continue
[[ $term =~ ^(if|for|while|switch|catch)$ ]] && continue
url=$(get_doc_url "$term" "$PRIMARY_LANG")
echo "| \`$term()\` | $count | [docs]($url) |" >>"$DOCS_FILE"
done
echo "" >>"$DOCS_FILE"
fi
if [ -f "$RESULTS_DIR/grep_imports.txt" ]; then
{
echo "## Imports/Includes"
echo ""
echo "| Import | Count | Documentation |"
echo "|--------|-------|---------------|"
} >>"$DOCS_FILE"
{ grep -v '^#' "$RESULTS_DIR/grep_imports.txt" || true; } | head -n "$TOP_N" | while read -r count import; do
[ -z "$import" ] && continue
module=$(echo "$import" | sed -E 's/.*[<"]([^">]+)[">].*/\1/' | sed 's|.*/||' | sed 's/\..*$//')
url=$(get_doc_url "$module" "$PRIMARY_LANG")
import_escaped="${import//|/\\|}"
echo "| \`$import_escaped\` | $count | [docs]($url) |" >>"$DOCS_FILE"
done
echo "" >>"$DOCS_FILE"
fi
fi
{
echo ""
echo "---"
echo "*Generated by analyze_repo.sh + generate_study_materials.sh*"
} >>"$DOCS_FILE"
echo -e "${GREEN}Created: $DOCS_FILE${NC}"
}