From 3fbb9a18372f2b6a675dd6c039ba52be76f3eeb4 Mon Sep 17 00:00:00 2001 From: TheSiahxyz <164138827+TheSiahxyz@users.noreply.github.com> Date: Fri, 16 Jan 2026 08:30:14 +0900 Subject: updates --- ui/shadcn/.claude/hooks/validate-components.sh | 131 +++++++++++++++++++++++++ 1 file changed, 131 insertions(+) create mode 100755 ui/shadcn/.claude/hooks/validate-components.sh (limited to 'ui/shadcn/.claude/hooks/validate-components.sh') diff --git a/ui/shadcn/.claude/hooks/validate-components.sh b/ui/shadcn/.claude/hooks/validate-components.sh new file mode 100755 index 0000000..190bcf6 --- /dev/null +++ b/ui/shadcn/.claude/hooks/validate-components.sh @@ -0,0 +1,131 @@ +#!/bin/bash + +# Validate shadcn/ui component structure before changes +# This hook runs before Write/Edit/MultiEdit operations + +# Colors for output +RED='\033[0;31m' +YELLOW='\033[1;33m' +GREEN='\033[0;32m' +NC='\033[0m' # No Color + +# Read tool input from stdin +TOOL_INPUT=$(cat) +TOOL_NAME=$(echo "$TOOL_INPUT" | jq -r '.tool_name // empty') +FILE_PATH=$(echo "$TOOL_INPUT" | jq -r '.tool_input.file_path // empty') + +# Only validate component files +if [[ ! "$FILE_PATH" =~ components/ui/.*\.tsx$ ]] && [[ ! "$FILE_PATH" =~ src/components/ui/.*\.tsx$ ]]; then + echo "$TOOL_INPUT" + exit 0 +fi + +# Extract component name from file path +COMPONENT_NAME=$(basename "$FILE_PATH" .tsx) + +# Validation flags +HAS_ERRORS=0 +WARNINGS="" + +# Function to log warnings +log_warning() { + WARNINGS="${WARNINGS}⚠️ $1\n" +} + +# Function to log errors +log_error() { + echo -e "${RED}❌ Component Validation Error: $1${NC}" >&2 + HAS_ERRORS=1 +} + +# Check if this is a Write operation for a new file +if [ "$TOOL_NAME" = "Write" ] && [ ! -f "$FILE_PATH" ]; then + # New component file - check for required patterns in content + CONTENT=$(echo "$TOOL_INPUT" | jq -r '.tool_input.content // empty') + + # Check for forwardRef pattern + if [[ ! "$CONTENT" =~ "React.forwardRef" ]] && [[ ! "$CONTENT" =~ "forwardRef" ]]; then + log_warning "New component should use React.forwardRef for ref forwarding" + fi + + # Check for displayName + if [[ ! "$CONTENT" =~ "displayName" ]]; then + log_warning "Component should have displayName for debugging" + fi + + # Check for TypeScript types + if [[ ! "$CONTENT" =~ "interface.*Props" ]] && [[ ! "$CONTENT" =~ "type.*Props" ]]; then + log_warning "Component should have TypeScript prop types defined" + fi + + # Check for cn utility usage + if [[ "$CONTENT" =~ "className" ]] && [[ ! "$CONTENT" =~ "cn(" ]]; then + log_warning "Consider using cn() utility for className merging" + fi + + # Check for accessibility attributes in interactive components + if [[ "$CONTENT" =~ "&2 + echo -e "$WARNINGS" >&2 +fi + +# Pass through the original input +echo "$TOOL_INPUT" +exit 0 \ No newline at end of file -- cgit v1.2.3