-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsyntax-check.sh
More file actions
executable file
·61 lines (50 loc) · 1.58 KB
/
syntax-check.sh
File metadata and controls
executable file
·61 lines (50 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/bin/bash
# syntax-check.sh - Script to check for syntax issues in tutorial code blocks
# Text formatting
GREEN="\033[0;32m"
RED="\033[0;31m"
YELLOW="\033[0;33m"
RESET="\033[0m"
# Counter variables
ERRORS_FOUND=0
# Directory containing tutorials
TUTORIALS_DIR="./tutorials"
echo "XID Tutorial Syntax Checker"
echo "================================="
# Check all markdown files in tutorials directory
for tutorial in "$TUTORIALS_DIR"/*.md; do
# Skip README
if [[ "$(basename "$tutorial")" == "README.md" ]]; then
continue
fi
echo -e "\nChecking $(basename "$tutorial")..."
# Extract all code blocks within sh fences
TMP_FILE=$(mktemp)
awk '/^```sh/,/^```/ { if (!/^```/) print }' "$tutorial" > "$TMP_FILE"
# Check for missing $ in variable references
MISSING_DOLLARS=$(grep -n "[A-Za-z_][A-Za-z0-9_]*\$(" "$TMP_FILE" 2>/dev/null || true)
if [ -n "$MISSING_DOLLARS" ]; then
echo -e "${RED}Found missing \$ in variable references:${RESET}"
echo "$MISSING_DOLLARS"
ERRORS_FOUND=$((ERRORS_FOUND + 1))
fi
# Check for basic bash syntax
if ! bash -n "$TMP_FILE" 2>/dev/null; then
echo -e "${RED}Found bash syntax errors:${RESET}"
bash -n "$TMP_FILE" 2>&1 | head -5
ERRORS_FOUND=$((ERRORS_FOUND + 1))
else
echo -e "${GREEN}✓ No syntax errors found${RESET}"
fi
# Clean up
rm "$TMP_FILE"
done
# Print summary
echo -e "\n================================="
if [ $ERRORS_FOUND -eq 0 ]; then
echo -e "${GREEN}✓ All tutorials passed syntax check${RESET}"
exit 0
else
echo -e "${RED}× Found $ERRORS_FOUND syntax issues${RESET}"
exit 1
fi