Files
2025-11-30 08:33:44 +08:00

50 lines
1.0 KiB
Bash
Executable File
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/bin/bash
# Example validation hook that runs after Write/Edit operations
# This demonstrates how to validate file changes
FILE_PATH="$1"
echo "Validating file: $FILE_PATH"
# Check if file exists
if [ ! -f "$FILE_PATH" ]; then
echo "Warning: File not found: $FILE_PATH"
exit 0
fi
# Get file extension
EXT="${FILE_PATH##*.}"
# Perform basic validation based on file type
case "$EXT" in
json)
echo "Checking JSON syntax..."
if command -v jq &> /dev/null; then
if jq empty "$FILE_PATH" 2>/dev/null; then
echo "✓ JSON validation passed"
else
echo "✗ JSON validation failed"
exit 1
fi
else
echo " jq not installed, skipping JSON validation"
fi
;;
sh)
echo "Checking shell script syntax..."
if bash -n "$FILE_PATH" 2>/dev/null; then
echo "✓ Shell script syntax valid"
else
echo "✗ Shell script syntax error"
exit 1
fi
;;
*)
echo " No specific validation for .$EXT files"
;;
esac
echo "Validation complete"
exit 0