#!/bin/bash # # DSS Code Quality Verification Script # Runs automated checks to ensure code quality standards before commits # # Enforces standards from: .knowledge/dss-coding-standards.json # # Thresholds: # - Inline event handlers: 0 (ZERO TOLERANCE) # - Inline styles: ≤10 (dynamic values only) # - Console statements: ≤10 (use logger utility) # - File size: ≤100KB # - Syntax errors: 0 (ZERO TOLERANCE) # # Only checks files that are staged for commit (git diff --cached) # set -e echo "🔍 Running DSS Code Quality Checks..." echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" # Colors for output RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' NC='\033[0m' # No Color # Track if any checks fail FAILED=0 # Get list of staged JS files in admin-ui/js/ and server/src/ STAGED_JS_FILES=$(git diff --cached --name-only --diff-filter=ACMR | grep -E '(admin-ui/js/.*\.js|server/src/.*\.js)$' || true) # If no JS files are staged, skip quality checks if [ -z "$STAGED_JS_FILES" ]; then echo "â„šī¸ No JavaScript files in commit, skipping quality checks." exit 0 fi echo "📄 Checking $(echo "$STAGED_JS_FILES" | wc -w) staged JavaScript files..." # 1. Check for inline event handlers (onmouseover, onclick, etc.) # ZERO TOLERANCE per DSS coding standards echo "" echo "📋 Checking for inline event handlers..." INLINE_EVENTS=$(echo "$STAGED_JS_FILES" | xargs grep -n "on\(click\|mouseover\|mouseout\|keydown\|keyup\|load\|submit\)=" 2>/dev/null || true) if [ -n "$INLINE_EVENTS" ]; then echo "$INLINE_EVENTS" echo -e "${RED}✗ CRITICAL: Inline event handlers found in staged files (ZERO TOLERANCE)${NC}" echo -e "${RED} Use event delegation with addEventListener instead${NC}" echo -e "${RED} See: .knowledge/dss-coding-standards.json > event_handling${NC}" FAILED=1 fi # 2. Check for excessive inline styles # Threshold: ≤10 per DSS coding standards (exceptions for dynamic values only) echo "" echo "🎨 Checking for excessive inline styles..." INLINE_STYLE_COUNT=$(echo "$STAGED_JS_FILES" | xargs grep -n 'style="' 2>/dev/null | wc -l) if [ "$INLINE_STYLE_COUNT" -gt 10 ]; then echo -e "${RED}✗ Found $INLINE_STYLE_COUNT inline style attributes in staged files (threshold: ≤10)${NC}" echo -e "${RED} Extract styles to Shadow DOM