-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck_css_syntax.py
More file actions
65 lines (53 loc) · 2.06 KB
/
check_css_syntax.py
File metadata and controls
65 lines (53 loc) · 2.06 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
#!/usr/bin/env python3
import os
import re
from pathlib import Path
css_files = list(Path('frontend/src').rglob('*.css'))
total_files = len(css_files)
errors_found = []
for css_file in sorted(css_files):
try:
content = css_file.read_text(errors='ignore')
except:
continue
lines = content.split('\n')
file_issues = []
for i, line in enumerate(lines, 1):
stripped = line.strip()
# Skip empty lines and comments
if not stripped or stripped.startswith('/*') or stripped.endswith('*/'):
continue
# Check for double closing braces
if '}}' in line:
# Check if it's not in a comment
if not '//' in line.split('}}')[0]:
file_issues.append((i, 'Double closing braces }}', line.strip()[:80]))
# Check for double opening braces
if '{{' in line:
file_issues.append((i, 'Double opening braces {{', line.strip()[:80]))
# Check for empty selectors { }
if re.search(r'{\s*}', line):
file_issues.append((i, 'Empty selector {}', line.strip()[:80]))
# Check for orphaned closing braces (line starting with })
if stripped == '}':
# Normal - part of nested rule
pass
# Check for suspicious brace patterns
if line.count('{') != line.count('}'):
# This is normal for multi-line, so skip
pass
if file_issues:
errors_found.append((css_file, file_issues))
if errors_found:
print(f"Found CSS syntax errors in {len(errors_found)} file(s):\n")
for css_file, issues in errors_found:
print(f"FILE: {css_file}")
for line_num, issue_type, content in issues:
print(f" LINE {line_num}: {issue_type}")
print(f" {content}")
print()
else:
print(f"✓ No CSS syntax errors found in {total_files} CSS files\n")
print("CSS files checked:")
for css_file in sorted(css_files):
print(f" - {css_file.relative_to('.')}")