修复bug
This commit is contained in:
51
scan_self_closing.py
Normal file
51
scan_self_closing.py
Normal file
@@ -0,0 +1,51 @@
|
||||
import os
|
||||
import re
|
||||
|
||||
def scan_self_closing_tags(root_dir):
|
||||
print(f"Scanning {root_dir} for suspicious self-closing tags...")
|
||||
|
||||
# Tags that are safe to self-close or are void elements
|
||||
safe_tags = {
|
||||
'image', 'img', 'input', 'br', 'hr', 'meta', 'link', 'col', 'base',
|
||||
'area', 'embed', 'param', 'source', 'track', 'wbr',
|
||||
'slot', 'template' # Maybe
|
||||
}
|
||||
|
||||
suspicious_files = []
|
||||
|
||||
for subdir, dirs, files in os.walk(root_dir):
|
||||
if 'node_modules' in subdir or 'unpackage' in subdir:
|
||||
continue
|
||||
|
||||
for file in files:
|
||||
if file.endswith('.uvue') or file.endswith('.vue'):
|
||||
file_path = os.path.join(subdir, file)
|
||||
try:
|
||||
with open(file_path, 'r', encoding='utf-8') as f:
|
||||
content = f.read()
|
||||
|
||||
# Regex to find self-closing tags: <TagName ... />
|
||||
# matches <TagName (anything but >) />
|
||||
matches = re.finditer(r'<([a-zA-Z0-9-]+)([^>]*)/>', content)
|
||||
|
||||
found_issues = []
|
||||
for match in matches:
|
||||
tag_name = match.group(1)
|
||||
if tag_name not in safe_tags:
|
||||
# Start checking if it's a known component that might be problematic
|
||||
# For now, report everything that isn't standard void
|
||||
context = content[max(0, match.start()-20):min(len(content), match.end()+20)]
|
||||
found_issues.append((tag_name, context.replace('\n', '\\n')))
|
||||
|
||||
if found_issues:
|
||||
print(f"\nExample issues in {file_path}:")
|
||||
for tag, ctx in found_issues:
|
||||
print(f" Tag: <{tag} ... /> | Context: {ctx}")
|
||||
suspicious_files.append(file_path)
|
||||
|
||||
except Exception as e:
|
||||
print(f"Error reading {file_path}: {e}")
|
||||
|
||||
return suspicious_files
|
||||
|
||||
scan_self_closing_tags(r'.')
|
||||
Reference in New Issue
Block a user