spacehub

surshar / claude-code

Claude Code is an agentic coding tool that lives in your terminal, understands your codebase, and helps you code faster by executing routine tasks, explaining complex code, and handling git workflows - all through natural language commands.

Built by Anthropic ยท github.com/anthropics

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