56 lines
1.8 KiB
Python
56 lines
1.8 KiB
Python
#!/usr/bin/env python3
|
|||
|
|
import re
|
||
|
|
import sys
|
||
|
|
|
||
|
|
def validate_js_in_html(filepath):
|
||
|
|
with open(filepath, 'r') as f:
|
||
|
|
content = f.read()
|
||
|
|
|
||
|
|
# Extract all JavaScript code blocks
|
||
|
|
js_pattern = r'<script[^>]*>(.*?)</script>'
|
||
|
|
js_blocks = re.findall(js_pattern, content, re.DOTALL)
|
||
|
|
|
||
|
|
print(f"Found {len(js_blocks)} JavaScript blocks")
|
||
|
|
|
||
|
|
for i, js_code in enumerate(js_blocks):
|
||
|
|
print(f"\n--- Block {i+1} ---")
|
||
|
|
|
||
|
|
# Check for basic syntax issues
|
||
|
|
open_braces = js_code.count('{')
|
||
|
|
close_braces = js_code.count('}')
|
||
|
|
open_parens = js_code.count('(')
|
||
|
|
close_parens = js_code.count(')')
|
||
|
|
|
||
|
|
print(f"Braces: {{{open_braces}}} vs {{{close_braces}}} - {'OK' if open_braces == close_braces else 'MISMATCH'}")
|
||
|
|
print(f"Parens: ({open_parens}) vs ({close_parens}) - {'OK' if open_parens == close_parens else 'MISMATCH'}")
|
||
|
|
|
||
|
|
# Check for common issues
|
||
|
|
issues = []
|
||
|
|
|
||
|
|
# Check for double semicolons
|
||
|
|
if ';;' in js_code:
|
||
|
|
issues.append("Double semicolons found")
|
||
|
|
|
||
|
|
# Check for empty object patterns that might be issues
|
||
|
|
if re.search(r'\{\s*\};\s*\};', js_code):
|
||
|
|
issues.append("Potential double closing braces with semicolons")
|
||
|
|
|
||
|
|
# Check for arrow functions with potential issues
|
||
|
|
arrow_funcs = re.findall(r'=>\s*\{[^}]*\}', js_code)
|
||
|
|
print(f"Arrow functions found: {len(arrow_funcs)}")
|
||
|
|
|
||
|
|
if issues:
|
||
|
|
print("⚠️ Issues found:")
|
||
|
|
for issue in issues:
|
||
|
|
print(f" - {issue}")
|
||
|
|
else:
|
||
|
|
print("✅ No obvious issues found")
|
||
|
|
|
||
|
|
return True
|
||
|
|
|
||
|
|
if __name__ == "__main__":
|
||
|
|
if len(sys.argv) > 1:
|
||
|
|
validate_js_in_html(sys.argv[1])
|
||
|
|
else:
|
||
|
|
validate_js_in_html("apps/web/vue3/index.html")
|