#!/usr/bin/env bash # ============================================================================= # lib/lint.sh # Validation logic for Knowledge Genome files. # ============================================================================= # Validates YAML frontmatter and mandatory fields lint_markdown_file() { local file="$1" local genome_name="$2" local errors=0 # 1. Check Frontmatter delimiters if [[ $(head -n 1 "$file") != "---" ]]; then warn "Missing frontmatter start (---) in: $file" errors=$((errors + 1)) fi # 2. Check mandatory fields local mandatory_fields=("title:" "type:" "domain:") for field in "${mandatory_fields[@]}"; do if ! grep -q "^${field}" "$file"; then warn "Missing mandatory field '${field}' in: $file" errors=$((errors + 1)) fi done # 3. Check if domain matches the genome name if grep -q "^domain:" "$file" && ! grep -q "^domain: ${genome_name}" "$file"; then warn "Domain mismatch in $file (expected ${genome_name})" errors=$((errors + 1)) fi return $errors } # Ensures files in private/ directories have the 'private: true' flag check_privacy_consistency() { local file="$1" local errors=0 if [[ "$file" == *"/private/"* ]]; then if ! grep -q "^private: true" "$file"; then error "Privacy Leak: $file is in a private folder but lacks 'private: true' metadata." errors=$((errors + 1)) fi else if grep -q "^private: true" "$file"; then warn "Metadata Mismatch: $file is marked private but located in a public directory." # We count this as a warning unless you want to force strict isolation fi fi return $errors } # Basic check for internal wiki-links [[target]] check_broken_links() { local file="$1" local base_dir base_dir=$(dirname "$file") # Extract links, stripping aliases: [[Link|Alias]] -> Link local links links=$(grep -oP '\[\[\K[^\]]+' "$file" | cut -d'|' -f1) for link in $links; do local target="$link" [[ "$target" != *.md ]] && target="${target}.md" # Simple relative check if [[ ! -f "${base_dir}/${target}" && ! -f "${base_dir}/../${target}" ]]; then # Only a warning as links might point to other genomes or deep structures warn "Potential broken link: [[$link]] in $file" fi done }