validate-settings.sh 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. #!/bin/bash
  2. # Settings File Validator
  3. # Validates .claude/plugin-name.local.md structure
  4. set -euo pipefail
  5. # Usage
  6. if [ $# -eq 0 ]; then
  7. echo "Usage: $0 <path/to/settings.local.md>"
  8. echo ""
  9. echo "Validates plugin settings file for:"
  10. echo " - File existence and readability"
  11. echo " - YAML frontmatter structure"
  12. echo " - Required --- markers"
  13. echo " - Field format"
  14. echo ""
  15. echo "Example: $0 .claude/my-plugin.local.md"
  16. exit 1
  17. fi
  18. SETTINGS_FILE="$1"
  19. echo "🔍 Validating settings file: $SETTINGS_FILE"
  20. echo ""
  21. # Check 1: File exists
  22. if [ ! -f "$SETTINGS_FILE" ]; then
  23. echo "❌ File not found: $SETTINGS_FILE"
  24. exit 1
  25. fi
  26. echo "✅ File exists"
  27. # Check 2: File is readable
  28. if [ ! -r "$SETTINGS_FILE" ]; then
  29. echo "❌ File is not readable"
  30. exit 1
  31. fi
  32. echo "✅ File is readable"
  33. # Check 3: Has frontmatter markers
  34. MARKER_COUNT=$(grep -c '^---$' "$SETTINGS_FILE" 2>/dev/null || echo "0")
  35. if [ "$MARKER_COUNT" -lt 2 ]; then
  36. echo "❌ Invalid frontmatter: found $MARKER_COUNT '---' markers (need at least 2)"
  37. echo " Expected format:"
  38. echo " ---"
  39. echo " field: value"
  40. echo " ---"
  41. echo " Content..."
  42. exit 1
  43. fi
  44. echo "✅ Frontmatter markers present"
  45. # Check 4: Extract and validate frontmatter
  46. FRONTMATTER=$(sed -n '/^---$/,/^---$/{ /^---$/d; p; }' "$SETTINGS_FILE")
  47. if [ -z "$FRONTMATTER" ]; then
  48. echo "❌ Empty frontmatter (nothing between --- markers)"
  49. exit 1
  50. fi
  51. echo "✅ Frontmatter not empty"
  52. # Check 5: Frontmatter has valid YAML-like structure
  53. if ! echo "$FRONTMATTER" | grep -q ':'; then
  54. echo "⚠️ Warning: Frontmatter has no key:value pairs"
  55. fi
  56. # Check 6: Look for common fields
  57. echo ""
  58. echo "Detected fields:"
  59. echo "$FRONTMATTER" | grep '^[a-z_][a-z0-9_]*:' | while IFS=':' read -r key value; do
  60. echo " - $key: ${value:0:50}"
  61. done
  62. # Check 7: Validate common boolean fields
  63. for field in enabled strict_mode; do
  64. VALUE=$(echo "$FRONTMATTER" | grep "^${field}:" | sed "s/${field}: *//" || true)
  65. if [ -n "$VALUE" ]; then
  66. if [ "$VALUE" != "true" ] && [ "$VALUE" != "false" ]; then
  67. echo "⚠️ Field '$field' should be boolean (true/false), got: $VALUE"
  68. fi
  69. fi
  70. done
  71. # Check 8: Check body exists
  72. BODY=$(awk '/^---$/{i++; next} i>=2' "$SETTINGS_FILE")
  73. echo ""
  74. if [ -n "$BODY" ]; then
  75. BODY_LINES=$(echo "$BODY" | wc -l | tr -d ' ')
  76. echo "✅ Markdown body present ($BODY_LINES lines)"
  77. else
  78. echo "⚠️ No markdown body (frontmatter only)"
  79. fi
  80. echo ""
  81. echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
  82. echo "✅ Settings file structure is valid"
  83. echo ""
  84. echo "Reminder: Changes to this file require restarting Claude Code"
  85. exit 0