Skip to content

Commit 4178a5a

Browse files
ZviBaratzclaude
andauthored
fix(ego-lint): propagate strip_comments newline preservation to all scripts (#61)
## Summary - `strip_comments()` used `re.sub(r'/\*.*?\*/', '', ...)` which collapsed multi-line block comments to empty strings, shifting all subsequent line numbers in output - `check-init.py` already had the fix (`_preserve_newlines` helper) — propagated it to the remaining 6 scripts - Also fixed `strip_css_comments()` in `check-css.py` which had the same bug (not listed in the original issue) ### Files modified | Script | Function | |--------|----------| | `check-lifecycle.py` | `strip_comments()` | | `check-async.py` | `strip_comments()` | | `check-prefs.py` | `strip_comments()` | | `check-accessibility.py` | `strip_comments()` | | `build-resource-graph.py` | `strip_comments()` | | `check-css.py` | `strip_css_comments()` | ## Test plan - [x] `bash tests/run-tests.sh` — all 584 assertions pass, 0 failures - [x] Verified all 6 files contain `_preserve_newlines` helper - [x] No new test fixture needed — this is a line-number accuracy fix Closes #51 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 782c7b4 commit 4178a5a

File tree

6 files changed

+36
-6
lines changed

6 files changed

+36
-6
lines changed

skills/ego-lint/scripts/build-resource-graph.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,14 @@ def read_file(path):
4040
return f.read()
4141

4242

43+
def _preserve_newlines(match):
44+
"""Replace block comment content with empty lines to preserve line numbers."""
45+
return '\n' * match.group(0).count('\n')
46+
47+
4348
def strip_comments(content):
4449
"""Remove single-line and block comments from JS content."""
45-
content = re.sub(r'/\*.*?\*/', '', content, flags=re.DOTALL)
50+
content = re.sub(r'/\*.*?\*/', _preserve_newlines, content, flags=re.DOTALL)
4651
content = re.sub(r'//.*$', '', content, flags=re.MULTILINE)
4752
return content
4853

skills/ego-lint/scripts/check-accessibility.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,14 @@ def find_js_files(ext_dir):
3333
return files
3434

3535

36+
def _preserve_newlines(match):
37+
"""Replace block comment content with empty lines to preserve line numbers."""
38+
return '\n' * match.group(0).count('\n')
39+
40+
3641
def strip_comments(content):
3742
"""Remove single-line and block comments."""
38-
content = re.sub(r'/\*.*?\*/', '', content, flags=re.DOTALL)
43+
content = re.sub(r'/\*.*?\*/', _preserve_newlines, content, flags=re.DOTALL)
3944
content = re.sub(r'//.*$', '', content, flags=re.MULTILINE)
4045
return content
4146

skills/ego-lint/scripts/check-async.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,14 @@ def find_js_files(ext_dir, exclude_prefs=True):
3333
return files
3434

3535

36+
def _preserve_newlines(match):
37+
"""Replace block comment content with empty lines to preserve line numbers."""
38+
return '\n' * match.group(0).count('\n')
39+
40+
3641
def strip_comments(content):
3742
"""Remove single-line and block comments from JS content."""
38-
content = re.sub(r'/\*.*?\*/', '', content, flags=re.DOTALL)
43+
content = re.sub(r'/\*.*?\*/', _preserve_newlines, content, flags=re.DOTALL)
3944
content = re.sub(r'//.*$', '', content, flags=re.MULTILINE)
4045
return content
4146

skills/ego-lint/scripts/check-css.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,14 @@ def result(status, check, detail):
5555
}
5656

5757

58+
def _preserve_newlines(match):
59+
"""Replace block comment content with empty lines to preserve line numbers."""
60+
return '\n' * match.group(0).count('\n')
61+
62+
5863
def strip_css_comments(content):
5964
"""Remove CSS block comments."""
60-
return re.sub(r'/\*.*?\*/', '', content, flags=re.DOTALL)
65+
return re.sub(r'/\*.*?\*/', _preserve_newlines, content, flags=re.DOTALL)
6166

6267

6368
def find_stylesheet(ext_dir):

skills/ego-lint/scripts/check-lifecycle.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,15 @@ def read_file(path):
6262
return f.read()
6363

6464

65+
def _preserve_newlines(match):
66+
"""Replace block comment content with empty lines to preserve line numbers."""
67+
return '\n' * match.group(0).count('\n')
68+
69+
6570
def strip_comments(content):
6671
"""Remove single-line and block comments from JS content."""
6772
# Remove block comments
68-
content = re.sub(r'/\*.*?\*/', '', content, flags=re.DOTALL)
73+
content = re.sub(r'/\*.*?\*/', _preserve_newlines, content, flags=re.DOTALL)
6974
# Remove single-line comments
7075
content = re.sub(r'//.*$', '', content, flags=re.MULTILINE)
7176
return content

skills/ego-lint/scripts/check-prefs.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,13 @@ def result(status, check, detail):
2222
print(f"{status}|{check}|{detail}")
2323

2424

25+
def _preserve_newlines(match):
26+
"""Replace block comment content with empty lines to preserve line numbers."""
27+
return '\n' * match.group(0).count('\n')
28+
29+
2530
def strip_comments(content):
26-
content = re.sub(r'/\*.*?\*/', '', content, flags=re.DOTALL)
31+
content = re.sub(r'/\*.*?\*/', _preserve_newlines, content, flags=re.DOTALL)
2732
content = re.sub(r'//.*$', '', content, flags=re.MULTILINE)
2833
return content
2934

0 commit comments

Comments
 (0)