-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck_css_errors.py
More file actions
73 lines (59 loc) · 2.17 KB
/
check_css_errors.py
File metadata and controls
73 lines (59 loc) · 2.17 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
62
63
64
65
66
67
68
69
70
71
72
73
#!/usr/bin/env python3
import os
import re
from pathlib import Path
def check_css_file(filepath):
"""Check a CSS file for syntax errors"""
with open(filepath, 'r', encoding='utf-8', errors='ignore') as f:
content = f.read()
errors = []
lines = content.split('\n')
# Count braces
open_braces = content.count('{')
close_braces = content.count('}')
if open_braces != close_braces:
errors.append(f"Brace mismatch: {open_braces} opening, {close_braces} closing")
# Check for duplicate selectors
selectors = re.findall(r'^[^{]*(?={)', content, re.MULTILINE)
selector_dict = {}
for selector in selectors:
selector = selector.strip()
if selector in selector_dict:
selector_dict[selector] += 1
else:
selector_dict[selector] = 1
for selector, count in selector_dict.items():
if count > 1 and selector: # Multiple definitions of same selector
errors.append(f"Duplicate selector: '{selector}' appears {count} times")
# Check for unclosed blocks
in_rule = False
brace_level = 0
for i, line in enumerate(lines, 1):
brace_level += line.count('{') - line.count('}')
if brace_level < 0:
errors.append(f"Line {i}: More closing braces than opening")
brace_level = 0
# Check for common issues
if '}}' in content:
errors.append("Found '}}' - possible extra closing brace")
if '{ ' in content or '{ ' in content:
errors.append("Empty or malformed CSS rule")
return errors
# Check all CSS files
css_dir = Path('frontend/src')
css_files = list(css_dir.glob('**/*.css'))
print(f"Checking {len(css_files)} CSS files...\n")
all_errors = {}
for css_file in sorted(css_files):
errors = check_css_file(str(css_file))
if errors:
all_errors[str(css_file)] = errors
print(f"❌ {css_file}")
for error in errors:
print(f" - {error}")
else:
print(f"✅ {css_file}")
if all_errors:
print(f"\n⚠️ Found {sum(len(e) for e in all_errors.values())} total CSS errors")
else:
print("\n✅ No CSS syntax errors found!")