Skip to content

Commit 49294f1

Browse files
committed
fix(ownts): consume full multi-line expr cleanup; fail CI on ownir crash
Two follow-ups from review (CodeRabbit + Codex) on the cleanup-span fix: - Expression-bodied cleanups were cut at the FIRST newline after `=>`, so a formatted cleanup like return () => el.removeEventListener("resize", onResize); left an empty cleanup and reintroduced the false OWN001. _cleanup_span now consumes the whole expression across line breaks, stopping only at a top-level `;` or the effect body's own closing brace (depth-aware over the masked body). - The silent-case CI step used `|| true`, which would turn an OwnIR load/schema crash (rc 2, no findings printed) into a false-green zero-count. Dropped it so a parser/core regression fails the step; the other steps keep `|| true` because they legitimately expect findings (rc 1). EffectExprCleanup.tsx gains a multi-line cleanup case. Full suite green (effects 31/31, ownir 194/194); ruff + mypy --strict clean; all fixtures unchanged. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01PVeuchch67CtjSbizYm8gi
1 parent 23c89f2 commit 49294f1

3 files changed

Lines changed: 30 additions & 7 deletions

File tree

‎.github/workflows/ci.yml‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1092,7 +1092,9 @@ jobs:
10921092
run: |
10931093
python frontend/ownts/ownts.py frontend/ownts/examples/EffectExprCleanup.tsx \
10941094
-o "$RUNNER_TEMP/expr.facts.json"
1095-
expr=$(python -m ownlang ownir "$RUNNER_TEMP/expr.facts.json" || true)
1095+
# no `|| true`: this case expects ZERO findings (rc 0), so a parser/core
1096+
# crash (rc 2) must FAIL the step, not be swallowed into an empty result.
1097+
expr=$(python -m ownlang ownir "$RUNNER_TEMP/expr.facts.json")
10961098
echo "$expr"
10971099
# the `{` of `{capture: true}` belongs to the call, not the cleanup block —
10981100
# the listener is released, so no false-positive leak

‎frontend/ownts/examples/EffectExprCleanup.tsx‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,13 @@ export function ExprCleanup() {
1111
return () => window.removeEventListener("scroll", onScroll, { capture: true });
1212
}, []);
1313

14+
// a MULTI-LINE expression-bodied cleanup must not be cut at the first newline
15+
// after `=>` (which would leave an empty cleanup and a false leak).
16+
useEffect(() => {
17+
el.addEventListener("resize", onResize);
18+
return () =>
19+
el.removeEventListener("resize", onResize);
20+
}, []);
21+
1422
return <div>expr cleanup</div>;
1523
}

‎frontend/ownts/ownts.py‎

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -395,12 +395,25 @@ def _cleanup_span(mbody: str) -> tuple[int, int] | None:
395395
if stripped.startswith("{"): # block-bodied cleanup: `=> { ... }`
396396
brace = m.end() + (len(rest) - len(stripped))
397397
return (m.start(), _match_block(mbody, brace))
398-
# single-expression cleanup — ends at the line break. Crucially NOT a
399-
# `find("{")`, which would mistake an options object inside the call (e.g.
400-
# `=> el.removeEventListener("x", h, {capture: true})`) for the cleanup block
401-
# and truncate the trailing `)`, breaking _listener_call into a false leak.
402-
nl = mbody.find("\n", m.end())
403-
return (m.start(), nl if nl != -1 else len(mbody))
398+
# single-expression cleanup. Consume the WHOLE expression across line breaks
399+
# — stopping at a top-level `;` or the effect body's own closing brace, NOT
400+
# the first newline (which truncates a multi-line call) and NOT a `find("{")`
401+
# (which would mistake an options object like `{capture: true}` inside the
402+
# call for the cleanup block). Both truncations drop the closing `)` and turn
403+
# a released listener into a false leak.
404+
i, depth = m.end(), 0
405+
while i < len(mbody):
406+
c = mbody[i]
407+
if c in "([{":
408+
depth += 1
409+
elif c in ")]}":
410+
if depth == 0: # the effect body's closing brace — expression ends
411+
break
412+
depth -= 1
413+
elif c == ";" and depth == 0:
414+
break
415+
i += 1
416+
return (m.start(), i)
404417
return None
405418

406419

0 commit comments

Comments
 (0)