diff --git a/scripts/__pycache__/clean_comments.cpython-312.pyc b/scripts/__pycache__/clean_comments.cpython-312.pyc new file mode 100644 index 0000000..1080164 Binary files /dev/null and b/scripts/__pycache__/clean_comments.cpython-312.pyc differ diff --git a/scripts/clean_comments.py b/scripts/clean_comments.py index 2c880af..41e90fd 100644 --- a/scripts/clean_comments.py +++ b/scripts/clean_comments.py @@ -24,12 +24,15 @@ def clean_line(line: str) -> str: line = re.sub(r'BS-\S+\s*(?:fix|修复|修正|强化|兜底)?\s*:\s*', '', line) line = re.sub(r'BS-\S+\s+', '', line) # "// BS-XX explanation" -> "// explanation" - # --- Pattern 2: R tags --- - if re.match(r'^\s*//\s*R\d+[a-z]*\s*$', line): return '' - if re.match(r'^\s*\*\s*R\d+[a-z]*\s*$', line): return '' - line = re.sub(r'R\d+[a-z]*\s+P\d+-\d+\s*:\s*', '', line) - line = re.sub(r'R\d+[a-z]*\s*(?:fix|修复|修正)?\s*:\s*', '', line) - line = re.sub(r'R\d+[a-z]*\s+', '', line) + # --- Pattern 2: R tags (R17, R3.3, R13a, etc.) --- + if re.match(r'^\s*//\s*\(?R\d+(?:\.\d+)?[a-z]*\)?\s*$', line): return '' + if re.match(r'^\s*\*\s*\(?R\d+(?:\.\d+)?[a-z]*\)?\s*$', line): return '' + # R17 P1-3: text + line = re.sub(r'R\d+(?:\.\d+)?[a-z]*\s+P\d+-\d+\s*:\s*', '', line) + # (R3.3): text or R3.3: text or R3.3 fix: text + line = re.sub(r'\(?R\d+(?:\.\d+)?[a-z]*\)?\s*(?:fix|修复|修正)?\s*:\s*', '', line) + # (R3.3) text or R3.3 text + line = re.sub(r'\(?R\d+(?:\.\d+)?[a-z]*\)?\s+', '', line) # --- Pattern 3: Round tags --- if re.match(r'^\s*//\s*Round\d+\s*$', line): return '' @@ -44,11 +47,15 @@ def clean_line(line: str) -> str: line = re.sub(r'\bdevelopSystem\b', 'reference app', line) line = re.sub(r'\btds\b', 'app', line) - # --- Pattern 5: v0.x+ version markers (handle v0.10, v0.10.1, v0.11h+, v0.21+) --- + # --- Pattern 5: v0.x+ version markers (handle v0.10, v0.10.1, v0.11h+, v0.21+, etc.) --- if re.match(r'^\s*//\s*v0\.\d+(?:\.\d+)?[a-z]*\+?\s*$', line): return '' if re.match(r'^\s*\*\s*v0\.\d+(?:\.\d+)?[a-z]*\+?\s*$', line): return '' - line = re.sub(r'v0\.\d+(?:\.\d+)?[a-z]*\+?\s*(?:fix|修复|修正)?\s*:\s*', '', line) - line = re.sub(r'v0\.\d+(?:\.\d+)?[a-z]*\+?\s+', '', line) + # v0.XX+: text or v0.XX.YY: text or v0.XX fix: text + line = re.sub(r'v0\.\d+(?:\.\d+)?[a-z]*\+?\s*(?:fix|修复|修正)?\s*:', '', line) + # v0.XX+, text or v0.XX+ text or v0.XX+ — text + line = re.sub(r'v0\.\d+(?:\.\d+)?[a-z]*\+?[,]?\s+(?:fix|修复|修正)?\s*', '', line) + # v0.XX+ remaining (at end of line, no text after) + line = re.sub(r'\(?v0\.\d+(?:\.\d+)?[a-z]*\+?\)?', '', line) # --- Pattern 6: ssw-*-biz/ssw-common --- # Only in comments. Remove or simplify. @@ -77,10 +84,17 @@ def clean_line(line: str) -> str: line = re.sub(r'^(\s*//\s*)(?:fix:|修复:|修正:|强化:|兜底:)\s*', r'\1', line) line = re.sub(r'^(\s*\*\s*)(?:fix:|修复:|修正:|强化:|兜底:)\s*', r'\1', line) + # Remove leading ": " after stripping version/date markers at comment start + line = re.sub(r'^(\s*//\s*):\s+', r'\1', line) + line = re.sub(r'^(\s*\*\s*):\s+', r'\1', line) + # After all stripping, if main content is gone, delete if re.match(r'^\s*//\s*$', line): return '' if re.match(r'^\s*\*\s*$', line): return '' + # Trim trailing whitespace + line = line.rstrip() + '\n' if line.endswith('\n') else line.rstrip() + return line def clean_file(filepath: str) -> int: