-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_rewrite_docs_phase2.py
More file actions
101 lines (80 loc) · 3.26 KB
/
Copy path_rewrite_docs_phase2.py
File metadata and controls
101 lines (80 loc) · 3.26 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#!/usr/bin/env python3
"""
Phase 2: Deep rustdoc quality rewrite for the Maintain element crate.
Fixes that require structural understanding of the file:
1. Fix empty /// lines that are between code comments (not adjacent to doc comments)
2. Ensure all non-code-wrapper // comments are not /// doc comments
3. Add #[allow(missing_docs)] for private items that can't reasonably be documented
4. Clean up redundant /// lines around section headers
"""
import re
import os
SOURCE_DIR = "/Volumes/CORSAIR/Developer/macOS/Application/CodeEditorLand/Land/Element/Maintain/Source"
def classify_lines(text):
"""
Classify each line and fix issues:
- Lines that are // ... comments formatted as /// ... (should be // not ///)
- Empty /// lines that are between // comment blocks
"""
lines = text.split('\n')
result = []
for i, line in enumerate(lines):
stripped = line
# Fix "//=" and "//-" section banners that got prefixed with extra /
# e.g., "////" or "/////" section banners
# Pattern: starts with 4+ slashes
m = re.match(r'^(/+)([/!=-].*)', stripped)
if m:
slashes = m.group(1)
rest = m.group(2)
if len(slashes) >= 4 and rest and rest[0] in ('/', '!', '=', '-'):
# This is a comment section marker with too many slashes
# Change ///// === --> // === (keep exactly 2 slashes)
if rest.startswith('/'):
# //// some comment --> // some comment
new_line = '//' + rest[1:]
elif rest.startswith('!'):
# ////! doc comment -> //! doc comment
new_line = '//!' + rest[1:]
else:
new_line = '//' + rest
result.append(new_line)
continue
# Fix "/// " lines that are actually // comments (architecture section banners)
# Patterns like "/// // =====" or "/// // --------"
if re.match(r'^///\s*//', stripped):
# This is a // comment inside a doc comment - change to regular comment
result.append('//' + stripped[3:])
continue
result.append(line)
return '\n'.join(result)
def process_file(filepath):
with open(filepath, 'r') as f:
text = f.read()
original = text
# Fix comments
text = classify_lines(text)
if text != original:
with open(filepath, 'w') as f:
f.write(text)
return True
return False
def walk_and_process():
modified_files = []
total_files = 0
for root, dirs, files in os.walk(SOURCE_DIR):
for f in sorted(files):
if not f.endswith('.rs'):
continue
filepath = os.path.join(root, f)
total_files += 1
if process_file(filepath):
modified_files.append(os.path.relpath(filepath, SOURCE_DIR))
print(f" MODIFIED: {os.path.relpath(filepath, SOURCE_DIR)}")
return total_files, modified_files
if __name__ == '__main__':
total, modified = walk_and_process()
print(f"\nTotal .rs files scanned: {total}")
print(f"Files modified: {len(modified)}")
for f in modified:
print(f" - {f}")